GraphQL Filter Specifications: Arguments

Filtering using GraphQL in Oracle AI Database is achieved by using arguments.

Arguments in GraphQL is analogous to where clause in SQL queries. The syntax for defining the argument includes one or many comma separated predicates which takes the field name and its corresponding value that needs to be filtered in the output.

SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    driver (teamId: 301) {
        id: driver_id
        name
        points
        teamId: team_id
    }
');
The above example, teamID: 301 is the filtering argument. The example would produce details of the driver where the teamID field is equal to 301:
DATA                                                                           
--------------------------------------------------------------------------------
{                                                                              
  "id" : 101,                                                                  
  "name" : "Lando Norris",                                                     
  "points" : 282,                                                              
  "teamId" : 301                                                               
}                                                                              
                                                                                 
{                                                                              
  "id" : 102,                                                                  
  "name" : "Oscar Piastri",                                                    
  "points" : 384,                                                              
  "teamId" : 301                                                               
}                                                                              
                                                                                 
 
2 rows selected.
Using a specific field argument does not mandate that the field must be present in the output. So the following example would not produce an error where team_id used as a filter argument is not specified in the output:
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    driver (team_id: 301) {
        id: driver_id
        name
        points
    }
');
The output would just display the id, name and points of the driver object where team_id is equal to 301:
DATA                                                                           
--------------------------------------------------------------------------------
{                                                                              
  "id" : 101,                                                                  
  "name" : "Lando Norris",                                                     
  "points" : 282                                                               
}                                                                              
                                                                                 
{                                                                              
  "id" : 102,                                                                  
  "name" : "Oscar Piastri",                                                    
  "points" : 384                                                               
}                                                                              
                                                                                 
 
2 rows selected.

LIMIT Argument

The GraphQL limit argument in Oracle AI Database limits the output to the specified number of JSON objects. The syntax is simple - the keyword limit, followed by a : and then an integer which defines the limit.

The limit:5 in the following example would retrieve only 5 objects irrespective of the number of objects in the table:
SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    driver (limit: 5) {
        id: driver_id
        name
        points
    }
');