GraphQL support

Moesif natively supports GraphQL APIs throughout the entire platform.

Overview

Moesif parses your GraphQL operations into its respective components.
This allows you to filter and aggregate on any GraphQL query fields including GraphQL selectors and variables. This also enables you to create complex alerts in Moesif based on specific resources or responses even if for 200 OK HTTP status codes.

The parsed GraphQL query fields are available in Request.Graphql Query.

Accessing GraphQL query fields

Example

Consider the following set of criteria for a time series metrics plot for an API:

  • We want to plot the performance metrics of GraphQL mutation operations in a bar chart.
  • We want to plot this chart for each day for the past week.
  • We want to know the average latency and the maximum latency.
  • We want the chart show performance data for individual mutation operations.

For this set of criteria, the filters, group definition, and metrics specification look like this:

Chart settings for the previous example scenario

Notice that we’ve asked for a stacked bar chart.

With these settings, Moesif plots this chart:

Resulting chart with the preceding settings applied

We get a breakdown on the performances of each GraphQL mutation operations for each day.

Comparing GraphQL Analytics vs REST Analytics

Moesif can provide insight into how users access your GraphQL APIs compared to your REST APIs. This enables you to track how the usage differs if you’re migrating from REST to GraphQL.

Consider the following two examples showcasing similar metrics for GraphQL and REST APIs:

  • The first example shows a breakdown of mutatation operations by definition name.
  • The REST equivalent shows a breakdown of non GET API transactions broken down by API routes.
GraphQL segmentation chart breaking down GraphQL operations by definition name Viewing a breakdown of GraphQL operations by definition name
Segmentation chart for a REST API breaking down API calls by API routes Viewing a breakdown of REST calls by route

GraphQL over HTTP

There are four different ways to transport GraphQL over HTTP that Moesif supports.

  1. For the Content-Type set to application/graphql, Moesif treats the HTTP request body content as the GraphQL query string itself.

     {
       human(id: "1000") {
         name
         height(unit: FOOT)
       }
     }
    
  2. Your have specified the GraphQL query string in the URL using ?query= when receiving a HTTP GET request.
  3. A standard GraphQL POST request that uses application/json as the Content-Type header includes a JSON-encoded request body of the following form:

     {
       'query': '...',
       'operationName': '...',
       'variables': { 'myVariable': 'someValue', ... }
     }
    
  4. Alternatively, you have specified the GraphQL query string in the ?query= query string when receiving an HTTP POST request.

Filters and Segmentation

If Moesif detects a GraphQL request, you will find the parsed AST in Request.Graphql Query in the Filters pane.

Accessing GraphQL query fields

You can select any attribute in your GraphQL operation such as a specific query field name or argument value.

Like REST APIs, you have the same set of metrics tools for GraphQL APIs. For more information, see Introduction to Event Analytics and Logging.

Updated: