Using Literals in the Passing Clause

The passing clause of the GraphQL variables allows the table function to use fixed value of the variable directly, eliminating the need for the bind variable.

Example 3-22 Using Numeric Literal in the Passing Clause of a GraphQL Variable

SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    query getTeamById($teamId: Int) {
        team (id: $teamId) {
            id: team_id
            name
            points
        }
    }
' passing 301 as "teamId");

The preceding code would fetch the requested information from the team table where the teamId is 301. Note that, the literal value 301 is passed using the passing clause of the GraphQL variable.

DATA
--------------------------------------------------------------------------------
{
  "id" : 301,
  "name" : "McLaren Mercedes",
  "points" : 666
}


1 row selected.

Similarly, you could also pass a character (string) literal by enclosing the value in single quotes.

Example 3-23 Using String Literal in the Passing Clause of a GraphQL Variable

SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    query getTeamByName($teamName: String) {
        team (name: $teamName) {
            id: team_id
            name
            points
        }
    }
' passing 'Ferrari' as "teamName");

The preceding example would fetch the requested information from the team table where the team name is Ferrari.

DATA
--------------------------------------------------------------------------------
{
  "id" : 302,
  "name" : "Ferrari",
  "points" : 652
}


1 row selected.