Query GraphQL Endpoints for Data Extraction
GraphQL Loader fetches documents from GraphQL endpoints via custom queries, enabling data ingestion into LlamaIndex with optional authentication headers.
Why it matters
Effortlessly extract structured data from any GraphQL endpoint. This asset enables seamless integration of your GraphQL data sources into LlamaIndex for advanced analysis or use within LangChain agents.
Outcomes
What it gets done
Connect to specified GraphQL endpoints with optional credentials.
Execute custom GraphQL queries and retrieve nested results.
Load extracted data into LlamaIndex for further processing.
Utilize the loader as a tool within LangChain agents.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-reader-readers-graphql | bash Overview
GraphQL Loader
GraphQL Loader executes custom GraphQL queries against endpoints and transforms the results into LlamaIndex documents. It supports authentication via headers, parameterized queries with variables, and handles nested result structures from GraphQL APIs. Use GraphQL Loader when building LlamaIndex applications that need to pull data from GraphQL APIs. It can subsequently be used as a Tool in LangChain Agents.
What it does
GraphQL Loader retrieves documents from GraphQL endpoints by executing custom queries and transforming the results into LlamaIndex-compatible documents. It connects to GraphQL APIs with optional authentication headers, executes queries with optional variables, and returns nested result documents ready for indexing or downstream processing.
When to use - and when NOT to
Use GraphQL Loader when you need to ingest data from GraphQL APIs into your LlamaIndex pipeline. The loader executes queries with optional variables and supports optional authentication headers.
Inputs and outputs
You provide a GraphQL endpoint URI, optional authentication headers as a dictionary, a GraphQL query string, and optional query variables as parameters. The loader executes the query against the endpoint and returns documents containing the nested result data, ready for use in LlamaIndex workflows.
Integrations
GraphQL Loader integrates with LlamaIndex as a data reader for loading documents into indexes and pipelines. It can subsequently be used as a Tool in LangChain Agents for dynamic data retrieval. The loader uses the gql GraphQL library internally to handle query execution and communication with GraphQL endpoints.
Installation:
pip install llama-index-readers-graphql
Example usage:
import os
from llama_index.readers.graphql import GraphQLReader
uri = "https://countries.trevorblades.com/"
headers = {}
query = """
query getContinents {
continents {
code
name
}
}
"""
reader = GraphQLReader(uri, headers)
documents = reader.query(query, variables={})
Who it's for
Data engineers and AI developers building LlamaIndex applications who need to ingest data from GraphQL APIs.
Source README
GraphQL Loader
pip install llama-index-readers-graphql
This loader loads documents via GraphQL queries from a GraphQL endpoint.
The user specifies a GraphQL endpoint URL with optional credentials to initialize the reader.
By declaring the GraphQL query and optional variables (parameters) the loader can fetch the nested result docs.
Usage
Here's an example usage of the GraphQLReader.
You can test out queries directly on the site
import os
from llama_index.readers.graphql import GraphQLReader
uri = "https://countries.trevorblades.com/"
headers = {}
query = """
query getContinents {
continents {
code
name
}
}
"""
reader = GraphQLReader(uri, headers)
documents = reader.query(query, variables={})
This loader is designed to be used as a way to load data into LlamaIndex
and/or subsequently used as a Tool in a LangChain Agent.
It uses the gql GraphQL library for the GraphQL queries.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.