How to use _like with '%' in a graphql string?

114

just store you value inside another variable and then use that variable with ${variable} inside the graphql query it will help you

Share:
114
Serus
Author by

Serus

Updated on January 02, 2023

Comments

  • Serus
    Serus over 1 year

    I'm using flutter with graphql/client library. I'm trying to create a string for a gql query that has a where condition:

    const getUsers = """
    query getUsers(\$nameToSearch: String!) {
       users(where: {name: {_ilike: %\$nameToSearch%}}) {
          id
          name
       }
    }
    """;
    

    the problem is that I don't know how to insert the '%' symbol in that string... the example is wrong and I tried all the combinations. Online I found only basic examples that doesn't use the '%' symbol

    What is the correct syntax?

  • Serus
    Serus over 2 years
    I would like to use the 'variables' parameter in query options to pass the variables to avoid injections... at the moment i solved building the string in the classic way but I'm pretty sure that it isn't the correct way