Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide failing test for cache-redirect-id-array case #9902

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/__tests__/cache-redirect-id-array-case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import gql from "graphql-tag";
import { ApolloClient, ApolloLink } from "../core";
import { InMemoryCache } from "../cache";
import { itAsync } from "../testing";

const query = gql`
query GetProductsByIds($ids: [String]!) {
getProductsByIds(ids: $ids) {
id
name
}
}
`;

const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
getProductsByIds: {
read(_, { args, toReference }) {
// ℹ️ uncommenting the following line will make it work
// return false;

return args?.ids.map((id: string) => toReference(`Product:${id}`));
},
},
},
},
},
});

itAsync(
"does network request when ids are not found in cache",
(resolve, reject) =>
new ApolloClient({
link: ApolloLink.from([
(operation, forward) => {
// indicates, that an outgoing query attempted is being done
expect(operation.operationName).toBe("GetProductsByIds");
expect(operation.variables).toEqual({ ids: ["1", "2", "3"] });

resolve();

return forward(operation);
},
]),
cache,
})
.watchQuery({
query,
fetchPolicy: "cache-first",
variables: {
ids: ["1", "2", "3"],
},
})
.subscribe({ error: reject })
);