graph-node icon indicating copy to clipboard operation
graph-node copied to clipboard

WIP: improve pagination and introduce new connection-based GraphQL API

Open dotansimha opened this issue 3 years ago • 2 comments

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
  • [ ] Node interface
  • [ ] Testing

dotansimha avatar Feb 02 '22 15:02 dotansimha

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.

lutter avatar Feb 18 '22 20:02 lutter

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.

Sure, we can support only parts of this spec, thanks for the heads-up!

dotansimha avatar Feb 22 '22 09:02 dotansimha

Closing this since it's not been active for a while. Feel free to reopen when you're ready to work on this again

lutter avatar Apr 08 '24 16:04 lutter