联合 GraphQL 模式验证

问题描述

我在我的项目中创建了 3 个微服务并实现了 GraphQL Netflix DGS 联邦框架。 https://netflix.github.io/dgs/ 作为一家公司,我们拥有来自不同团队的不同微服务的 30 多个模式。但是,如果模式类型名称在不同的微服务中相互重复,我们会在 Apollo 网关中收到运行时错误。 我想知道如何验证模式?是否有任何引擎/库/概念来验证多个微服务等上的联合 GraphQL 模式?我正在检查模式注册表,但看起来它是用于存储模式和版本控制等,而不是完全验证模式。 示例架构和错误: 服务 1 中的架构:

type Query{
Status:status
}
type status{
id:String
@R_685_4045@ion:Info
}
type Info{
location:String
birthDate:String
gender:String
}

服务 2 中的架构:

type Query{
Books:Book
}
type Book{
name:String
@R_685_4045@ion:Info
}
type Info{
author:String
rating:String
}

在以上两个模式中,模式类型“信息”在两个微服务中是相同的。通过 ApolloGateway 实现这两个服务后,它抛出运行时错误: " 此数据图缺少有效配置。无法组合有效架构。发现以下组合错误:只能存在一种名为“信息”的类型

解决方法

如果 Info 是非共享类型,我建议您将其命名为 BookInfo 或 AnotherInfo

如果你想分享信息类型。你应该使用指令

https://www.apollographql.com/docs/federation/enterprise-guide/federated-schema-design/