盖茨比的addThirdPartySchema问题

时间:2020-07-21 23:25:07

标签: gatsby gatsby-plugin

我正在尝试创建一个自定义源插件,并尝试使用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,
  });
};

1 个答案:

答案 0 :(得分:2)

在我发表评论之前,我在本地运行您的代码,并可以确认错误由graphql@^15引发。

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