Use SQL WHERE and ORDER BY with the GraphQL Table Function

Use SQL predicates and ordering with the JSON data returned by the GRAPHQL() table function.

The GRAPHQL() table function returns query results in the data column. You can apply SQL WHERE and ORDER BY clauses to the rows returned by the table function.

The following example filters driver rows by using JSON_VALUE on the data column, and orders the result by the top-level JSON name field:

SELECT JSON_SERIALIZE(data PRETTY) AS data FROM GRAPHQL('
    query {
        driver {
            id: driver_id
            name
            points
        }
    }
')
WHERE JSON_VALUE(data, '$.points' RETURNING NUMBER) > 300
ORDER BY data."name";