Skip to content

Commit

Permalink
demonstrate issue with read query, evict, write query
Browse files Browse the repository at this point in the history
  • Loading branch information
danReynolds committed May 22, 2020
1 parent 3d48f9f commit d2a09a7
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/cache/inmemory/__tests__/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,83 @@ describe('EntityStore', () => {
});
});

it("allows clearing of evicted entities from cached queries", () => {
const query: DocumentNode = gql`
query {
authors {
name
hobby
}
}
`;

const cache = new InMemoryCache();

const TedChiangData = {
__typename: "Author",
name: "Ted Chiang",
hobby: "video games",
id: 1,
};

const IsaacAsimovData = {
__typename: "Author",
name: "Isaac Asimov",
hobby: "chemistry",
id: 2,
};

cache.writeQuery({
query,
data: {
authors: [TedChiangData, IsaacAsimovData],
},
});

expect(cache.extract()).toEqual({
"Author:1": {
__typename: "Author",
name: "Ted Chiang",
hobby: "video games",
id: 1,
},
"Author:2": {
__typename: "Author",
name: "Isaac Asimov",
hobby: "chemistry",
id: 2,
},
ROOT_QUERY: {
__typename: "Query",
authors: [{ __ref: "Author:1" }, { __ref: "Author:2" }],
},
});

cache.evict("Author:1");
const remainingAuthorsQuery: any = cache.readQuery({
query,
});
cache.writeQuery({
query,
data: {
authors: remainingAuthorsQuery?.authors,
},
});

expect(cache.extract()).toEqual({
"Author:2": {
__typename: "Author",
name: "Isaac Asimov",
hobby: "chemistry",
id: 2,
},
ROOT_QUERY: {
__typename: "Query",
authors: [{ __ref: "Author:2" }],
},
});
});

it("allows evicting specific fields with specific arguments using EvictOptions", () => {
const query: DocumentNode = gql`
query {
Expand Down

0 comments on commit d2a09a7

Please sign in to comment.