我正在尝试graphql-compose
库,并遵循他们的Getting started Github page,我建立了一个非常简单的示例。
这是我的代码:
import { schemaComposer } from "graphql-compose";
export const UserTC = schemaComposer.createObjectTC({
name: "UserTC",
fields: {
name: "String",
surname: "String"
}
});
UserTC.addResolver({
kind: "query",
name: "userFind",
resolve: async () => {
return []; // empty array
}
});
schemaComposer.Query.addFields({
userFind: UserTC.getResolver("userFind")
});
export const schema = schemaComposer.buildSchema()
将返回的架构对象传递到
时出现以下错误
我的Apollo服务器:
TypeError: Cannot read property 'getTypeName' of undefined
错误堆栈指向代码的最后一行。我不知道 我做错了。
感谢您的帮助。
我看不到我是什么错误
答案 0 :(得分:0)
将“类型”添加到解析器:
UserTC.addResolver({
kind: "query",
name: "userFind",
type: UserTC,
resolve: async () => {
return []; // empty array
}
});