graphql 模块不调用 __resolveType
graphql-modules not calling __resolveType
我不完全确定 __resolveType
函数在接口/联合上的目的/操作,但我想它是在添加一个具有已解析类型的 __typename
字段。但是,我似乎无法使用 graphql-modules
进行此操作。这里作为子集,但我的模式的足够子集。
const typeDefs = gql`
interface Node {
id: ID!
}
type User implements Node {
id: ID!
email: String!
password: String
}
type Group implements Node {
id: ID!
name: String!
}
type Query {
node(id: ID!): Node
}`;
下面是我的解析器。
const resolvers = {
Query: {
node: () => {
return { id: 'abc', email: 'a@b.c', password: 'test' };
}
},
Node: {
__resolveType: () => {
console.log('__resolveType');
return 'User';
}
}
}
它们一起组合成一个模块。
const Module = new GraphQLModule({
resolvers,
typeDefs,
});
像 Apollo 服务器一样使用。
const server = new ApolloServer({
modules: [Module],
})
// Launch etc...
但是在查询 node
时,__resolveType 没有被记录,我得到以下错误。
Abstract type Node must resolve to an Object type at runtime for field Query.node with { id: "abc", email: "a@b.c" password: "test" }, received "undefined". Either the Node type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function."
我做错了什么,我该如何解决这个问题?
快速说明:在 Query.node
的返回对象中添加 __typename: 'User'
似乎可行,但似乎不是理想的解决方案
我遇到了同样的问题,可以确认在使用 graphql-modules 时似乎 __resolveType 从未被调用。我将在 repo 中提出一个问题并引用此 SO。 post 会回复我得到的任何答案吗?
它已经在 repo 问题中报告过,修复是将顶层模块模式传递给 apollo-server,而不是作为模块
({
schema: Appmodule.schema,
context: session => session
})
请在此处查看问题。 https://github.com/Urigo/graphql-modules/issues/619
可以确认这是有效的
我不完全确定 __resolveType
函数在接口/联合上的目的/操作,但我想它是在添加一个具有已解析类型的 __typename
字段。但是,我似乎无法使用 graphql-modules
进行此操作。这里作为子集,但我的模式的足够子集。
const typeDefs = gql`
interface Node {
id: ID!
}
type User implements Node {
id: ID!
email: String!
password: String
}
type Group implements Node {
id: ID!
name: String!
}
type Query {
node(id: ID!): Node
}`;
下面是我的解析器。
const resolvers = {
Query: {
node: () => {
return { id: 'abc', email: 'a@b.c', password: 'test' };
}
},
Node: {
__resolveType: () => {
console.log('__resolveType');
return 'User';
}
}
}
它们一起组合成一个模块。
const Module = new GraphQLModule({
resolvers,
typeDefs,
});
像 Apollo 服务器一样使用。
const server = new ApolloServer({
modules: [Module],
})
// Launch etc...
但是在查询 node
时,__resolveType 没有被记录,我得到以下错误。
Abstract type Node must resolve to an Object type at runtime for field Query.node with { id: "abc", email: "a@b.c" password: "test" }, received "undefined". Either the Node type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function."
我做错了什么,我该如何解决这个问题?
快速说明:在 Query.node
的返回对象中添加 __typename: 'User'
似乎可行,但似乎不是理想的解决方案
我遇到了同样的问题,可以确认在使用 graphql-modules 时似乎 __resolveType 从未被调用。我将在 repo 中提出一个问题并引用此 SO。 post 会回复我得到的任何答案吗?
它已经在 repo 问题中报告过,修复是将顶层模块模式传递给 apollo-server,而不是作为模块
({
schema: Appmodule.schema,
context: session => session
})
请在此处查看问题。 https://github.com/Urigo/graphql-modules/issues/619
可以确认这是有效的