Create your own Graphback plugin
You can build your own custom Graphback plugin to:
- automate additional customisations to the final generated schema
- build dynamic resolvers
- create file resources such as client-side queries.
To create your own plugin, start by creating a class that extends GraphbackPlugin
.
GraphbackPlugin
has a number of methods for performing different extensions to your Graphback API.
For the rest of this documentation, we will be using the following business model:
#
transformSchematransformSchema
lets you make modifications to the current iteration of the GraphQL schema object. In here you can create or modify any type or field in the schema.
As the GraphQLSchema
and its types are immutable we highly recommend you to install and use the amazing GraphQL Compose to modify the schema.
In MyGraphbackPlugin
, the transformSchema
hook adds a new query field to the schema for each of the data models to retrieve all archived models.
#
createResolversWith the createResolvers
hook you can create and return resolvers using the graphql-tools
format.
To use createResolvers
you will first need to install @graphql-tools/utils
:
Here createResolvers
is creating a new query resolver for each query field added to the schema in transformSchema
.
#
createResourcesSince Graphback is primarily a runtime framework, you probably won't use createResources
too often. However it is a very useful method if you ever need to output something to a file, such as your schema.
Here createResources
is creating a GraphQL schema file from the schema generated by Graphback.
#
getPluginNameReturns a unique name of the plugin. The will be used by plugin registry to uniquely identify the plugin.
#
UsageTo use the plugin, add it to the plugins
array in buildGraphbackAPI
.
Archived Notes
or Comments
can be retrieved by the following query: