0

这是我使用的 GraphQL Schema 的简化片段。有 - 一个枚举,类型 Contributor 和类型 Review。

enum CONTRIBUTOR_TYPE {
  AUTHOR
  EDITOR
}

type Contributor {
  name: String
  role: CONTRIBUTOR_TYPE
}

type Article {
  text: String
  authors: [Contributor]
}

我想描述的是,“作者”字段不仅仅是贡献者类型的数组,而是具有特定工作角色的贡献者。在伪代码中它看起来像

 authors: [Contributor{type: CONTRIBUTOR_TYPE.AUTHOR}]!

有没有办法在 GraphQL Schema 中描述这个约束?

4

1 回答 1

0

您应该能够使用模式指令来描述/强制执行约束。对于 apollo 服务器,请查看https://www.apollographql.com/docs/apollo-server/schema/creating-directives/,对于 graphql-java,请查看https://www.graphql-java.com/documentation/v15/ sdl-directives/,对于其他服务器实现,请检查其相应的文档。

于 2020-06-01T17:24:14.720 回答