Queries
Building on top of the entity structure defined earlier, here are some common GraphQL queries for fetching data from the Sablier subgraph.
Recent streams
The 10 most recent streams
query getStreams {
Stream(limit: 10, distinct_on: [subgraphId], order_by: { subgraphId: desc }) {
id
alias
category
asset {
id
symbol
}
}
}
Paginated streams
To query streams in sets/pages (and avoid edge cases where using timestamps may skip simultaneous batched streams), we
can use the unique subgraphId
.
This query includes pagination.
The next streams indexed before the last seen subgraphId
query getStreams($first: Int!, $subgraphId: numeric!) {
Stream(
limit: $first
distinct_on: [subgraphId]
order_by: { subgraphId: desc }
where: { subgraphId: { _lt: $subgraphId } }
) {
id
alias
category
asset {
id
symbol
}
}
}
Streams by sender (with support for the old V2.0)
To support both proxy senders (case 3) and native senders (case 2) we query for:
- streams where the connected account is the native sender
- streams where the connected account is the proxender - the owner of the proxy labeled as a sender
This query includes pagination.
warning
Some queries, especially those using OR
will potentially yield duplicate results. To make sure we only retrieve unique
streams/entities with a query, we make use of the distinct_on
filter (and apply it on keys included in order_by
).
The next streams created by an address (natively or through a proxy)
Stream(
limit: $first
offset: $skip
distinct_on: [subgraphId]
order_by: { subgraphId: desc }
where: {
_or: [
{ _and: [{ sender: {_eq: $sender} }, { subgraphId: {_lt: $subgraphId} }] }
{ _and: [{ proxender: {_eq: $sender} }, { subgraphId: {_lt:$subgraphId} }] }
]
}
) {
id
alias
category
}