Skip to content

Commit

Permalink
Merge branch 'main' into release-3.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jul 29, 2021
2 parents 7ca8d30 + 110eb8a commit 0377d22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions docs/source/data/queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,27 @@ function DelayedQuery() {

By default, the `useQuery` hook checks the Apollo Client cache to see if all the data you requested is already available locally. If all data _is_ available locally, `useQuery` returns that data and _doesn't_ query your GraphQL server. This `cache-first` policy is Apollo Client's default **fetch policy**.

You can optionally specify a different fetch policy for a given query. To do so, include the `fetchPolicy` option in your call to `useQuery`:
You can specify a different fetch policy for a given query. To do so, include the `fetchPolicy` option in your call to `useQuery`:

```js
```js{2}
const { loading, error, data } = useQuery(GET_DOGS, {
fetchPolicy: "network-only"
fetchPolicy: "network-only" // Doesn't check cache before making a network request
});
```

### `nextFetchPolicy`

You can _also_ specify a query's `nextFetchPolicy`. If you do, `fetchPolicy` is used for the query's _first_ execution, and `nextFetchPolicy` is used to determine how the query responds to future cache updates:

```js{3}
const { loading, error, data } = useQuery(GET_DOGS, {
fetchPolicy: "network-only", // Used for first execution
nextFetchPolicy: "cache-first" // Used for subsequent executions
});
```

For example, this is helpful if you want a query to always make an initial network request, but you're comfortable reading from the cache after that.

### Supported fetch policies

<table class="field-table">
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ After you [get started](./get-started/), check out the full Apollo Client docume
We recommend the following articles in particular:

* **[Queries](./data/queries/) and [Mutations](./data/mutations/)**. These are the read and write operations of GraphQL.
* [**Configuring the cache**](./caching/cache-configuration). Apollo Client's normalized cache enables you to skip network requests entirely when data is already available locally.
* [**Caching overview**](./caching/overview/). Apollo Client's normalized cache enables you to skip network requests entirely when data is already available locally.
* [**Managing local state**](./local-state/local-state-management/). Apollo Client provides APIs for managing both remote and local data, enabling you to consolidate all of your application's state.
* [**Basic HTTP networking**](./networking/basic-http-networking/). Learn how to send custom headers and other authentication metadata in your queries.
* [**Testing React components**](./development-testing/testing/). Test your GraphQL operations without requiring a connection to a server.
Expand Down

0 comments on commit 0377d22

Please sign in to comment.