Skip to content

Commit

Permalink
Remove nagging updateQuery deprecation warning.
Browse files Browse the repository at this point in the history
Now that fetchMore's updateQuery callback is implemented in terms of the
supported/documented cache.updateQuery method, I feel better about
allowing fetchMore to continue to take an updateQuery callback.

Also, everyone with any ability to migrate from updateQuery to
InMemoryCache field policies has presumably already done so, so this
warning is less useful now than it was following the release of AC3.
  • Loading branch information
benjamn committed Mar 29, 2022
1 parent 857583c commit 1b3406a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 65 deletions.
46 changes: 0 additions & 46 deletions src/__tests__/fetchMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,52 +153,6 @@ describe('updateQuery on a query with required and optional variables', () => {
});
});

// TODO: Delete this test after removal of updateQuery from fetchMore.
// This test squashes deprecation notice errors when the suite is run, but not
// when individual tests are run.
describe('updateQuery with fetchMore deprecation notice', () => {
const query = gql`
query thing {
entry
}
`;

const result = {
data: {
__typename: 'Query',
entry: 1,
},
};

const result1 = cloneDeep(result);
itAsync('fetchMore warns exactly once', (resolve, reject) => {
const spy = jest.spyOn(console, "warn").mockImplementation();
const link = mockSingleLink({
request: { query },
result,
}, {
request: { query },
result: result1,
}).setOnError(reject);

const client = new ApolloClient({
link,
cache: new InMemoryCache(),
});

const observable = client.watchQuery({query});
return observable.fetchMore({updateQuery: (prev) => prev}).then(() => {
expect(spy).toHaveBeenCalledTimes(1);
}).then(() => {
return observable.fetchMore({updateQuery: (prev) => prev});
}).then(() => {
expect(spy).toHaveBeenCalledTimes(1);
}).finally(() => {
spy.mockRestore();
}).then(resolve, reject);
});
});

describe('fetchMore on an observable query', () => {
type TCommentData = {
entry: {
Expand Down
19 changes: 0 additions & 19 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export interface UpdateQueryOptions<TVariables> {
variables?: TVariables;
}

let warnedAboutUpdateQuery = false;

interface Last<TData, TVariables> {
result: ApolloQueryResult<TData>;
variables?: TVariables;
Expand Down Expand Up @@ -419,23 +417,6 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
update: cache => {
const { updateQuery } = fetchMoreOptions;
if (updateQuery) {
if (__DEV__ &&
!warnedAboutUpdateQuery) {
invariant.warn(
`The updateQuery callback for fetchMore is deprecated, and will be removed
in the next major version of Apollo Client.
Please convert updateQuery functions to field policies with appropriate
read and merge functions, or use/adapt a helper function (such as
concatPagination, offsetLimitPagination, or relayStylePagination) from
@apollo/client/utilities.
The field policy system handles pagination more effectively than a
hand-written updateQuery function, and you only need to define the policy
once, rather than every time you call fetchMore.`);
warnedAboutUpdateQuery = true;
}

cache.updateQuery({
query: this.options.query,
variables: this.variables,
Expand Down

0 comments on commit 1b3406a

Please sign in to comment.