Troubleshooting Sanity and Gatsby

How to troubleshoot common errors integrating Gatsby and Sanity.io

First make sure that:

  • gatsby and gatsby-source-sanity is up to date
  • That schemas in Sanity has been (re)deployed to GraphQL sanity graphq deploy
  • That there's no stale cache in Gatsby: gatsby clean (deletes the .cache and public folders)

If you ask for help in the community, it's very helpful if you share the schema in a gist on Github or similar. That makes it easier for us to reproduce the errors and help you out.

Error messages and how to solve them

warning `createResolvers` passed resolvers for type `SanityRootQuery` that doesn't exist in the schema. Use `createTypes` to add the type before adding resolvers.
error UNHANDLED REJECTION


  Error: SanityNavItem.internal provided incorrect OutputType: '{}'

In this case the internal field on navItem was a reference. This issue was solved by wrapping that reference in an object and hoisting it:

export default createSchema({
  name: 'default',
  types: [
    {
      name: 'internal',
      type: 'object',
      title: 'Internal',
      fields: [
        {
          type: 'reference',
          name: 'link',
          to: [{type: 'page'}]
        }
      ]
    },
    {
      name: 'navItem',
      type: 'object',
      title: 'NavItem',
      fields: [
        {
          name: 'text',
          type: 'string',
          title: 'Text'
        },
        {
          name: 'id',
          type: 'string',
          title: 'Id'
        },
        {
          name: 'internal',
          type: 'internal',
          title: 'Internal',
        },
        {
          name: 'external',
          type: 'url',
          title: 'External'
        }
      ]
    },
    {
      name: 'page',
      type: 'document',
      title: 'Page',
      fields: [
        {
          name: 'tilte',
          type: 'string'
        }
      ]
    }
]

Was this article helpful?