In the previous post of this series, GraphQL Backend, we went over how to clone the repo, and deploy it to have a functional graphql
backend endpoint.
On this post, we will go over the folders and files in the repo and how to add more queries.
A JSON file to hold configuration settings in case we need some.
Configuration for the serverless
framework. Function gql
is defined here. The settings allow for an https
trigger using API Gateway
.
Utility belt with some functions.
Entry point to our lambda
function.
Of note:
makeExecutableSchema
to enable GraphQL schema language
to define our object definitions (types) in simple .gql
files, instead of directly using graphql.js
javascript objects and making type definitions unnecessarily verbose.utils.gql.readSchema
to aggregate our .gql
typesutils.gql.readResolvers
to load all our resolversHolds a JSON
file pokemon.json with some information about 26 pokemon.
This is where our graphql
stuff will reside.
Where we define our object types
. The two main files in here are _Query.gql
and _Mutation.gql
.
Any files in this folder are read by utils.gql.readSchema()
and aggregated into our graphql schema
.
In this file, we define the queries that will be available from our graphql API
.
To add a new query
, you can add a new row with the query name, its parameters, and a return type
. A type
is defined in a .gql
file. You can inspect the available ones like Paging
and Pokemon
.
Paging
type.Pokemon
type, and other related types.In the Pokemon
type, you can see how other types are nested in it, like Stats
and Evolution
.
A comprehensive explanation of type
definitions can be found here.
This file defines mutations available from our graphql API.
It is the same as _Query.gql
; the difference being that these queries change (mutate) underlying data.
You can think of a query
as a GET
, and a mutation
as a POST
or PUT
.
Our javascript logic for our graphql API.
Query resolvers go here.
If you open up ./entities/_Query.gql
, you will see that each defined query has a respective resolver
in this folder.
Thru this convention, our lambda will know to call the proper resolver for the queries.
Same as /Query
but for mutations.
Next entry for this series will be
How the pokemon
query works and adding a new query for move
.