nexus graphql 中出现 Ambiguos“错误:NEXUS__UNKNOWN__TYPE 已定义并导入为类型”错误

Zan*_*rou 7 nexus node.js express apollo graphql

使用 Nexus 与 apollo-server 定义 graphql 架构时,出现以下错误。

Error: NEXUS__UNKNOWN__TYPE was already defined and imported as a type

堆栈跟踪没有提供有关问题发生位置或问题是什么的太多信息。该项目有 20 多个模型和数十个解析器,因此调试起来相当困难。

Error: NEXUS__UNKNOWN__TYPE was already defined and imported as a type, check the docs for extending types
    at extendError (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1744:2)
    at SchemaBuilder.addType (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:603:8)
    at SchemaBuilder.missingType (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1212:5)
    at SchemaBuilder.getOrBuildType (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1540:4)
    at SchemaBuilder.getOutputType (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1471:10)
    at SchemaBuilder.buildOutputField (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1349:52)
    at /Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1307:7
    at Array.forEach (<anonymous>)
    at SchemaBuilder.buildOutputFields (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1306:7)
    at fields (/Users/username/Documents/folder/folder/graphq-nexus-prisma-api/node_modules/nexus/src/builder.ts:1009:33)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

小智 0

It could have been much helpful if you could elaborate what did you do before this error happened.

I just came up with this error exactly as same as what you got and for me it was because I just accidentally changed the name for objectType of typeDef.

For instance, the name for the FollowUserResult was actually FollowResult and after I changed the name, the whole mutation resolvers related to this objectType became wrong.

export const FollowUserResult = objectType({
  name: "FollowUserResult", // It was originally "FollowResult"
  definition(t) {
    t.nonNull.boolean("ok");
    t.string("error");
  },
});
Run Code Online (Sandbox Code Playgroud)

You may check on this again. Once you got those correct, delete the schema.graphql file and generate the new schema.graphql file.