graph-node
graph-node copied to clipboard
WIP: improve pagination and introduce new connection-based GraphQL API
Related: https://github.com/graphprotocol/graph-node/issues/613
Background
This PR introduces a non-breaking change, that adds xyzConnection filed on a Query, and the matching XyzConnection type for easy pagination.
Related:
- https://relay.dev/graphql/connections.htm
- https://graphql.org/learn/pagination/
For a given input schema:
type Purpose @entity {
# ...
}
We'll get now:
type Query {
# ...
purposesConnection(
first: Int
last: Int
after: String
before: String
orderBy: Purpose_orderBy
orderDirection: OrderDirection
where: Purpose_filter
subgraphError: _SubgraphErrorPolicy_ = deny
): PurposeConnection!
}
type PurposeConnection {
totalCount: Int!
edges: [PurposeEdge!]!
pageInfo: PageInfo!
}
type PurposeEdge {
cursor: String!
node: Purpose!
}
Changes in this PR
TODO
- [x] Implement GraphQL schema generation.
- [ ] Cursor calculation
- [ ] SQL implementation
- [ ]
Nodeinterface - [ ] Testing
My one concern with the proposed schema is the totalCount field on PurposeConnection since that can be very expensive to calculate. I think it would be better to leave that out for the first cut of this feature.
My one concern with the proposed schema is the
totalCountfield onPurposeConnectionsince that can be very expensive to calculate. I think it would be better to leave that out for the first cut of this feature.
Sure, we can support only parts of this spec, thanks for the heads-up!
Closing this since it's not been active for a while. Feel free to reopen when you're ready to work on this again