Version: 0.12.x

CRUD Resolvers Plugin

The Graphback CRUD Resolvers plugin gives developers an opinionated way to generate a set of Node.js server compatible GraphQL resolvers that will work with the schema and client side queries generated by Graphback.

The generated CRUD resolvers use our Runtime Abstraction that gives you the ability to dynamically connect to a variety of data sources.

Installation

Add the plugin to your application with npm:

npm install @graphback/codegen-resolvers

Using

Add graphback-resolvers to your .graphqlrc.yml config file under the graphback extension:

plugins:
graphback-resolvers:
outputPath: ./server/src/resolvers

graphback-resolvers configuration must come after graphback-schema as it depends on the generated schema.

Run graphback generate to generate your CRUD resolvers. This will generate a single resolvers file in your outputPath.

Example generated resolver function:

findAllNotes: (parent, args, context) => {
return context.Note.findAll(args)
},

For a full example, see our TypeScript Apollo Template.

You can then import the resolvers into your application:

import resolvers from './resolvers/resolvers';
const apolloServer = new ApolloServer({
...
resolvers
})

The generated resolvers use our Runtime Abstraction and depend on the CRUD services to be passed to the resolver function as part of the context. To add these services to your application see Data Sources.

Configuration

You can customise how your resolvers are generated by editing extensions.graphback.graphback-resolvers in your .graphqlrc.yml file.

File extension

To specify the file extension of the generated resolvers file:

format: 'ts'

If not specified this defaults to 'ts'.

Supported options:

  • ts - TypeScript extension.
  • js - JavaScript extension.

Output path

To specify the relative path for the generated resolvers file to be located:

outputPath: './src/resolvers'

File name

The generated resolvers file by default will be called resolvers.(ts|js). You can override this by adding resolversFileName to your config:

resolversFileName: 'generatedResolvers'

If not specified this defaults to resolvers.

Layout

To customise the layout of the resolvers object:

layout: 'graphql'

If not specified this defaults to 'apollo'.

Supported options:

  • apollo - Apollo GraphQL resolvers layout.
  • graphql - GraphQL.js resolvers layout.