Search code examples
gatsbygatsby-plugin

Issue with Gatsby's addThirdPartySchema


I am trying to create a custom source plugin and am trying to use the addThirdPartySchema method, I tried with this simple example below but receive this error:

Error: Cannot create as TypeComposer the following value: Test.
import * as graphql from "graphql";
import { SourceNodesArgs } from "gatsby";

export const sourceNodes = function sourceNodes(args: SourceNodesArgs) {
  const { addThirdPartySchema } = args.actions;

  const schema = new graphql.GraphQLSchema({
    query: new graphql.GraphQLObjectType({
      name: "Test",
      fields: {
        test: {
          type: graphql.GraphQLString,
          resolve: () => "hello",
        },
      },
    }),
  });

  addThirdPartySchema({
    schema,
  });
};

Solution

  • Following up to my comment, I run your code locally & can confirm the error is thrown with graphql@^15.

    Downgrading to graphql@14.6.0 (same as Gatsby's graphql version) fixed the issue.