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

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jan 25, 2020

Follow-up to #5680.

Assuming keyArgs:false just because a merge function (or a read function) was defined means that the following pattern can actually change cache behavior in surprising ways:

const cache = new InMemoryCache({
  typePolicies: {
    Person: {
      fields: {
        friends: {
          // This is supposed to be identical to what the cache does by
          // default, except without warnings about data loss, but it
          // subtly alters the default argument-based field identity
          // behavior when arguments are provided to the friends field.
          merge(_, incoming) {
            return incoming;
          },
        },
      },
    },
  },
});

Although this merge function mirrors how the cache behaves without a merge function, it has the benefit of making that behavior explicit, thereby silencing the warnings introduced by #5833. In order to recommend this strategy for silencing warnings when a last-write-wins merge strategy is desired, it seems unacceptable for this pattern to have any unexpected consequences beyond silencing the warnings.

Thinking about this default keyArgs:false behavior more, disabling field identity with keyArgs:false doesn't really make sense if you have only a merge function, or only a read function, since any fancy argument handling done by one of those functions cannot be balanced in the other direction.

@benjamn benjamn added this to the Release 3.0 milestone Jan 25, 2020
@benjamn benjamn self-assigned this Jan 25, 2020
Follow-up to #5680.

Assuming keyArgs:false just because a merge function (or a read function)
was defined means that the following pattern can actually change cache
behavior in surprising ways:

  const cache = new InMemoryCache({
    typePolicies: {
      Person: {
        fields: {
          friends: {
            // This is supposed to be identical to what the cache does by
            // default, except without warnings about data loss, but it
            // subtly alters the default argument-based field identity
            // behavior when arguments are provided to the friends field.
            merge(_, incoming) {
              return incoming;
            },
          },
        },
      },
    },
  });

Although this merge function mirrors how the cache behaves without a merge
function, it has the benefit of making that behavior explicit, thereby
silencing the warnings introduced by #5833. In order to recommend this
strategy for silencing warnings when a last-write-wins merge strategy is
desired, it seems unacceptable for this pattern to have any unexpected
consequences beyond silencing the warnings.

Thinking about this default keyArgs:false behavior more, disabling field
identity with keyArgs:false doesn't really make sense if you have only a
merge function, or only a read function, since any fancy argument handling
done by one of those functions cannot be balanced in the other direction.
@benjamn benjamn force-pushed the assume-keyArgs-false-only-when-both-read-and-merge-defined branch from d08e2b0 to 42dafcf Compare January 25, 2020 19:34
@benjamn benjamn requested a review from hwillson January 28, 2020 15:40
@benjamn benjamn merged commit 8a86adc into master Jan 28, 2020
@benjamn benjamn deleted the assume-keyArgs-false-only-when-both-read-and-merge-defined branch January 28, 2020 15:40
@stackia
Copy link

stackia commented Jul 28, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants