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 {
streams(first: 10, orderBy: subgraphId, orderDirection: 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!) {
streams(first: $first, orderBy: subgraphId, orderDirection: 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.
query getStreams($first: Int!, $skip: Int!, $subgraphId: BigInt!) {
streams(
first: $first
skip: $skip
orderBy: $subgraphId
orderDirection: desc
where: { subgraphId_lt: $subgraphId }
) {
id
alias
category
}
}
streams(
first: $first
skip: $skip
orderBy: $subgraphId
orderDirection: desc
where: {
or: [
{ and: [{ sender: $sender }, { subgraphId_lt: $subgraphId }] }
{ and: [{ proxender: $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.
streams(
first: $first
skip: $skip
orderBy: $subgraphId
orderDirection: desc
where: {
or: [
{ and: [{ sender: $sender }, { subgraphId_lt: $subgraphId }] }
{ and: [{ proxender: $sender }, { subgraphId_lt: $subgraphId }] }
{ and: [{ recipient: $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: [
{ sender: $sender }
{ id_in: $streamIds }
{ subgraphId_lt: $subgraphId }
]
}
{
and: [
{ proxender: $sender }
{ id_in: $streamIds }
{ subgraphId_lt: $subgraphId }
]
}
{
and: [
{ recipient: $recipient }
{ id_in: $streamIds }
{ subgraphId_lt: $subgraphId }
]
}
]
}
Actions by stream
To avoid writing the same entity definitions over and over again, check out Fragments.
actions(
first: 100
orderBy: subgraphId # Action's subgraph id
orderDirection: desc
where: { stream: $streamId }
) {
id
category
stream {
...StreamFragment
}
}