GraphQL Client

Overview

You can use this Snap to run queries and access resources on a GraphQL endpoint. This Snap includes a built-in query builder that enables you to build queries with optimal efficiency. GraphQL queries provide a flexible and efficient way to fetch data from a server by allowing clients to retrieve precisely the data they require, minimizing the amount of unnecessary data transferred over the network.



Prerequisites

  • A valid API Suite account with the required permissions. An API Suite account is required only if the GraphQL end point requires credentials to function. Otherwise, the account can be omitted.

  • A GraphQL end point, which is the server URL.

  • A GraphQL schema defined on the server.

Pagination prerequisites:
  • In the schema provided by the server at the GraphQL endpoint, the root field that you want to query must implement cursor based pagination. It should use field parameters that enable pagination to be controlled by the user-defined variables at the top level of your GraphQL query (and pass them as arguments to the root field).

  • The schema must contain a Boolean field whose return value indicates the presence of additional pages of data.

  • The schema must contain a field whose value can be used to represent Position in the queried data (acting as a cursor). The field’s value must be usable directly for this purpose (without transformation or combination with another field’s value).

Limitations

  • This Snap does not support subscriptions.

  • For key-value pairs defined in the GraphQL variables settings, string values must be contained in double quotes (" ").

Behavior changes

  • The validation for the Variable name and Cursor variable name fields against variable names parsed from the query is now done in the document processing stage.

  • For Variable name and Cursor variable name suggestible fields, a warning message is displayed if the suggested variable names cannot be generated. This happens when the Query setting uses upstream parameters in its expression and the query cannot be evaluated during the suggestion stage.

  • Has additional page path, Next cursor path, and Cursor variable name will no longer produce configuration errors that stop Snap execution for validation issues, such as missing or invalid values, because they are now evaluated during document processing and the values may differ between input documents. These will now produce Snap data errors that write documents to the error view, and the Snap continues to process additional input documents.

  • When the Query setting is expression-enabled, there can be potential syntax errors, because the expression text that is carried over can cause the following syntax issues in the interactive builder:
    • When the query is copied from the Snap to the query builder, it remains in expression format (for example, ${variableName}) instead of being converted into valid GraphQL syntax.

    • As the expression isn’t evaluated before being passed into the query builder, the UI takes raw expressions instead of actual query values. Evaluation happens later. This behavior is bidirectional and expected. That is, when you copy a valid GraphQL query back into the Snap, it might not translate into an expression string. For example:

      If your query builder expects:

      query {
      
        user(id: "123") {
      
        name
      
        }
      
      }

      But the Snap uses expressions like:

      query {
      
        user(id: "${userId}") {
      
        name
      
        }
      
       }
The Query builder UI might display ${userId} as plain text rather than resolving it to 123
  • The GraphQL Snap retires 401 responses by reloading the account between attempts. If the maximum number of attempts is exhausted and the response still contains a 401, the Snap stops the execution instead of writing to the error view because the error is now unrecoverable.

  • The improved error-handling mechanism (to reflect how errors are reported in the raw GraphQL responses) in the GraphQL Client Snap has resulted in the following behavior changes:
    • Any error document caused by an error reported in the GraphQL Client Snap response now has a generic error message, similar to the errors reported by the GraphQL server while processing requests. The specific error message (and other additional details) are now available under the graphqlErrors field of the error document.

    • Data for all GraphQL errors reported for a single request (or single page request when pagination is enabled) is now available in the same error document under the graphqlErrors field.

    • Any error document generated by an error reported in the GraphQL Client Snap response now includes the query and variables for the request that caused it in the query and graphqlVariables fields, respectively.

Note: If you want to access the same error message string that is written to the error field in the previous Snap version (because it is now generalized to mimic the error reporting of the GraphQL endpoint), you can access the previous error output with the following expression:
jsonPath($, "$graphqlErrors[0].message")

  • Standard output:
    • Before: The GraphQL Client Snap returned no output document for the partially successful requests.

    • After: The Snap now returns the successful data processed from the GraphQL response in the output document, even if some GraphQL errors are also reported.

Note:

You can check downstream Snaps of the GraphQL Client Snap to verify if the Snaps appropriately handle successful output especially when the output wasn’t expected before, or a mix of error documents and successful output documents.

  • Pagination
    • When you enable pagination (wherein each input document may trigger multiple GraphQL requests for separate pages as you process the document), GraphQL errors in the response of one page will not cause page requests to stop early. Subsequent pages will continue to be requested as long as the data necessary to prepare the next page request is available in the previous page’s response.

Snap views

View Description Examples of upstream and downstream Snaps
Input

Each input document includes a set of variables that are used to create the GraphQL query.

