Scaffolding Resolvers

IMPORTANT: Scaffolded resolvers are typically generated into a temporary directory and manually copied over into your actual source files. After the generated resolver skeletons have been copied over, the generated files can be deleted.

This feature increases your productivity by generating the boilerplate resolver skeletons for those fields that are not default resolvers. A great example for this are the resolvers for your root types: Query, Mutation and Subscription.

For fields on these types, the resolver implementation needs to call out to some data source (e.g. a database, a REST API or a Prisma service) and therefore can not be automatically generated by graphqlgen. However, graphqlgen is able to reduce the amount of boilerplate you need to write by generating resolver "skeletons".

Consider the following Query type:

type Query {
  user(id: ID!): User

The resolver skeleton for the user field will look similar to this:

export const Query: QueryResolvers.Type = {
  user: (parent, args) => null,

With that boilerplate in place, all that's left to do for the developer is implement fetching the requested User object from some data source (guided by the generated typings for resolver arguments and return values).

The relevant properties from graphqlgen.yml for the Scaffolding feature are:

  • language (required)
  • schema (required)
  • models (required)
  • context (optional)
  • output (required)
  • resolver-scaffolding (required)



Assume you have the following minimal setup with three files:


type Query {
  user(id: ID!): User

type Mutation {
  createUser(name: String): User!

type User {
  id: ID!
  name: String


export interface User {
  id: string
  name: string | null
  password: string


language: typescript
schema: ./src/schema.graphql
    - ./src/models.ts
output: ./src/generated/graphqlgen.ts
  output: ./src/tmp/
  layout: file-per-type

Generated code

After running $ graphqlgen in your terminal, the following code will be generated into ./src/tmp/:


import { UserResolvers } from '../generated/graphqlgen'

export const User: UserResolvers.Type = {


import { QueryResolvers } from '../generated/graphqlgen'

export const Query: QueryResolvers.Type = {
  user: (parent, args) => null,


import { MutationResolvers } from '../generated/graphqlgen'

export const Mutation: MutationResolvers.Type = {
  createUser: (parent, args) => {
    throw new Error('Resolver not implemented')


import { Resolvers } from '../generated/graphqlgen'

import { Query } from './Query'
import { Mutation } from './Mutation'
import { User } from './User'

export const resolvers: Resolvers = {

Note the following:

  • The paths in the import statements will likely need to be adjusted depending on your file structure.

results matching ""

    No results matching ""