2

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

1 回答 1

3

按照我的评论,我在本地运行您的代码并可以确认错误是用graphql@^15.

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

于 2020-07-22T06:03:06.763 回答