@FLEX Directive

The @flex GraphQL directive in Oracle is used to designate a column typically of JSON data type as a flex column. @flex directive is used with JSON relational duality views and is not supported in the GraphQL table function.

This exposes not only regular, predefined columns from a table, but also additional, dynamic fields present in the JSON data of the flex column. The fields inside a flex column are unpacked and included in the resulting JSON document, making your data model more flexible and extensible.

When a column is marked with @flex, any key-value pairs stored in the JSON flex column become part of each document produced by the duality view. This is especially useful for cases where you may have evolving or variable attributes associated with a record and you do not want to update the database schema for every change.

Assume you have a DRIVER table structured as follows:

Column Type Description
driver_id NUMBER Unique driver identifier
name VARCHAR2 Driver name
extras JSON JSON column for flexible, extra fields
Let’s say the extras column in your data contains dynamic attributes like birthplace or sponsor, stored as key-value pairs in the JSON. The sample row would look like:
  • driver_id: 101
  • name: "Lando Norris"
  • extras: { "birthplace": "Bristol", "sponsor": "Team X" }

The duality view using GraphQL in Oracle would look like:

driver {
  driverID: driver_id
  name
  extras @flex
}
Oracle will automatically include all fields from the extras flex column in the resulting JSON output:

{                                                                              
  "driverId": 101,                                                               
  "name": "Lando Norris",                                             
  "birthplace": "Bristol",                                                         
  "sponsor": "Team X"
 }

Note:

Note that birthplace and sponsor come directly from the extras column and are dynamically included due to the use of @flex directive.

Detailed of this directive in the context of JSON-relational duality view is covered in Flex Columns, Beyond the Basics.