I have a GraphQl API for listing a bunch of items, and I can query it perfectly etc. But now I'd like to query for a subset of that list where one property can have 'all possible values except one specific one'.
For example, I want to query something like this:
{
items(status: !"Unwanted"){
id
}
}
That exclamation mark obviously doesn't work, but it illustrates what I am after. Can't find any information about this online.
Does anybody know of a way to do this? I would really hate having to enumerate all possible wanted values instead of just excluding the one unwanted value. This would be really bad design and is not scalable.
Thanks.
Every GraphQL search filter can use and , or , and not operators. GraphQL syntax uses infix notation, so: “a and b” is a, and: { b } , “a or b or c” is a, or: { b, or: c } , and “not” is a prefix ( not: ). The and operator is implicit for a single filter object, if the fields don't overlap.
What is GraphiQL? GraphiQL is the GraphQL integrated development environment (IDE). It's a powerful (and all-around awesome) tool you'll use often while building Gatsby websites. You can access it when your site's development server is running—normally at http://localhost:8000/___graphql .
A resolver is a function that's responsible for populating the data for a single field in your schema. It can populate that data in any way you define, such as by fetching data from a back-end database or a third-party API.
Use ne
:
{
items(filter: {status: {ne: "Unwanted"}}){
id
}
}
If you can define the schema (implement the server) then you can add a second argument like statusExcept
to the items
field. Then in the resolve method check if status or statusExcept was set and deliver the items according to that.
It the server API is fixed there is afaik nothing that you can do except getting everything and filter on the client.
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