Both functions receive these arguments:
context contains:
Each returned entry is a GraphQL field config with
type, optional args, and resolve. FrogBot attaches req.frogbot before each resolve runs.
Return value
BothgraphQL.queries and graphQL.mutations functions should return an object with properties equal to your newly written GraphQL queries and mutations.
Example
graphQL to buildConfig in your FrogBot config.
Resolver function
In your resolver, make sure you setdepth: 0 if you’re returning data directly from the Local API so that GraphQL can correctly resolve queries to nested values such as relationship data.
Your function will receive four arguments you can make use of:
Example
obj
The previous object. Not very often used and usually discarded.
args
The available arguments from your query or mutation will be available to you here, these must be configured via the custom operation first.
context
An object containing the incoming request as req, the same FrogBotRequest a custom endpoint receives. Use req.frogbot to call the Local API and req.user to read the signed-in user. Pass req to Local API calls so they run in the same request and see the same user.
info
Contextual information about the currently running GraphQL operation. You can get schema information from this as well as contextual information about where this resolver function is being run.
Types
We’ve exposed a few types and utilities to help you extend the API further. FrogBot uses the GraphQL.js package for which you can view the full list of available types in the official documentation.GraphQLJSON & GraphQLJSONObject
GraphQL
You can directly import the GraphQL package used by FrogBot, most useful for typing.
buildPaginatedListType
This is a utility function that allows you to build a new GraphQL type for a paginated result similar to the FrogBot’s generated schema.
It takes in two arguments, the first for the name of this new schema type and the second for the GraphQL type to be used in the docs parameter.
Example
context.collections[slug].graphQL
If you want to extend more of the provided API then the graphQL object on your collection slug will contain additional types to help you re-use code for types, mutations and queries.
Best practices
There are a few ways to structure your code, we recommend using a dedicatedgraphql directory so you can keep all of your logic in one place. You have total freedom of how you want to structure this but a common pattern is to group functions by type and with their resolver.
Example