Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a case-insensitive graphql query?

Tags:

graphql

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

like image 778
Xun Lee Avatar asked Dec 21 '18 02:12

Xun Lee


People also ask

Is GraphQL query case sensitive?

Names in GraphQL are case‐sensitive. That is to say name , Name , and NAME all refer to different names.

What is __ Typename in GraphQL?

The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).

Is GraphQL strong typing?

Strongly-typed: GraphQL is strongly-typed. Given a query, tooling can ensure that the query is both syntactically correct and valid within the GraphQL type system before execution, i.e. at development time, and the server can make certain guarantees about the shape and nature of the response.

Does GraphQL support filtering?

Searching and filtering is a standard part of any GraphQL API.


2 Answers

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

like image 100
kotchwane Avatar answered Oct 19 '22 23:10

kotchwane


_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
 }
}
like image 38
prajwalAS Avatar answered Oct 20 '22 00:10

prajwalAS