GraphQL REST Connections
This library helps with pagination in GraphQL, when backed by REST services.
It will convert a Connection object, as defined by the Cursor Connection Specification:
and turn it into a list of headers and nodes, so that it could easily be returned by a RESTful service:
GET /users
Content-Type: application/json
x-pageinfo-start-cursor: d02dsf
x-pageinfo-end-cursor: b8df4=
x-pageinfo-has-previous-page: true
x-pageinfo-has-next-page: false
x-pageinfo-cursors: d02dsf,b8df4=
[
{"id": "56", "name": "mary"},
{"id": "78", "name": "joe"}
]
Note that the returned objects is a list of resources that are
exactly the same as ones you would get from /users/78
(for example).
The pagination info goes inside the pageinfo
headers.
Usage
isConnection(object)
-- determines whether the object is a ConnectionfromConnection(connection)
-- returns{nodes: [], headers: []}
toConnection(nodes, headers)
-- returns aconnection
In a REST service:
app;
In GraphQL service that is backed by the REST service above:
const userConnections = type: userConnection args: connectionArgs resolve: { requestPromise ; };