graphql-modules不调用__resolveType

问题描述 投票:2回答:1

我不确定接口/联合上__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: '[email protected]', 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没有得到记录,并且出现以下错误。

抽象类型节点必须在运行时解析为字段Query.node的对象类型,字段{。id:“ abc”,电子邮件:“ [email protected]”密码:“ test”},收到“未定义”。 Node类型应提供“ resolveType”函数,或者每种可能的类型应提供“ isTypeOf”函数。“

我在做什么错,我将如何解决这个问题?

快速说明:在__typename: 'User'中的返回对象中添加Query.node似乎可行,但似乎不是理想的解决方案

node.js graphql apollo-server
1个回答
0
投票

我有相同的问题,可以确认它出现在使用graphql-modules时从未调用过__resolveType。我将在回购中提出一个问题,并引用此SO。将回传我得到的任何答案

© www.soinside.com 2019 - 2024. All rights reserved.