@well-known-components/thegraph-component v1.0.0-20220518223517.commit-bae0ceb
thegraph-component
A port used to query thegraph's subgraphs.
API
Create
To create the component you'll have to supply the subgraph's url. You can get it from thegraph's site, for example: https://api.thegraph.com/subgraphs/name/decentraland/marketplace
const url = "https://api.thegraph.com/subgraphs/name/decentraland/marketplace"
await createSubgraphComponent(url, { config, logs, metrics, fetch })Query
The main API is:
query: <T>(query: string, variables?: Variables) => Promise<T>So you can call it like this:
type Element = {
id: string
count: number
}
function getElementsQuery() {
return `query getCollection($count: Number!) {
elements(where: { count_gt: $count }) {
id
count
}
}`
}
await subgraph.query<{ elements: Element[] }>(getElementsQuery(), { count: 5 })Configuration
It supports two ENV variables:
SUBGRAPH_COMPONENT_RETRIES: How many retries per subraph query. Defaults to3.SUBGRAPH_COMPONENT_QUERY_TIMEOUT: How long to wait until a connection is timed-out. Defaults to10000ms or 10 seconds.SUBGRAPH_COMPONENT_TIMEOUT_INCREMENT: How much time to add after each retry. The value will be multiplied for the attempt number. For example: if the increment is 10000, it'll wait 10s the first retry, 20s next, 30s, etc. Defaults to10000ms or 10 seconds.SUBGRAPH_COMPONENT_BACKOFF: How long to wait until a new query is tried after an unsuccessfull one (retrying). Defaults to500ms.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago