Skip to content

Commit

Permalink
call setOptions based on watchQueryOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Aug 16, 2021
1 parent bcd160e commit e7eab4c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/react/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,26 @@ export function useQuery<
options,
result,
data: void 0 as TData | undefined,
watchQueryOptions: createWatchQueryOptions(query, options),
});

// An effect to recreate the obsQuery whenever the client or query changes.
// This effect is also responsible for checking and updating the obsQuery
// options whenever they change.
useEffect(() => {
const watchQueryOptions = createWatchQueryOptions(query, options);
let nextResult: ApolloQueryResult<TData> | undefined;
if (
ref.current.client !== client ||
!equal(ref.current.query, query)
) {
const obsQuery = client.watchQuery(
createWatchQueryOptions(query, options),
);
const obsQuery = client.watchQuery(watchQueryOptions);
setObsQuery(obsQuery);
nextResult = obsQuery.getCurrentResult();
} else if (!equal(ref.current.options, options)) {
obsQuery.setOptions(createWatchQueryOptions(query, options))
.catch(() => {});
} else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {
obsQuery.setOptions(watchQueryOptions).catch(() => {});
nextResult = obsQuery.getCurrentResult();
ref.current.watchQueryOptions = watchQueryOptions;
}

if (nextResult) {
Expand Down

0 comments on commit e7eab4c

Please sign in to comment.