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.
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:
Notice that we’ve asked for a stacked bar chart.
With these settings, Moesif plots this chart:
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
Segmentation chart for a REST API breaking down API calls by API routes
GraphQL over HTTP
There are four different ways to transport GraphQL over HTTP that Moesif supports.
-
For the
Content-Type
set toapplication/graphql
, Moesif treats the HTTP request body content as the GraphQL query string itself.{ human(id: "1000") { name height(unit: FOOT) } }
- Your have specified the GraphQL query string in the URL using
?query=
when receiving a HTTP GET request. -
A standard GraphQL
POST
request that usesapplication/json
as theContent-Type
header includes a JSON-encoded request body of the following form:{ 'query': '...', 'operationName': '...', 'variables': { 'myVariable': 'someValue', ... } }
- Alternatively, you have specified the GraphQL query string
in the
?query=
query string when receiving an HTTPPOST
request.
Filters and Segmentation
If Moesif detects a GraphQL request, you will find the parsed AST in Request.Graphql Query in the Filters pane.
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.