GraphQL Query Test Step

Applies to ReadyAPI 3.57, last modified on December 20, 2024

About GraphQL Query test step

The GraphQL Query test step is a request based on a GraphQL Query request. It means that you can validate the query and a response from the server against the GraphQL schema.

Tip: If you do not have a GraphQL schema, use the GraphQL Request test step.

Add GraphQL Query Request test step

  1. Right-click the request in the Navigator panel and select Add to Test Case

    Show image

    – or –

    Open the request editor and click Add to Test Case.

    Show image

  1. In the test case editor, select the GraphQL Query Request test step from the toolbar.

    Show image

    – or –

    Click in the navigator and select the SOAP Request test step from the APIs and Connections section.

    Show image

    Tip: Use the Search field to filter test steps.
  1. ReadyAPI shows the Add Request Test Step dialog:

    GraphQL testing in ReadyAPI: Add GraphQL Query Request test step dialog

    Click the image to enlarge it.

    In the dialog, you select the base request and the target test case to which you want to add the new test step. Additionally, you specify the Valid HTTP Status Code and Valid Response SLA assertions.

Edit GraphQL Query test step

To modify the settings of the test step, use its editor:

GraphQL Support in ReadyAPI: GraphQL Query test step

Click the image to enlarge it.

Name Description
Request Displays the GraphQL query. You write queries by using the general GraphQL syntax.
You can view available object fields in the Code Completion window. To invoke it, press Ctrl+Space.

In the Query Variables panel, you specify variables used in the query in the JSON format (see the example below).
Tip: Both fields in the Request panel support property expansions.
Raw Displays the header and body of the request as text.
ReadyAPI populates this tab after you run the test step.
Auth Use this panel to specify the authorization type and authorization parameters for your request.
Headers Use this panel to create and modify custom header fields.

Property list

You can also change the test step behavior by using the step properties on the GraphQL Request Properties and Custom GraphQL Query Test Step Properties panels in the Navigator.

Name Description
Name

The test step’s name.

Description

Text that describes the test step.

Encoding

The encoding of the request data in the charset header. You can select one of the predefined values or specify a custom value. If it is empty, the utf-8 encoding is used.

Endpoint

A URL address of the tested web service.

Timeout

The number of milliseconds to wait for a server response. If there is no response during this period, the test step fails. 0 (zero) or no value means an infinite waiting time.

Bind Address

The network interface (IP address) through which ReadyAPI will send the request.

Follow Redirects

Enables handling of redirects. Specify true to allow sending the request to a new address. When it is set to false, the request receives the actual response from the server without going to a new address.

Follow 302 Redirect with GET

If set to true, when the server redirects the request with the 302 status code, ReadyAPI sends the GET method.

Works only when the Follow Redirects property is set to true.
SSL Keystore

The file that stores the private keys used to authorize ReadyAPI when connecting to the server. This works for HTTPS requests only.

Dump File

Specifies the fully qualified name of the file to which you want to save the server response. Leave this property empty if you don't want to save the response to a file.

Max Size

Specifies the maximum number of response bytes ReadyAPI shows in the editor to save memory. To show the entire response, specify 0.

The specified assertions may fail if there is not enough data for verification.
Discard Response

When this option is set to true, ReadyAPI deletes the response data from memory after the assertion run is over. Works only if the test step editor is closed.

The values on the Custom GraphQL Query Test Step Properties tab are available to other test steps in your project. For instance, you can verify these property values with the Assertion test step, or you can check them and change the execution flow with the Conditional GoTo test step.

You can load the values of custom properties from a file or save them to a file. To learn more, see About Properties.

This tab contains the following properties that provide access to the request and response data:

Name Description
Response

The response data without headers. You can see the same content in the response's JSON panel. To get the response data without headers, use the RawResponse property.

RawRequest

The body content of the sent request. You can see the same content in the request's Raw panel. Property expansions are converted to the expected values. To get data with unconverted property expansions, use the Request property.

ResponseAsXml

The response data as an XML DOM document (if possible).

RawResponse

The response data with headers. You can see the same content in the Raw panel of the response editor. To get the response data without headers, use the Response property.

Test step toolbar

The test step toolbar contains commands that allow you to modify a test step, change the base GraphQL query, or customize the appearance of the test step editor.

GraphQL support in ReadyAPI: GraphQL Query test step toolbar

Click the image to enlarge it.

Verifying response

To add an assertion, use the Add Assertion button on the Request toolbar.

To validate the response content using the data of received responses, click Smart Assertion on the Response editor. To learn more, see Validate response content.

To modify assertions, use the Assertion panel.

The following assertions are available for the GraphQL Query test step:

Name Description
Property Content:
Contains Verifies that the response contains the specified string.
Equals Verifies that the value of a property is equal to the specified value.
Equals (Binary) Checks whether the binary response is equal to a file.
JsonPath Count Counts the occurrences of the specified element.
JsonPath Existence Match Checks whether the specified element exists.
JsonPath Match Checks whether the specified element matches the expected value.
JsonPath RegEx Match Checks whether the specified element matches a regular expression.
Message Content Assertion Verifies that the message contains the expected contents.
Not Contains Verifies that the response does not contain the specified value.
Compliance, Status and Standards
HTTP Header Equals Checks whether the response contains the expected value of an HTTP header.
HTTP Header Exists Verifies that the response contains the specified HTTP header.
Invalid HTTP Status Codes Checks whether the HTTP status code is not in the specified list.
JSON Schema Compliance Verifies that the request and response comply with the specified JSON schema.
Valid HTTP Status Codes Checks whether the HTTP status code is in the specified list.
Smart Assertion Verifies the message content and metadata such as headers and the status code.
Script
Script Assertion Executes a script to perform a custom assertion.
SLA
Response SLA Checks whether the response was returned during the specified timeout.
Security
Sensitive Information Exposure Verifies that the response does not contain any sensitive information.

Logging

While the test step editor is open, brief information on the sent requests is specified on the Log tab. If the test step is run as part of a test case, you can see a more detailed log in the Transaction Log panel.

Working with

Below, you can find information on common tasks you can perform with the GraphQL Query test step.

To specify a query with variables:

  1. Declare a variable the query will accept:

    query($myid: String!) {
      customer (id: $myid) {
        id
        name
        email
      }
    }

  2. In the Query Variables panel, specify the values of the variables in the JSON format:

    {
      "myid": "1"
    }

When you send a request, ReadyAPI will send the variables along with the query, and a GraphQL service will use the variable values in the query:

Testing GraphQL in ReadyAPI: Specifying Query Variables

Click the image to enlarge it.

See Also

GraphQL Mutation Test Step
GraphQL Request Test Step
Testing GraphQL APIs
GraphQL APIs
GraphQL Requests

Watch the video
 
Highlight search results