Tutorial: Creating a GraphQL API for an Oracle database

Create a GraphQL API for an Oracle database by letting API Connect for GraphQL introspect the database and generate a GraphQL schema.

This tutorial uses the CLI command stepzen import db2 to introspect a backend Oracle database and generate a GraphQL schema.

Tip: You can alternatively write your schema in a .graphql GraphQL Schema Definition Language (SDL) file, using the GraphQL directive @dbquery to connect to the Oracle database. See Connecting an Oracle database for an example.

Generate the GraphQL Schema

The API Connect for GraphQL CLI can create a GraphQL API that connects data from a database backend.

  1. Login to API Connect for GraphQL. See Setting up your environment for steps.
  2. Run the following CLI command on your local machine to import schema:
    stepzen import oracle jdbc:oracle:thin:[<user>/<password>]@//<host>[:<port>]/<service>;
    Note: Ensure that the JDBC URL that connects to your Oracle database is valid.

    The command starts creating a GraphQL API that connects the data from your Oracle database, and prompts you for information as shown in the following steps.

  3. Specify the preferred endpoint where you want your GraphQL deployed. The CLI prompts with a default name for your endpoint (in this example, called api/binging-puma), but you can change it:
    ? What would you like your endpoint to be called? (api/binging-puma)

    The command creates a new directory that contains a stepzen.config.json file, which in turn contains your project's CLI configuration. The configuration includes the name of your endpoint, in this case, (api/binging-puma):

    Created /Users/path/to/project-folder/stepzen.config.json
    
    Downloading from StepZen...... done
  4. Deploy schema to StepZen.
    stepzen deploy
  5. Once the deployment is complete, test your GraphQL API using Postman or API Connect for GraphQL Dashboard.