I'm working with Airbyte for the first time and tr...
# ask-community-for-troubleshooting
c
I'm working with Airbyte for the first time and trying to build pagination into a GraphQL request where the cursor needs to be passed into the GraphQL body. I can see lots of great examples of pagination in the request but not as much for injecting it into the GraphQL body. Is there some documentation I've missed?
k
Yes, Airbyte does support injecting pagination cursors into the body of a GraphQL request, and there is documentation covering this scenario. To inject a cursor (or any value) into a nested field in the JSON body of a GraphQL request, you should use the
request_body_json
option in the
request_options_provider
. For GraphQL, this is typically done by specifying a
field_path
that points to the nested location (such as
variables.after
for a cursor). Here’s how you can configure it:
Copy code
yaml requester:   type: HttpRequester   url_base: "<https://your.graphql.api/>"   http_method: "POST"   request_options_provider:     request_body_json:       query: "query($after: String) { users(after: $after) { id name } }"       variables:         after: "{{ next_page_token }}"
Or, using the more advanced
RequestOption
component for nested injection:
Copy code
yaml page_cursor_option:   request_option:     type: RequestOption     inject_into: body_json     field_path:       - variables       - after
This configuration ensures that the cursor value (e.g.,
next_page_token
) is injected into the correct place in the GraphQL request body. The documentation also notes that nested key injection is only available for
body_json
injection, and the
field_path
property is specifically designed for this use case. The
field_name
property is being deprecated in favor of
field_path
for future compatibility. You can find more details and examples in the official Airbyte documentation on [Request Options Provider](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/request-options#request-options-provider) and specifically the section on GraphQL request injection, which demonstrates how to inject values into nested fields in the request body for GraphQL queries. This should cover your use case for paginating GraphQL APIs with Airbyte. If you need to use a dynamic cursor value (e.g., from the previous response), you would use a Jinja expression like
{{ next_page_token }}
or
{{ last_records[-1]['cursor'] }}
as appropriate for your API and pagination strategy. For more on pagination strategies and cursor extraction, see the [pagination documentation](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/pagination#cursor-pagination) as well. Summary: - Use
request_body_json
with
field_path
for nested GraphQL variables. - Inject the cursor using Jinja expressions. - See the linked documentation for detailed examples and schema references. [Request Options Provider (GraphQL injection)](https://docs.airbyte.com/platform/connector-development/config-based/understanding-the-yaml-file/request-options#request-options-provider) [Pagination in Connector Builder UI](https://docs.airbyte.com/platform/connector-development/connector-builder-ui/pagination#cursor-pagination)
c
@kapa.ai You're answer suggests the use of the
next_page_token
. Is that derived from the cursor_value of the CursorPagination pagination_strategy?
k
A message from kapa.ai
Yes, in Airbyte's config-based connectors, the value referred to as
next_page_token
in the context of pagination is derived from the
cursor_value
defined in the
CursorPagination
pagination strategy. The
cursor_value
is a Jinja template that extracts the cursor (such as a token or ID) from the previous API response, and this value is then used as the token for the next page request. When you configure pagination with
CursorPagination
, Airbyte evaluates the
cursor_value
template after each response to determine the value to use for the next request. This value is then available for injection into the next request—whether as a query parameter, header, or, in your case, within the body of a GraphQL request—using the appropriate request option configuration. For example, if you set:
Copy code
yaml pagination_strategy:   type: CursorPagination   cursor_value: "{{ response['data']['pageInfo']['endCursor'] }}"
The value extracted by this template will be used as the
next_page_token
for the next request, and you can inject it into your GraphQL body as needed. This mechanism is described in the documentation, which states that the cursor value is evaluated from the response and then used to request the next page of records. The injection into the request body (such as a GraphQL variable) is handled by the request options configuration, which can use this token wherever needed in the request structure [see documentation](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/pagination#cursor) [see also](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/CursorPagination). So, to summarize: Yes, the value you inject (often called
next_page_token
in examples) is derived from the
cursor_value
of your
CursorPagination
strategy.
c
@kapa.ai Is there a way to use page_size too?
k
A message from kapa.ai
Yes, you can use
page_size
together with cursor-based pagination in Airbyte's config-based connectors. The
CursorPagination
object includes a
page_size
property, which allows you to specify the number of records to request per page. This value can be injected into your GraphQL request body in the same way as the cursor, using the
field_path
property for nested JSON injection. For example, your pagination strategy might look like this:
Copy code
yaml pagination_strategy:   type: CursorPagination   cursor_value: "{{ response['data']['pageInfo']['endCursor'] }}"   page_size: 100
And you can inject the
page_size
into your GraphQL variables like this:
Copy code
yaml page_size_option:   request_option:     type: RequestOption     inject_into: body_json     field_path:       - variables       - limit
This will inject the
page_size
value into the
variables.limit
field of your GraphQL request body. The documentation confirms that the
CursorPagination
object supports a
page_size
property, and provides an example of how to use it for pagination in API requests [see documentation](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/reference#/definitions/CursorPagination).