Skip to content

Commit

Permalink
Failing regression test for issue #8639.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Aug 12, 2021
1 parent bd03ff0 commit a371406
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,60 @@ describe("type policies", function () {
checkAuthorName(cache);
});

it("can specify nested keyFields with alias", function () {
const cache = new InMemoryCache({
typePolicies: {
Book: {
keyFields: ["title", "author", ["name"]],
},
},
});

const aliasQuery = gql`
query {
book {
title
writer: author {
name
}
}
}
`;

const { author, ...rest } = theInformationBookData;
const aliasBookData = {
...rest,
writer: author,
};

cache.writeQuery({
query: aliasQuery,
data: {
book: aliasBookData,
},
});

expect(cache.extract(true)).toEqual({
ROOT_QUERY: {
__typename: "Query",
book: {
__ref: 'Book:{"title":"The Information","author":{"name":"James Gleick"}}',
},
},
'Book:{"title":"The Information","author":{"name":"James Gleick"}}': {
__typename: "Book",
title: "The Information",
// Note that "author" is stored internally, since it's the real name of
// the field, despite the "writer: author" alias.
author: {
name: "James Gleick"
},
},
});

checkAuthorName(cache);
});

it("keeps keyFields in specified order", function () {
const cache = new InMemoryCache({
typePolicies: {
Expand Down

0 comments on commit a371406

Please sign in to comment.