Home > Mobile >  Can we write GraphQL query for getting data based on predicate(condition)
Can we write GraphQL query for getting data based on predicate(condition)

Time:10-07

I need to write graphql query with some predicate like

Select * from User Where loginId like "abc%"

In GraphQL :

{
  getWithPredicate(clazz : String, predicates : Predicates){
        loginId
        enabled
        accountLocked
        accountExpired
        accountExpireBy
        createdBy
  }

}

Please suggest, if any default implementation is available in graphql.

Thanks in advance.

CodePudding user response:

This is possible. I once wrote a query like this. I needed to search the database using some search terms.

query ($title: String!, $company: String!, $city: String!, $investor: String!) {
    jobs(
      where: {
        and: [
          { title: { ilike: $title } },
          { company: { name: { ilike: $company } } },
          { city: { ilike: $city } },
          {company: {company_investors:{investor:{name: {ilike: $investor}}}}}
          
        ]
      }
    ) {
      id
      title
      city
      company {
        name
        id
        company_investors {
          investor {
            name
            id
          }
        }
      }
    }
  }

  • Related