You can use the input view for GraphQL variables, but it’s not required.

Output Each output document contains data retrieved from the GraphQL server.
  • When you select the Include extensions checkbox, the output document contains two fields (data and extensions), otherwise, it contains only the content of the data field.

  • Following is a sample output when you select the Include extensions checkbox:

[
  {
    data: {
      queryField1: {
        queryField2: {...}
      },
      ...
    },
    extensions: {
      extField1: {...},
      ...
    }
  }
]
  • Following is a sample output when you deselect the Include extensions checkbox:

[
  {
    queryField1: {
      queryField2: {...}
    },
    ...
  }
]
  • If Snap fails to retrieve the data, an error is written to the output document error view, which contains the fields error, reason, resolution, and stack trace. To view the error document, you must enable the Error view.

  • The error document of the GraphQL Client Snap also includes the graphqlErrors, query, and graphqlVariables fields when the GraphQL response reports field errors. Learn more about the GraphQL errors.

Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:

  • Stop Pipeline Execution Stops the current pipeline execution when an error occurs.
  • Discard Error Data and Continue Ignores the error, discards that record, and continues with the remaining records.
  • Route Error Data to Error View Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap settings

Legend:
  • Expression icon (): Allows using pipeline parameters to set field values dynamically (if enabled). SnapLogic Expressions are not supported. If disabled, you can provide a static value.
  • SnapGPT (): Generates SnapLogic Expressions based on natural language using SnapGPT. Learn more.
  • Suggestion icon (): Populates a list of values dynamically based on your Snap configuration. You can select only one attribute at a time using the icon. Type into the field if it supports a comma-separated list of values.
  • Upload : Uploads files. Learn more.
Learn more about the icons in the Snap settings dialog.
Field / Field set Type Description
Label String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: GraphQL Client

Example: GraphQL Client
GraphQL endpoint String Required. Specify the server URL that the Snap uses to connect to the GraphQL endpoint.

Default value: None.

Example: https://api.github.com/graphql

Query builder Button If you need help to form the query, click on this button to open the query builder. If the account is valid, the fields available from the server schema appear on the left side of the query builder. You can choose any fields to query on by clicking the dropdown lists and checkboxes. The formed query appears on the right. Click Ok to close the UI component and the query appears in under Query in the Snap Settings.

Query String/Expression Required. Specify the query in the text box. You can also click the expression icon to build your query dynamically, which can evaluate both pipeline and upstream parameters. If you need help building the query, click the Query Builder button to open the query builder.
Note:
  • GraphQL query variables (names prefixed with $ in the query) are defined in the String literal parts of the query, and so do not conflict with upstream parameters that are also prefixed with $)

  • A GraphQL query follows a hierarchical structure that matches the schema of the GraphQL API. It starts with a root query object and includes nested fields and relationships as needed. The query is sent to the GraphQL server, which processes the request and returns a response containing the requested data in the exact format specified by the client.

Warning: An expression-enabled Query setting might not align with the required formatting for the query builder UI to function correctly.

Default value: None.

Example:

query MyQuery {
 rateLimit {
 cost
 }
}
GraphQL variables Use this field set to add query parameters to be included in the request. This is optional and can either be defined directly in the URL, as separate parameters, or both.
Variable name String/Expression/ Suggestion Specify the name of the query variable. String values must be enclosed in double quotes (" ").
Note: Suggestions cannot be generated if the Query setting is an expression that references upstream document variables. Learn more.

Default value: None.

Example: limit

Variable value String/Expression Specify the value to assign to the variable.

Default value: None.

Example: 1 ”this is a string”

Client settings Additional settings for the GraphQL Client.
Trust all certificates Checkbox Select this checkbox to trust all certificates, such as self-signed certificates.

Default status: Deselected

Follow redirects Checkbox Select this checkbox to accept the response and redirect the request.

Default status: Selected

Maximum number of redirects Integer/Expression Specify the maximum number of redirects to allow.

Default value: 10

Example: 5

Read timeout (seconds) Integer Specify the number of seconds that the Snap must wait before terminating the request because of a failure to read from the target service.

Default value: 900

Example: 60

Connection timeout (seconds) Integer Specify the number of seconds that the Snap must wait before terminating the request because of a failure to establish a connection to the target endpoint or service.

Default value: 30

Example: 60

Enable pagination Checkbox Select this checkbox to return multiple pages of results through repeated requests with the GraphQL query.
  • When you select this checkbox, multiple requests to the query are made as defined in the pagination properties.

  • When you deselect this checkbox, only a single request to the query is made

Default status: Deselected

