合并GraphQL模式错误:在解析器中定义,但在模式中未定义

时间:2019-09-23 01:53:46

标签: merge graphql schema

我已将代码分为不同的graphql和resolver文件。 然后出现了这个错误。

Error: "getComments" defined in resolvers, but not in schema

但是,当我console.log合并graphql时,getComment确实出现在字符串中。但由于某种原因它不是Query {}的一部分。这就是为什么会出现此错误的原因吗?我该如何解决?

有一个src\graphql\resolver.graphql,此处定义的架构似乎出现在Query {}, Mutation {}, Subscription{}中。所有其他.graphql文件都单独出现,不属于这3个文件。

src \ resolvers \ Comment \ schema.graphql

type Query {
  getComments(commentOption: CommentQuery!): [CommentInfo!]
}

type Mutation {
  """
  Return > [true] : DB save successful  [false] : DB save unsuccessful
  """
  createComment(commentInfo: CommentInfoInput!): Boolean!
}

src \ schema.ts

const graphqlArray = fileLoader(path.join(__dirname, "."), { recursive: true })
const resolverArray = fileLoader(path.join(__dirname, "./**/*.resolver.*"))

console.log(resolverArray)

const schema: GraphQLSchema = makeExecutableSchema({
  typeDefs: mergeTypes(graphqlArray),
  resolvers: mergeResolvers(resolverArray)
})

console.log(resolverArray)

的结果
[ { getComments: [Function: getComments],
    createComment: [Function: createComment] },
  { Query: {},
    Mutation:
     { FollowTarget: [Function: FollowTarget],
       isFollowingTarget: [Function: isFollowingTarget],
       IncrementViewCount: [Function: IncrementViewCount] },
    Subscription: { helloWorld: [Function: helloWorld] } },
  { createUser: [Function: createUser],
    createUserInfo: [Function: createUserInfo],
    getUserInfo: [Function: getUserInfo],
    isDuplicateName: [Function: isDuplicateName] } ]
Error: "getComments" defined in resolvers, but not in schema

0 个答案:

没有答案