Xun Lee
Xun Lee

Reputation: 312

how to make a case-insensitive graphql query?

Using GraphQL to fetch and parse a config file, sometimes the file name be podfile, sometimes be Podfile, so I am wondering how to make a case-insensitive query?

now I only can query repository->object: podfile and Podfile, but if the file name be podFILE, again not works.

query($org_name: String!, $resp_name: String!)
                {
                repository(owner: $org_name name: $resp_name){
                          object: object(expression: "%s:proj.ios_mac/podfile"){
                                                              ... on Blob{
                                                                          text
                                                                          }
                                                              }
                          ios_object_1: object(expression: "%s:proj.ios_mac/Podfile"){
                                                              ... on Blob{
                                                                          text
                                                                          }
                                                              }
                          }
                }

REF:https://github.community/t5/How-to-use-Git-and-GitHub/graphql-api-resource-query-is-case-sensitive/m-p/6003

Upvotes: 10

Views: 16645

Answers (5)

Matt Saunders
Matt Saunders

Reputation: 4074

For anyone using Primsa with PostgreSQL, you need to set the mode property to insensitive, e.g.

const users = await prisma.user.findMany({
  where: {
    email: {
      endsWith: 'prisma.io',
      mode: 'insensitive'
    },
  },
})

Reference.

Upvotes: 0

paq
paq

Reputation: 117

There's an abbreviated way of writing the _ilike operator now.

For matching a string with insensitive case you can use eqi.

query MyQuery {
  posts (
    filters: { name : { eqi: "my post"}}
  ) { ... }
}

Or for querying a string that contains the same value with insensitive case you can use containsi.

query MyQuery {
  posts (
    filters: { name : { containsi: "my "}}
  ) { ... }
}

Upvotes: -1

prajwalAS
prajwalAS

Reputation: 79

_similar: "%key%" performs Case sensitive query
_ilike:   "%key%" performs case insensitive query

For Eg : Below query will return all devices with name contains iphone. It fails to return objects if name contains "iPhone" i.e. the query is case sensitive.

query MyQuery {
  devices: devices(where: {name: { _similar: "%iphone%"}}) {
    name
 }
}

Below query will return all objects with name containing "iphone", "IPhone". i.e. case insensitive

query MyQuery {
  devices: devices(where: {name: { _ilike: "%iphone%"}}) {
    name
 }
}

Upvotes: 4

kotchwane
kotchwane

Reputation: 2404

Using the _ilike operator makes the query case-insensitive.

query MyQuery {
  heroes(where: {name: {_ilike: "%baTmaN%"}}) {name, movie }
}

Source & documentation: https://github.com/hasura/graphql-engine/issues/1516

Upvotes: 6

ecthiender
ecthiender

Reputation: 503

Names in GraphQL are case-sensitive, as per the spec. Names include field names, type names, variable names etc.

So, in short it is not possible to do it.

Upvotes: 3

Related Questions