diff --git a/README.md b/README.md
index cacc60e5..9ddd9fc3 100644
--- a/README.md
+++ b/README.md
@@ -86,6 +86,7 @@ function MyComponent() {
- [useMutation](#useMutation)
- Guides
- [SSR](#SSR)
+ - [Pagination](#Pagination)
- [Authentication](#Authentication)
- [Fragments](#Fragments)
- [Migrating from Apollo](#Migrating-from-Apollo)
@@ -187,6 +188,9 @@ This is a custom hook that takes care of fetching your query and storing the res
- `skipCache`: Boolean - defaults to `false`; If `true` it will by-pass the cache and fetch, but the result will then be cached for subsequent calls. Note the `refetch` function will do this automatically
- `ssr`: Boolean - defaults to `true`. Set to `false` if you wish to skip this query during SSR
- `fetchOptionsOverrides`: Object - Specific overrides for this query. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) for info on what options can be passed
+ - `updateData(previousData, data)`: Function - Custom handler for merging previous & new query results; return value will replace `data` in `useQuery` return value
+ - `previousData`: Previous GraphQL query or `updateData` result
+ - `data`: New GraphQL query result
### `useQuery` return value
@@ -197,7 +201,8 @@ const { loading, error, data, refetch, cacheHit, ...errors } = useQuery(QUERY);
- `loading`: Boolean - `true` if the query is in flight
- `error`: Boolean - `true` if `fetchError` or `httpError` or `graphQLErrors` has been set
- `data`: Object - the result of your GraphQL query
-- `refetch`: Function - useful when refetching the same query after a mutation; NOTE this presets `skipCache=true`
+- `refetch(options)`: Function - useful when refetching the same query after a mutation; NOTE this presets `skipCache=true` & will bypass the `options.updateData` function that was passed into `useQuery`. You can pass a new `updateData` into `refetch` if necessary.
+ - `options`: Object - options that will be merged into the `options` that were passed into `useQuery` (see above).
- `cacheHit`: Boolean - `true` if the query result came from the cache, useful for debugging
- `fetchError`: Object - Set if an error occured during the `fetch` call
- `httpError`: Object - Set if an error response was returned from the server
@@ -309,6 +314,130 @@ The `options` object that can be passed either to `useMutation(mutation, options
See [graphql-hooks-ssr](https://github.com/nearform/graphql-hooks-ssr) for an in depth guide.
+### Pagination
+
+[GraphQL Pagination](https://graphql.org/learn/pagination/) can be implemented in various ways and it's down to the consumer to decide how to deal with the resulting data from paginated queries. Take the following query as an example of offset pagination:
+
+```javascript
+export const allPostsQuery = `
+ query allPosts($first: Int!, $skip: Int!) {
+ allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) {
+ id
+ title
+ votes
+ url
+ createdAt
+ }
+ _allPostsMeta {
+ count
+ }
+ }
+`;
+```
+
+In this query, the `$first` variable is used to limit the number of posts that are returned and the `$skip` variable is used to determine the offset at which to start. We can use these variables to break up large payloads into smaller chunks, or "pages". We could then choose to display these chunks as distinct pages to the user, or use an infinite loading approach and append each new chunk to the existing list of posts.
+
+#### Separate pages
+
+Here is an example where we display the paginated queries on separate pages:
+
+```jsx
+import { React, useState } from 'react';
+import { useQuery } from 'graphql-hooks';
+
+export default function PostList() {
+ // set a default offset of 0 to load the first page
+ const [skipCount, setSkipCount] = useState(0);
+
+ const { loading, error, data } = useQuery(allPostsQuery, {
+ variables: { skip: skipCount, first: 10 }
+ });
+
+ if (error) return
+
+
+
+ );
+}
+```
+
+#### Infinite loading
+
+Here is an example where we append each paginated query to the bottom of the current list:
+
+```jsx
+import { React, useState } from 'react';
+import { useQuery } from 'graphql-hooks';
+
+// use options.updateData to append the new page of posts to our current list of posts
+const updateData = (prevData, data) => ({
+ ...data,
+ allPosts: [...prevData.allPosts, ...data.allPosts]
+});
+
+export default function PostList() {
+ const [skipCount, setSkipCount] = useState(0);
+
+ const { loading, error, data } = useQuery(
+ allPostsQuery,
+ { variables: { skip: skipCount, first: 10 } },
+ updateData
+ );
+
+ if (error) return