-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1c67b4
commit 5f45a8c
Showing
9 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
`useLazyQuery` no longer supports SSR environments and will now throw. If you | ||
need to run a query in an SSR environment, use `useQuery` instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
The execute function returned from `useLazyQuery` now only supports the `context` and `variables` options. This means that passing options supported by the hook no longer override the hook value. | ||
|
||
To change options, rerender the component with new options. These options will take effect with the next query execution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
The result resolved from the promise returned from the exeucte function in | ||
`useLazyQuery` is now an `ApolloQueryResult` type and no longer includes all the | ||
fields returned from the `useLazyQuery` hook tuple. | ||
|
||
If you need access to the additional properties such as `called`, `refetch`, | ||
etc. not included in `ApolloQueryResult`, read them from the hook instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
`useLazyQuery` will no longer rerender with the loading state when calling the execute function the first time unless the `notifyOnNetworkStatusChange` option is set to `true`. | ||
|
||
If you prefer the behavior from 3.x, rerender the component with | ||
`notifyOnNetworkStatusChange` set to `false` after the execute function is | ||
called the first time. | ||
|
||
```ts | ||
function MyComponent() { | ||
const [notifyOnNetworkStatusChange, setNotifyOnNetworkStatusChange] = useState(true); | ||
const [execute] = useLazyQuery(query, { notifyOnNetworkStatusChange }); | ||
|
||
async function runExecute() { | ||
await execute(); | ||
|
||
// Set to false after the initial fetch to stop receiving notifications | ||
// about changes to the loading states. | ||
setNotifyOnNetworkStatusChange(false); | ||
} | ||
|
||
// ... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
The `reobserve` option is no longer available in the result returned from `useLazyQuery`. This was considered an internal API and should not be used directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
`useLazyQuery` no longer supports calling the execute function in render and will now throw. If you need to execute the query immediately, move the call to the execute function to `useEffect`. | ||
|
||
```ts | ||
function MyComponent() { | ||
const [execute, { loading, called }] = useLazyQuery(query); | ||
|
||
if (!loading && !called) { | ||
// This will now throw | ||
execute() | ||
} | ||
|
||
// Call the `execute` function in `useEffect` instead. | ||
useEffect(() => { | ||
execute(); | ||
}, [execute]); | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
NOTE: This change is limited to React 17 and 18. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
The `defaultOptions` and `initialFetchPolicy` options are no longer supported | ||
with `useLazyQuery`. | ||
|
||
If you use `defaultOptions`, pass those options directly to the hook instead. If | ||
you use `initialFetchPolicy`, use `fetchPolicy` instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
`useLazyQuery` no longer supports `variables` in the hook options and therefore no longer performs variable merging. The execute function must now be called with `variables` instead. | ||
|
||
```ts | ||
function MyComponent() { | ||
const [execute] = useLazyQuery(query); | ||
|
||
function runExecute() { | ||
execute({ variables: { ... }}); | ||
} | ||
} | ||
``` | ||
|
||
This change means the execute function returned from `useLazyQuery` is more type-safe. The execute function will require you to pass a `variables` option if the query type includes required variables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@apollo/client": major | ||
--- | ||
|
||
`useLazyQuery` will now only execute the query when the execute function is called. Previously `useLazyQuery` would behave like `useQuery` after the first call to the execute function which means changes to options might perform network requests. | ||
|
||
You can now safely rerender `useLazyQuery` with new options which will now take effect for the next query. |