I have a query that takes a status as an input variable which is an enum of (future, past, all).
I'd like to return some fields only when the status is future. I've tried using @include but it seems it will only accept a boolean exactly.
Is there some way of getting this to work:
aField @include(if: $status == future)
I think you can't use even use boolean fields with @include - literals/query variables only, so expressions are a no-go as well.
If it's really important, and you're able to modify the API/schema, you could (ab)use the interface functionality - have future entities resolve to one type, and past entities to another, then you can use fragments to select fields based on which it is:
interface Competition {
id: ID!
name: String!
status: Status!
something: String
}
type FutureCompetition implements Competition {
// same fields
}
type PastCompetition implements Competition {
// same fields
}
Then you can query with something like this:
competitions {
id
name
status
... on FutureCompetition {
something
}
}
A possibly easier thing to do would be to simply do two queries in one and merge the results client-side, assuming you can query by status:
pastCompetitions: competitions(withStatus: PAST) {
id
name
status
}
futureCompetitions: competitions(withStatus: FUTURE) {
id
name
status
something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With