Mocking your GraphQL APIs.
GET
requests, or
the request body for all other request methods.
More detail on the request query format can be found on the official GraphQL site.
If the request query is valid and matches the API’s schema, the stub will respond with a 200
status and a JSON payload with the standard GraphQL response body format.
If you want more control over the format of the data that this default stub generates, there are a few configuration
options available for GraphQL’s built-in types.
[A-F0-9]+
(a string of one or more random characters
between A
and F
or 0
and 9
) or (enabled|disabled)
(either enabled
or disabled
).
Int and float values can be configured to only return values above a minimum and/or below a maximum.
An additional option is available for floats that sets the scale of all float values (i.e. the number of digits to the
right of the decimal point). For example, in the number 123.45
, the scale is 2
. The default scale is 2
.
Boolean values can be fixed to always return true
or always return false
.
Lists can be configured to always return a fixed amount of items. The default is 3
.
Match query
field of your stub.
When matching, the GraphQL query matcher retrieves a request’s query (either from the query parameters for GET
requests, or from the request body for other request methods) and check if it is semantically similar
to the expected query.
If it is, this will be considered a match.
To return a specific response body, enter this into the Response body
field as usual.
If you want to return a valid GraphQL response body in JSON format, you’ll need to specify the full JSON, including
the root fields (i.e. "data"
, "errors"
, "extensions"
), as outlined in the GraphQL official documentation.
Dynamic response templating is available for GraphQL stubs, like all other API types.
Convert to stub
button at the bottom of the page.
type User
, union StringOrBool
and schema
) will
always be ignored.
As for the queries, only the query operation that was specified in the request will be compared.
If the supplied operation name for the request was GetUser
, the two queries would be considered a match, as the only
part being compared would be
GetUsers
, the two queries would not be considered a match, as the first
query does not even contain an operation with that name.
$userId: ID
) will be removed, and all references to this
variable (e.g. id: $userId
) will be replaced with the value of $userId
supplied by the request.
So, if the request’s variables looked like
$userId
variable resolves to.
$userId: ID = 321
) will be used if no variable is supplied in the request.
If a variable is defined in the query, but is not supplied by the request and does not have a default value, the
variable’s value will resolve to null
.