Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL Data Connector docs #267

Merged
merged 16 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions spiceaidocs/docs/data-connectors/graphql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: 'GraphQL Data Connector'
sidebar_label: 'GraphQL Data Connector'
description: 'GraphQL Data Connector Documentation'
---

## Federated SQL query
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved

To connect to any [GraphQL](https://graphql.org/) endpoint as connector for federated SQL query, specify `graphql` as the selector in the `from` value for the dataset.
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved

```yaml
datasets:
- from: graphql:your-graphql-endpoint
name: my_dataset
params:
json_path: data.some.nodes
query: |
{
some {
nodes {
field1
field2
}
}
}
```

## Limitations
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved

- The GraphQL data connector does not support pagination.
- The GraphQL data connector does not support variables in the query.
- Acceleration only works with `arrow` engine. Support for other engines is in progress.
- You need to specify path to an object or array (preferably array) in the JSON response using `json_path` parameter. More fine grained access will be supported in future.
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved

gloomweaver marked this conversation as resolved.
Show resolved Hide resolved
## Configuration

The GraphQL data connector can be configured by providing the following `params`:

- `auth_token`: The authentication token to use to connect to the GraphQL server. Uses bearer authentication. E.g. `auth_token: github_pat_...`
- `auth_token_key`: The secret key containing the authentication token to use to connect to the GraphQL server. Can be used instead of `auth_token`.
E.g. `auth_token_key: github_token`
- `auth_user`: The username to use for basic auth. E.g. `auth_user: my_user`
- `auth_user_key`: The secret key containing the user to use for basic auth. Can be used instead of `auth_user`. E.g. `auth_user_key: my_secret_user`
- `auth_pass`: The password to use for basic auth. E.g. `auth_pass: my_password`
- `auth_pass_key`: The secret key containing the password to use for basic auth. Can be used instead of `auth_pass`. E.g. `auth_pass_key: my_secret_password`
- `query`: The GraphQL query to execute. E.g.
```yaml
query: |
{
some {
nodes {
field1
field2
}
}
}
```
- `json_path`: The path to the JSON data in the response. E.g. `json_path: data.some.nodes`

Configuration `params` are provided either in the top level `dataset` for a dataset source and federated SQL query.
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved

Example using github graphql API using Bearer Auth:
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved
```yaml
from: graphql:https://api.github.com/graphql
name: stars
params:
auth_token: [your_github_token>]
json_path: data.viewer.starredRepositories.nodes
query: |
{
viewer {
starredRepositories {
nodes {
name
stargazerCount
languages (first: 10) {
nodes {
name
}
}
}
}
}
}

```
You can query nested structures as well. Here is an example of querying a nested structure:
gloomweaver marked this conversation as resolved.
Show resolved Hide resolved
<img width="500" src="/img/graphql/stars-query.png" />

Example using Basic Auth:
```yaml
from: graphql:https://your-site.com/graphql
name: your_dataset
params:
auth_user: [your_user]
auth_pass: [your_password]
query: |
{
some {
nodes {
field1
field2
}
}
}
```
digadeesh marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions spiceaidocs/docs/data-connectors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Currently supported Data Connectors include:
| `clickhouse` | Clickhouse | Alpha | | `full` | ❌ |
| `spark` | Spark | Alpha | Spark Connect | `full` | ❌ |
| `ftp`, `sftp`| FTP/SFTP | Alpha | Parquet, CSV | `full` | ❌ |
| `graphql` | GraphQL | Alpha | GraphQL | `full` | ❌ |

## Data Connector Docs

Expand Down
1 change: 1 addition & 0 deletions spiceaidocs/docs/reference/spicepod/datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Where:
- [`postgres`](../../data-connectors/postgres/index.md)
- [`mysql`](../../data-connectors/mysql.md)
- [`clickhouse`](../../data-connectors/clickhouse.md)
- [`graphql`](../../data-connectors/graphql.md)

If the Data Connector is not explicitly specified, it defaults to `spiceai`.

Expand Down
Binary file added spiceaidocs/static/img/graphql/stars-query.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.