I have a query where I want to filter results by seeing what is LIKE the input variable that the user will type.
Here is my query
query MyQuery($domain:String!, $hash:String!) {
hashtags_hashtags(where: {domain: {_eq: $domain}}, limit: 15, offset: 5, order_by: {hashtag: asc}) {
hashtag
responses_languages(where: {language: {_eq: "english"}, hashtag: {_ilike: %$hash%}}) {
hashtag
response
}
}
}
So When i was testing the _ilike filter in hasura console it only works with a sting written like this ex. "%cheese%". The percent signs work well with the string but when I try to do the same thing with my variable $hash it doesn't work. How to do the _ilike with a variable?? Of course I put the $hash after _ilike without the % but it did not return anything. It only works if I use a regular string not a variable. How am I suppose to write _ilike + variable in Hasura graph Ql. Oh and my project is in Javascript.
Thanks
I have a query where I want to filter results by seeing what is LIKE the input variable that the user will type.
Here is my query
query MyQuery($domain:String!, $hash:String!) {
hashtags_hashtags(where: {domain: {_eq: $domain}}, limit: 15, offset: 5, order_by: {hashtag: asc}) {
hashtag
responses_languages(where: {language: {_eq: "english"}, hashtag: {_ilike: %$hash%}}) {
hashtag
response
}
}
}
So When i was testing the _ilike filter in hasura console it only works with a sting written like this ex. "%cheese%". The percent signs work well with the string but when I try to do the same thing with my variable $hash it doesn't work. How to do the _ilike with a variable?? Of course I put the $hash after _ilike without the % but it did not return anything. It only works if I use a regular string not a variable. How am I suppose to write _ilike + variable in Hasura graph Ql. Oh and my project is in Javascript.
Thanks
Share Improve this question asked Sep 19, 2020 at 13:14 Mystery ManMystery Man 6552 gold badges11 silver badges23 bronze badges1 Answer
Reset to default 10Query 'body' is not for any kind of operations, no concatenation, no evaluation, no string literals etc.
You must pass ready, prepared earlier, string as variable.
variables: {
domain: "some domain",
hash: `%${someHashVariable}%`
}
// in query simply
// ... hashtag: {_ilike: $hash}