Im using Graphcool but this may be a general GraphQL question. Is there a way to make one of two fields required?
For instance say I have a Post type. Posts must be attached to either a Group or to an Event. Can this be specified in the schema?
type Post {
body: String!
author: User!
event: Event // This or group is required
group: Group // This or event is required
}
My actual requirements are a bit more complicated. Posts can either be attached to an event, or must be attached to a group and a location.
type Post {
body: String!
author: User!
event: Event // Either this is required,
group: Group // Or both Group AND Location are required
location: Location
}
So this is valid:
mutation {
createPost(
body: "Here is a comment",
authorId: "<UserID>",
eventId: "<EventID>"
){
id
}
}
As is this:
mutation {
createPost(
body: "Here is a comment",
authorId: "<UserID>",
groupID: "<GroupID>",
locationID: "<LocationID>"
){
id
}
}
But this is not:
As is this:
mutation {
createPost(
body: "Here is a comment",
authorId: "<UserID>",
groupID: "<GroupID>",
){
id
}
}