Testing a GraphQL API with the Test tab

For a GraphQL API definition, the Test tab contains a GraphiQL editor. You can use the GraphiQL editor to help construct a GraphQL query. When you test your GraphQL API, the response is displayed in the GraphiQL editor.

You can test a GraphQL query in either of the following ways:

  • Use a POST operation, in which case the query is sent in the body of the operation request.
  • Use a GET operation, in which case the query is sent as a query parameter.

For each operation type, you can test the query against either the GraphQL API endpoint itself, or against the cost endpoint that returns details of the cost of a request to the GraphQL API endpoint.

Whichever method and endpoint you use, you can either supply the query directly, or you can use the GraphiQL editor to help construct the query; the editor provides type ahead assistance based on the schema that is defined for the API, and highlights errors along with correction suggestions. The schema was initially uploaded when the GraphQL API definition was created, but might have been modified subsequently. For details on creating a GraphQL API definition, see Creating a GraphQL proxy API. For details on modifying the schema, see Using the GraphQL schema editor.

Before you begin

See Preparing an API for debugging with the Test tab for the requirements that your API definition must meet for you to test it with the Test tab.

Procedure

  1. In the Request section, select the required operation type and endpoint; for example:
    • POST https://myserver.com/myorg/sandbox/mybasepath/graphql
    • GET https://myserver.com/myorg/sandbox/mybasepath/graphql/cost
  2. On the GraphiQL tab, in the left hand pane of the editor, supply the query; for example:
    {
      accounts(limit: 100) {
        name {
          first
          last
        }
      }
    }
  3. If required, you can supply additional request headers on the Parameters tab.
  4. If your query includes variables, you can supply values for the variables in the Query Variables pane. For example, if the query is as follows:
    query MyQuery($Query__accounts__limit: Int)
    {
      accounts(limit: $Query__accounts__limit) {
        name {
          first
          last
        }
      }
    }
    you can set a value for the Query__accounts__limit by entering the following in the Query Variables pane:
    {
      "Query__accounts__limit": variable_value
    }
    where variable_value is the required value.
  5. Click either Send, or the Execute Query icon GraphiQL Execute Query icon in the editor. The response is displayed in the GraphiQL editor, and the Trace section shows you how the API call was executed. For details on the trace information, see Examine the trace.