Skip to content

Commit

Permalink
Add changesets
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Feb 13, 2025
1 parent a1c67b4 commit 5f45a8c
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/light-dolphins-taste.md
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.
7 changes: 7 additions & 0 deletions .changeset/lucky-hats-push.md
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.
10 changes: 10 additions & 0 deletions .changeset/nice-waves-work.md
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.
26 changes: 26 additions & 0 deletions .changeset/polite-bees-care.md
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);
}

// ...
}
```
5 changes: 5 additions & 0 deletions .changeset/rich-eagles-cross.md
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.
25 changes: 25 additions & 0 deletions .changeset/soft-mails-clean.md
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.
9 changes: 9 additions & 0 deletions .changeset/sour-pillows-guess.md
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.
17 changes: 17 additions & 0 deletions .changeset/strange-seahorses-impress.md
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.
7 changes: 7 additions & 0 deletions .changeset/twenty-snakes-sort.md
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.

0 comments on commit 5f45a8c

Please sign in to comment.