我正在使用 Graphcool,但这可能是一个通用的 GraphQL 问题。有没有办法使两个字段之一成为必需的?
例如说我有一个 Post 类型。帖子必须附加到组或事件。这可以在模式中指定吗?
type Post {
body: String!
author: User!
event: Event // This or group is required
group: Group // This or event is required
}
我的实际要求有点复杂。帖子可以附加到事件中,也可以附加到组和位置。
type Post {
body: String!
author: User!
event: Event // Either this is required,
group: Group // Or both Group AND Location are required
location: Location
}
所以这是有效的:
mutation {
createPost(
body: "Here is a comment",
authorId: "<UserID>",
eventId: "<EventID>"
){
id
}
}
就像这样:
mutation {
createPost(
body: "Here is a comment",
authorId: "<UserID>",
groupID: "<GroupID>",
locationID: "<LocationID>"
){
id
}
}
但这不是:
就像这样:
mutation {
createPost(
body: "Here is a comment",
authorId: "<UserID>",
groupID: "<GroupID>",
){
id
}
}