Skip to main content
Version: Next

GraphQL

GraphQL source connector

Support Those Engines

Spark
Flink
SeaTunnel Zeta

Description

The GraphQL source connector reads data from a GraphQL endpoint. It supports:

  • HTTP batch or polling reads with a GraphQL query.
  • WebSocket subscription reads with a GraphQL subscription.
  • JSON response parsing by content_field and schema.fields.
  • Request headers, request parameters, GraphQL variables, and timeout settings.

Key Features

Supported DataSource Info

In order to use the GraphQL connector, the following dependency is required. It can be downloaded via install-plugin.sh or from Maven central repository.

DatasourceSupported VersionsDependency
GraphQLuniversalDownload

Source Options

NameTypeRequiredDefaultDescription
urlStringYes-GraphQL endpoint. Use http:// or https:// for query mode. Use ws:// or wss:// for subscription mode.
queryStringYes-GraphQL statement. Source supports query, and supports subscription only when enable_subscription = true.
variablesMapNo-GraphQL variables sent with the request body.
enable_subscriptionBooleanNofalseWhether to use WebSocket subscription mode. When false, the connector uses HTTP POST.
timeoutLongNo-Request timeout value passed to the HTTP client parameter map.
headersMapNo-HTTP request headers, such as authentication headers.
paramsMapNo-HTTP request parameters.
formatStringNoTEXTResponse format inherited from HTTP source. Use json when schema.fields is configured.
content_fieldStringNo-JSONPath used to pick the data array or object from the GraphQL response, for example $.data.source.
schema.fieldsConfigNo-Output fields and SeaTunnel data types. Configure it when reading structured JSON rows.
poll_interval_millisIntNo-Interval between HTTP requests in streaming query mode.
max_retriesIntNo5Maximum reconnect attempts for WebSocket subscription mode.
retry_delay_msIntNo5000Delay between WebSocket reconnect attempts, in milliseconds.
retryIntNo-Maximum HTTP retry times when an HTTP request returns an IOException.
retry_backoff_multiplier_msIntNo100HTTP retry backoff multiplier in milliseconds.
retry_backoff_max_msIntNo10000Maximum HTTP retry backoff in milliseconds.
enable_multi_linesBooleanNofalseWhether to split the HTTP response by line before parsing.
connect_timeout_msIntNo12000HTTP connection timeout in milliseconds.
socket_timeout_msIntNo60000HTTP socket timeout in milliseconds.
common-optionsConfigNo-Source common options. See Source Common Options.

Notes

  • In normal query mode, url must start with http:// or https://.
  • In subscription mode, set enable_subscription = true and use a ws:// or wss:// URL.
  • Source queries cannot be GraphQL mutation operations. Use the GraphQL sink for mutation requests.
  • content_field is usually needed because GraphQL responses are commonly wrapped under data.
  • When schema.fields is configured, set format = "json" and point content_field to the array or object that should become SeaTunnel rows.
  • For streaming query mode over HTTP, configure poll_interval_millis to control how often SeaTunnel sends the same query again.
  • For WebSocket subscription mode, max_retries and retry_delay_ms only control reconnect behavior after a subscription connection fails.

Task Example

Query GraphQL Data

env {
parallelism = 1
job.mode = "BATCH"
}

source {
GraphQL {
plugin_output = "graphql_source"
url = "http://graphql:8080/v1/graphql"
format = "json"
content_field = "$.data.source"
query = """
query MyQuery($limit: Int) {
source(limit: $limit) {
id
val_bool
val_double
val_float
}
}
"""
variables = {
limit = 2
}
schema = {
fields {
id = "int"
val_bool = "boolean"
val_double = "double"
val_float = "float"
}
}
}
}

sink {
Console {
plugin_input = "graphql_source"
}
}

Subscribe to GraphQL Data

env {
parallelism = 1
job.mode = "STREAMING"
}

source {
GraphQL {
plugin_output = "graphql_subscription"
url = "ws://graphql:8080/v1/graphql"
format = "json"
content_field = "$.data.source"
enable_subscription = true
max_retries = 5
retry_delay_ms = 5000
query = """
subscription MySubscription {
source {
id
val_bool
val_double
val_float
}
}
"""
schema = {
fields {
id = "int"
val_bool = "boolean"
val_double = "double"
val_float = "float"
}
}
}
}

sink {
Console {
plugin_input = "graphql_subscription"
}
}

Changelog

Change Log
ChangeCommitVersion
[Feature][connector-http] Parameters support placeholder replacement (#9184)https://github.com/apache/seatunnel/commit/8617014edc2.3.11
[Feature][Connector-V2] Support GraphQL Connector (#8557) (#9021)https://github.com/apache/seatunnel/commit/9eec2520c02.3.11