Custom GraphQL Syntax in Oracle

The GraphQL type system serves as a structured schema that defines the data model for an API, specifying the types of data available, their relationships, and how they can be queried or modified.

This chapter introduces the standard GraphQL type system and describes the custom GraphQL syntax used in Oracle.

A standard GraphQL type is basically a logical representation of an entity and it’s attributes. The following example provides the GraphQL type system for the relational tables created in Setting up the Car Racing Dataset.

Example 2-1 GraphQL Type System for the Car-Racing Relational Tables

# Represents a racing team
type Team {
  team_id: ID!           # Team primary key
  name: String!          # Team name
  points: Int!           # Points team has scored
  driver: [Driver!]!     # List of drivers on the team
}

# Represents an individual driver
type Driver {
  driver_id: ID!          # Driver primary key
  name: String!           # Driver name
  points: Int!            # Points the driver has scored
  team: Team              # The team the driver belongs to
  race: [DriverRaceMap!]! # Races the driver has participated in
}

# Mapping table representing a driver participating in a race
type DriverRaceMap {
  driverRaceMapId: ID!   # Primary key for this mapping
  race: Race!            # Associated race
  position: Int          # Driver's finishing position in the race
}

# Represents a race event
type Race {
  _id: ID!                  # Race primary key
  name: String!             # Race name
  laps: Int!                # Number of laps in the race
  date: String              # Race date/time as ISO string
  podium: JSON              # JSON data about podium finishers (unstructured)
  result: [DriverRaceMap!]! # Results mapping driver to positions
}

The GraphQL type system is organized around these foundational elements:

Note: Standard GraphQL supports all of the preceding types. However, GraphQL in Oracle focuses only on the Scalar, Objects and Query Types and this book provides detailed information only about these types. Read the official GraphQL documentation to gain a better understanding of other types in the GraphQL type system.