Gatsby 的 addThirdPartySchema 问题

Issue with Gatsby's addThirdPartySchema

我正在尝试创建自定义源插件并尝试使用 addThirdPartySchema 方法,我尝试使用下面的这个简单示例但收到此错误:

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,
  });
};

根据我的评论,我 运行 您在本地的代码并且可以确认 graphql@^15 引发了错误。

降级到 graphql@14.6.0(与 Gatsby 的 graphql 版本相同)解决了这个问题。