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
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.
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.
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
).
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
}
Streams by sender or recipient
To show all streams that have an address marked as a sender (all cases) or a recipient, extend the example above to account for the recipient aspect.
This query includes pagination.
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} }] }
{ _and: [{ proxender: {_eq: $recipient} }, { subgraphId: {_lt: $subgraphId} }] }
]
}
) {
id
alias
category
}
Streams by filters
The official V2 Interfaces will provide a search interface where one may query for a list of streams using the following filters (the conditions will be combined)
- the sender address
- the recipient address
- a list of stream identifiers
This query includes pagination.
where: {
_or: [
{
_and: [
{ chainId: { _eq: $chainId } }
{ sender: { _eq: $sender } }
{ subgraphId: { _lt: $subgraphId } }
]
}
{
_and: [
{ chainId: { _eq: $chainId } }
{ proxender: { _eq: $sender } }
{ subgraphId: { _lt: $subgraphId } }
]
}
{
_and: [
{ chainId: { _eq: $chainId } }
{ recipient: { _eq: $recipient } }
{ subgraphId: { _lt: $subgraphId } }
]
}
]
}
Actions by stream
To avoid writing the same entity definitions over and over again, check out Fragments.
Action(
limit: 100
distinct_on: [subgraphId]
order_by: { subgraphId: desc }
where: { stream_id: {_eq: $streamId} }
) {
id
category
stream {
...StreamFragment
}
}