首页 文章

Apollo:从远程模式扩展类型

提问于
浏览
4

我目前有多个运行Apollo的GraphQL服务,并创建了一个使用远程模式拼接的“网关”服务,以便为我提供单一的访问 endpoints .

在我的网关服务中,我希望扩展远程类型以在拼接模式之间创建引用 .

const linkTypeDefs = `
    extend type User {
        profile: Profile
    }

    extend type Profile {
        user: User
    }`;

const schema = mergeSchemas({
    schemas: [userSchema, profileSchema, linkTypeDefs],
    resolvers: /* Resolvers */
});

但是我似乎得到以下错误:

GraphQLError:无法扩展“User”类型,因为它在现有模式中不存在 .

我已经仔细检查了“User”和“Profile”类型,我可以从Gateway Graphiql查询它们 .

为了扩展从远程模式合并的类型,是否需要采取任何特定步骤?

1 回答

  • 1

    我最终通过意识到 userSchemaprofileSchema 都返回了一个承诺来解决这个问题 .

    我等待这些返回值,并为我解决了这个问题 .

相关问题