Skip to content

Martini Validating & Testing GraphQL APIs

Consuming GraphQL for Testing

Testing your GraphQL implementation requires an operational GraphQL server. This guide outlines how to set up a GraphQL server using the GraphQLDBReaderEndpoint for testing purposes.

Prerequisites

  • An operational database.
  • A configured database connection within the Martini Integrated Development Environment (MIDE).

Setup Steps

1. Creating a GraphQLDBReader Endpoint

To facilitate testing, you will first need to create a dedicated package for setting up the GraphQLDBReader Endpoint. For example, let's name it dynamograph.

  • Step 1: Navigate to your MIDE and establish a new package, e.g., dynamograph.
  • Step 2: Inside the dynamograph package, configure your GraphQLDBReader endpoint. Note the endpoint URL (e.g., /api/dynamograph/graphql). This URL will serve as your GraphQL host. For local testing, prepend the URL with your localhost address and port, forming a complete URL like http://localhost:8080/api/dynamograph/graphql. This will be used in subsequent steps.

2. Consuming the GraphQL Schema

Create a separate package for consuming the GraphQL schema generated by the GraphQLDBReader.

  • Step 1: Right-click on the package or code directory and select New > Consume API.
  • Step 2: Choose GraphQL Schema and input the schema URL formatted as follows: http://localhost:8080/graphql/<package-name>/<graphqldbreaderendpoint-name>/schema.graphql, then click Consume.

3. Configuring the HostSpecifier Service

Before executing GraphQL queries:

  • Step 1: Implement a HostSpecifier service where users can specify their GraphQL server URL. Here, you'll use the URL created in the initial setup (e.g., http://localhost:8080/api/dynamograph/graphql).
  • Step 2: Add a map step to the URL output in the HostSpecifier service, incorporating the URL of your GraphQL server.

Testing with GraphQL Oneliners

Following the configuration, you can utilize the generated services to test GraphQL queries. Feel free to modify or augment these services with your own queries to thoroughly test your setup.