---
tags: v3
---
# @daohaus/dao-data Query Exploration
## superfluid query library example
https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/sdk-core/src
- Query class with several prescribed queries
- ie) listAllSuperTokens, listIndexes, listUserInteractedSuperTokens
**function args**
filter
- each function has it's own filter type
- so arg value is key/value of subgraph field/value
```typescript
export interface IAccountTokenSnapshotFilter {
readonly account?: string;
readonly token?: string;
}
export interface IStreamRequestFilter {
readonly sender?: string;
readonly receiver?: string;
readonly token?: string;
}
```
paging
- default: { skip: 0, take: 100 }
- can take override: { skip: number, take: number }
- You can also paginate by lastId, this allows you to bypass the limitation of the max skip of 5000 entities.
- 3 types = createSkipPaging, createPageNumberPaging, createLastIdPaging
- maybe figures out which type by the shape of the args (skip vs/ lastId)
- data res comes with a nextPage helper function to call and get the next set of results.
```typescript
export type Paging = {
readonly take: number;
readonly skip?: number;
readonly lastId?: string;
};
```
ordering
- object with orderBy and orderDirection
- default to createdAt and desc
```typescript
export type Ordering<TOrderBy extends string> = {
orderBy: TOrderBy;
orderDirection: OrderDirection;
};
```
interface
```typescript
const results = await sf.query.listAllSuperTokens(
{ isListed: true },
{ skip: 5, take: 150 },
{
orderBy: "createdAtBlockNumber",
orderDirection: "desc"
});
```
- they create the instance with the provider and network. we might want to support multiple networks at once for cross chain pages (hub)
polling
- single `on` in the class? do all functions then somehow repsond to this?
- not sure how that is working
- callback
- takes events - need more exploration here
- seems to keep track of all contract events and then just polls event logs, if a new one show up it fires the callback
- unsubscribe function
- if this gets triggered in the app, the sdk stops polling
- checks that interval isn't too small (> 1000)
- takes a timeout to turn off
```typescript
// A subscription function which allows you to subscribe to events via polling.
on(
callback: (events: AllEvents[], unsubscribe: () => void) => void,
ms: number,
account?: string,
timeout?: number
)
// not sure how this looks
const results = await sf.query.listAllSuperTokens(
{ isListed: true },
{ skip: 5, take: 150 },
{
orderBy: "createdAtBlockNumber",
orderDirection: "desc"
}, doSomething(events, unsubscribe));
```
function operation
1) function always validates the filter fields
2) call the [SubgraphClient](https://github.com/superfluid-finance/protocol-monorepo/blob/dev/packages/sdk-core/src/subgraph/SubgraphClient.ts) request
- has some cleaning function for the filter is missing values
- uses `import { request } from "graphql-request";``
- query object are getting generated somehow and take a filter object for `where` arg
- [see here](https://github.com/superfluid-finance/protocol-monorepo/blob/dev/packages/sdk-core/src/subgraph/queries/getTokens.graphql)
3) maps the results (some hydration)
4) adds pagination info
- hydrates with next page helpers
- paging - current paging object
- nextPaging - iif there is another page it passes a function to get the next page
- data
- [see here](https://github.com/superfluid-finance/protocol-monorepo/blob/0839cae1488e9db6c1eac69208bd55079dcf40c2/packages/sdk-core/src/pagination.ts#L82)
## Takeaways
- We should use the `list` and `find` keywords for query/function names
- list = pulling many, find = pulling one
- ie) listProposals, findProposal
- How can we make these filter types more flexible
- any key/field name
- stretch: other comparison types (greater than, does not equal)
- Pagination
- i tend to pagination by last createdDate instead of skip/take - due to 5000 max skip. but this requires ording by createdAt
- could replicate `createLastIdPaging` + `nextLastIdPaging `
- Polling
- could take inspiration - maybe work off eventTransaction and only fire query again if new one comes in
- call back somehow returns data to the app?
- function has to return void for typing?
- we raged on 2 types of polling
1) app wide/always on: poll the latest eventTransaction, if a new one come in notify the app, the app can then refire/refresh queries
2) tied to a pedning transaction: poll on a specific transactionHash, once it come in the app can then refresh data
- more to learn in how they handle subgraph types
- https://github.com/superfluid-finance/protocol-monorepo/tree/dev/packages/sdk-core/src/subgraph