GRAPHQL Table Function

Syntax

Description of the illustration graphql_table_function.gif

graphql_string_value::=

Description of the illustration graphql_string_value.gif

graphql_comment::=

Description of the illustration graphql_comment.gif

graphql_name::=

Description of the illustration graphql_name.gif

graphql_query::=

Description of the illustration graphql_query.gif

graphql_object_name::=

Description of the illustration graphql_object_name.gif

graphql_anyname::=

Description of the illustration graphql_anyname.gif

graphql_quoted_name::=

Description of the illustration graphql_quoted_name.gif

graphql_qbe_clause::=

Description of the illustration graphql_qbe_clause.gif

graphql_qbe_argument_list::=

Description of the illustration graphql_qbe_argument_list.gif

graphql_qbe_argument_list_continue::=

Description of the illustration graphql_qbe_argument_list_continue.gif

graphql_qbe_equality_argument::=

Description of the illustration graphql_qbe_equality_argument.gif

graphql_qbe_relational_argument::=

Description of the illustration graphql_qbe_relational_argument.gif

graphql_qbe_logical_argument::=

Description of the illustration graphql_qbe_logical_argument.gif

graphql_qbe_logical_argument_list::=

Description of the illustration graphql_qbe_logical_argument_list.gif

graphql_qbe_logical_argument_list_continue

Description of the illustration graphql_qbe_logical_argument_list_continue.gif

graphql_qbe_item_operator_argument::=

Description of the illustration graphql_qbe_item_operator_argument.gif

graphql_qbe_item_operator_list::=

Description of the illustration graphql_qbe_item_operator_list.gif

graphql_qbe_item_operator_list_continue::=

Description of the illustration graphql_qbe_item_operator_list_continue.gif

graphql_qbe_operator_name::=

Description of the illustration graphql_qbe_operator_name.gif

graphql_field_arguments::=

Description of the illustration graphql_field_arguments.gif

graphql_field_argument_list::=

Description of the illustration graphql_field_argument_list.gif

graphql_field_argument_list_continue::=

Description of the illustration graphql_field_argument_list_continue.gif

graphql_field_argument::=

Description of the illustration graphql_field_argument.gif

graphql_variable_name::=

Description of the illustration graphql_variable_name.gif

graphql_selection_set::=

Description of the illustration graphql_selection_set.gif

graphql_selection::=

Description of the illustration graphql_selection.gif

graphql_field::=

Description of the illustration graphql_field.gif

graphql_field_name::=

Description of the illustration graphql_field_name.gif

graphql_alias::=

Description of the illustration graphql_alias.gif

graphql_directives::=

Description of the illustration graphql_directives.gif

graphql_directive::=

Description of the illustration graphql_directive.gif

graphql_directive_arguments::=

Description of the illustration graphql_directive_arguments.gif

graphql_directive_argument_list::=

Description of the illustration graphql_directive_argument_list.gif

graphql_directive_argument_list_continue::=

Description of the illustration graphql_directive_argument_list_continue.gif

graphql_directive_argument::=

Description of the illustration graphql_directive_argument.gif

graphql_directive_argument_name::=

Description of the illustration graphql_directive_argument_name.gif

graphql_directive_argument_value::=

Description of the illustration graphql_directive_argument_value.gif

graphql_any_value::=

Description of the illustration graphql_any_value.gif

graphql_value::=

Description of the illustration graphql_value.gif

graphql_list_value::=

Description of the illustration graphql_list_value.gif

graphql_list_value_continue::=

Description of the illustration graphql_list_value_continue.gif

graphql_passing_clause::=

Description of the illustration graphql_passing_clause.gif

graphql_variable_list::=

Description of the illustration graphql_variable_list.gif

graphql_variable_list_continue::=

Description of the illustration graphql_variable_list_continue.gif

graphql_variable_identifier::=

Description of the illustration graphql_variable_identifier.gif

Purpose

The GRAPHQL table function is a SQL table function that you can use to query database tables and get the result in the form of JSON documents.

The GRAPHQL table function evaluates the embedded GraphQL query that is passed in as a string literal. The function returns rows derived from the GraphQL selection set, consistent with the JSON-relational duality mapping of the referenced object.

You can use the function only in the FROM clause of the SELECT statement.

Note: Whitespaces and comments can appear anywhere in the graphql_query clause.

Semantics

graphql_query

The input to the function, graphql_query, is a structured and hierarchical representation of the objects and fields to be queried .

The output of the function is a single column of type JSON consisting of the set of JSON documents corresponding to graphql_query.

graphql_passing_clause

If present, graphql_passing_clause provides variable bindings used by graphql_field_arguments or QBE. It starts with the keyword PASSING, and is followed by mappings of GraphQL variables to SQL expressions, literal, or bind variables.

graphql_selection_set

graphql_selection_set declares the the fields that you want to project from the current object.

graphql_field maps the underlying relational object (column or table) to the JSON field.

The optional argument graphql_alias changes the output key name.

The optional argument graphql_directives alters how the field is resolved or how it affects the metadata of the duality view.

Optional nested graphql_selection_set declares the fields to be projected in the nested object.

graphql_field_name can be the name of a table or a column or even a numeric literal.

graphql_alias renames the output key of the selected field. The underlying field lookup uses graphql_field_name. The output uses graphql_alias.

graphql_qbe_clause

Use graphql_qbe_clause to filter the JSON documents, by having predicates on the fields in the GraphQL query. It can express equality, relational, logical, and item-level operators.

graphql_qbe_clause is enclosed within parentheses and starts with the CHECK keyword, followed by the colon and the list of QBE arguments within curly braces.

qbe_equality_argument is a field-level equality predicate. It evaluates to true when the field equals the provided literal or bound variable.

qbe_relational_argument is a field-level relational predicate. The QBE operator refers to a comparison, which is applied to the specified field and the provided operand.

qbe_logical_argument refers to logical composition (for example, AND, or OR). The operator combines the enclosed argument list according to its truth table, evaluated against the current scope. Nested logical clauses are also allowed.

qbe_item_operator_argument refers to QBE item operators that can be used to first perform some transformations on the field before comparing it to the value.

graphql_directives

Directives are metadata-driven modifiers applied to fields or selection sets, written as @directive_name(directive_arguments) where each graphql_directive_argument is written as graphql_directive_argument_name: graphql_directive_argument_value. They control behavior like conditional inclusion, shape in the response, computed transformations, access and mutability. The arguments for a directive are name: value pairs. The value can be a name, a string, a number or even a list of values.

Comments in a GraphQL Expression

You can specify comments in a single line in a GraphQL expression. A single line comment is preceded by a hash (# )sign, in accordance with the GraphQL standard.

You can also specify SQL comments in the query containing the GraphQL expression. A single line SQL comment is preceded by a double dash (–). A SQL comment spanning multiple lines is enclosed within “/” and “/”.

Rules

Example: Valid Comments

  CREATE OR REPLACE JSON RELATIONAL DUALITY VIEW student_ov AS
    student { # this is a valid single line GraphQL comment
    _id: stuid
    Name: name
    -- SQL comments can be placed within GraphQL expression as well
};

Example

Querying the DB using GraphQL query

  SELECT * FROM GRAPHQL
('
    employees {
		  _id: employee_id
		  Name: first_name
	       }
');

The output is:

{
  "_id" : 174,
  "Name" : "Ellen"
}

{
  "_id" : 166,
  "Name" : "Sundar"
}

{
  "_id" : 130,
  "Name" : "Mozhe"
}

{
  "_id" : 105,
  "Name" : "David"
}

See Declarative GraphQL Developer’s Guide for more information on GraphQL.