最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use the % sign with a variable in graphql query - Stack Overflow

programmeradmin6浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 10

Query '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}
发布评论

评论列表(0)

  1. 暂无评论