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

Assume keyArgs:false only if *both* read and merge provided. #5862

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ describe("type policies", function () {
expect(result).toEqual(data);
});

it("assumes keyArgs:false when read or merge function present", function () {
it("assumes keyArgs:false when read and merge function present", function () {
const cache = new InMemoryCache({
typePolicies: {
TypeA: {
Expand Down Expand Up @@ -525,7 +525,7 @@ describe("type policies", function () {
expect(cache.extract()).toEqual({
ROOT_QUERY: {
__typename: "Query",
types: [
'types({"from":"A","to":"F"})': [
{
__typename: "TypeA",
},
Expand Down
9 changes: 6 additions & 3 deletions src/cache/inmemory/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,12 @@ export class Policies {
if (typeof merge === "function") existing.merge = merge;
}

if (existing.read || existing.merge) {
// If we have a read or merge function, assume keyArgs:false
// unless existing.keyFn has already been explicitly set.
if (existing.read && existing.merge) {
// If we have both a read and a merge function, assume
// keyArgs:false, because read and merge together can take
// responsibility for interpreting arguments in and out. This
// default assumption can always be overridden by specifying
// keyArgs explicitly in the FieldPolicy.
existing.keyFn = existing.keyFn || simpleKeyArgsFn;
}
});
Expand Down