Pagination properties Use this field set to define pagination settings related to query executions that make multiple requests for pages of data.
Note: Best practices
  • We recommend that you limit your GraphQL query to only one root field when pagination is enabled. If you define multiple root fields in the query when pagination is enabled, it could cause duplicated data or produce unexpected results.

  • Use clear, descriptive names when defining GraphQL variables to ensure that you use the correct variables for the correct purposes, especially when defining the Cursor variable name.

Max page count Integer Appears when you select the Enable pagination checkbox
Specify the maximum number of pages of data to retrieve, if enough data is available. This value is the number of times a request is made with the specified query. The Snap stops fetching the next page when the maximum number of pages is reached.
  • This value must be greater than 0.

  • If you do not enter any value in this field, pages are requested until end of the data is reached. Requests with the query continue to be made until the value query response at the location defined by Has additional page path is false (no additional data can be returned by an additional request).

Default value: 3

Example: 7

Pagination interval (seconds) Integer Appears when you select the Enable pagination checkbox.

Specify the time interval between each page request in seconds.

Default value: 0

Example: 10

Pagination type Dropdown list Appears when you select the Enable pagination checkbox

Required. Select the type of pagination to use for the GraphQL query.

Currently, this Snap supports only cursor-type pagination.

Default value: Cursor

Example: Cursor

Has additional page path String/Expression Appears when you select the Enable pagination checkbox

Required. Specify the path to the field in the GraphQL schema that indicates whether an additional page of data is available.

The path should start at the root field, not at the user-defined top-level query.

You can define only one Has additional page path and one Next cursor path for the query.

For this reason, we recommend that you include only one root field in the GraphQL query.

Default value: N/A

Example: allEmployees.pageInfo.hasNextPage

Next cursor path String/Expression Appears when you select the Enable pagination checkbox

Required. Specify the path to the field in the GraphQL schema that contains the cursor value for subsequent page requests. The path should start at the root field, not at the user-defined top-level query.

This path represents the location in the specified query’s payload that contains the value to be used as the cursor in the next page request.

You can define only one Has additional page path and one Next cursor path for the query.

For this reason, we recommend that you include only one root field in the GraphQL query.

Default value: None.

Example: allEmployees.pageInfo.endCursor

Cursor variable name String/Expression/ Suggestion Appears when you select the Enable pagination checkbox

Required. Specify the name of the GraphQL variable that holds the cursor used for pagination. This variable is passed as the cursor value within the query.

Note:

The cursor variable name is validated against the variable names parsed from the query defined in the Query field. If it does not match one of these parsed variable names, the Snap fails with an error.

Ensure that the variable name entered in this field matches the name of the variable mapped to the cursor parameter of the root field. Using an incorrect variable name here may cause the cursor data for the next request to be sent to the wrong root field parameter. This misalignment could lead to multiple requests returning identical data (if Max page count is provided) or an infinite loop of requests (if Max page count is left blank).

Warning: Suggestions cannot be generated if the Query setting is an expression that references upstream document variables. Learn more.

Default value: None.

Example: afterCursor

Include extensions Checkbox/Expression Select this checkbox to include extensions data in the output document of the GraphQL response.
[
 {
 data: {
 queryField1: {
 queryField2: {...}
 },
 ...
 },
 extensions: {
 extField1: {...},
 ...
 }
 }
]
Note: The output document structure contains two fields, data and extensions. The latter includes the query result and extension content from the GraphQL response, or null if no respective content is available in the response. Learn more about the response format.
Tip: We recommend that you select this checkbox for optimum performance of the Snap.

When you deselect this checkbox, the output document uses the original document structure (to maintain backward compatibility) and contains only the content of the data field.

[
 {
 queryField1: {
 queryField2: {...}
 },
 ...
 }
]

Default status: Deselected

Snap execution Dropdown list
Choose one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute: Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only: Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Default value: Execute only

Example: Validate & Execute

Troubleshooting

Error Reason Resolution
This endpoint requires you to be authenticated The account information is incorrect. Verify the accuracy of the credentials to ensure that the account is properly configured. After updating, save the Snap to preserve the changes.
Unexpected end of the document The query is incorrect. Review your query and make the necessary corrections. Check for missing closing braces '}', ensuring all specified fields exist in the schema. Use the Query Builder button if you need help to construct the query.
Field <name of field> doesn't exist on type <name of type> The query is incorrect. Review your query and make the necessary corrections. Check for missing closing braces '}', ensuring all specified fields exist in the schema. Use the Query Builder button if you need help to construct the query.
GraphQL server responded with a query error The specified path for the Next cursor path was not found in the query response. Ensure that the GraphQL query includes the targeted path and that the Next cursor path setting is correct.
Selected pagination type is invalid The selected pagination type is not supported. Select a supported pagination type.

Examples