faucet-source-graphql
A config-driven GraphQL API source with cursor-based pagination, JSONPath record extraction, and pluggable authentication.
Part of the faucet-stream ecosystem.
Installation
[]
= "0.1"
= { = "1", = ["full"] }
Or via the umbrella crate:
= { = "0.2", = ["source-graphql"] }
Quick Start
use ;
async
Configuration
GraphqlStreamConfig
| Field | Type | Default | Description |
|---|---|---|---|
endpoint |
String |
(required) | GraphQL endpoint URL |
query |
String |
(required) | The GraphQL query string |
variables |
Value |
{} |
Variables to pass with the query |
auth |
GraphqlAuth |
GraphqlAuth::None |
Authentication method |
headers |
HeaderMap |
empty | Additional request headers |
records_path |
Option<String> |
None |
JSONPath expression to extract records from the response. When None, the data field of the response is returned as a single record |
pagination |
Option<GraphqlPagination> |
None |
Pagination configuration. None for single-page queries |
max_pages |
Option<usize> |
None |
Maximum number of pages to fetch |
Authentication (GraphqlAuth)
| Variant | Description |
|---|---|
None |
No authentication |
Bearer(String) |
Bearer token in the Authorization header |
Custom(HeaderMap) |
Custom headers (e.g. API keys, cookies). Not serializable |
Pagination (GraphqlPagination)
Cursor-based pagination following the Relay specification with pageInfo { hasNextPage, endCursor }.
| Field | Type | Default | Description |
|---|---|---|---|
has_next_page_path |
String |
"$.data.*.pageInfo.hasNextPage" |
JSONPath to the hasNextPage boolean in the response |
cursor_path |
String |
"$.data.*.pageInfo.endCursor" |
JSONPath to the endCursor string in the response |
cursor_variable |
String |
"after" |
Name of the cursor variable in the GraphQL query |
page_size |
Option<usize> |
None |
Optional page size, injected as a variable |
page_size_variable |
String |
"first" |
Name of the page size variable |
Pagination includes loop detection -- if the same cursor is returned twice in a row, pagination stops.
Config Loading
use ;
use GraphqlStreamConfig;
let config: GraphqlStreamConfig = load_json?;
let config: GraphqlStreamConfig = load_env_file?;
Example JSON config
Example .env file
GRAPHQL_ENDPOINT=https://api.github.com/graphql
GRAPHQL_QUERY=query { viewer { login } }
GRAPHQL_MAX_PAGES=10
Config Schema Introspection
use Source;
let stream = new;
let schema = stream.config_schema;
println!;
Examples
Simple single-page query
use ;
use GraphqlAuth;
use json;
let config = new
.variables
.auth;
let stream = new;
let records = stream.fetch_all.await?;
Relay cursor pagination with record extraction
use ;
use ;
use json;
let config = new
.auth
.records_path
.pagination
.max_pages;
let stream = new;
let users = stream.fetch_all.await?;
println!;
Using with a Pipeline
use ;
use ;
let source = new;
let pipeline = new;
let result = pipeline.run.await?;
println!;
License
Licensed under MIT or Apache-2.0.