query queryRecipesContents($slug: String!) {
queryRecipesContents(filter: "data/slug/iv eq '$slug'") {...}
It responds here
{
"errors": [
{
"message": "Variable '$slug' is never used in operation '$queryRecipesContents'.",
"locations": [
{
"line": 1,
"column": 29
}
],
"extensions": {
"code": "NO_UNUSED_VARIABLES",
"codes": [
"NO_UNUSED_VARIABLES"
],
"number": "5.8.4"
}
}
],
}
I also try to use “data/slug/iv eq \”$slug\“”, but the problem is still here.
How do you use the variable in the GraphiQL?
Please use code blocks to format your code. Not quotes.
I found a way to filter the data.
query QueryRecipe($filter: String!) {
queryRecipesContents(filter: $filter) {...}
Variables:
{"filter": "data/slug/iv eq 'baked-lemon-herb-salmon'"}
We can pass the entire eq expression as a parameter.
Inspired xetera.dev/src/scripts/me.ts at 6521238915fee28505b4fe600b700d45bc8fc46e · Xetera/xetera.dev · GitHub
1 Like
Great,
I actually wanted to implement a filter language in GraphQL, where you have intellisense, but this would create so much types. Basically you need one field for every schema field and operator, e.g. something like
iv_eq: "11"
or you have complex objects like
iv: { eq: "11" }
Yep,
I remember the origin GraphQL support eq key-value filter.
So far, we can use this way as a temporary solution.
This is usually built in the application code. Some libraries also support GraphQL filters, but the problem is the amount of additional types, you could easily create 100.000+ per schema and they are expensive to create and you have to keep them in memory.