Skip to content

Commit

Permalink
Fix {query,mutation,subscription}Type:true type policies.
Browse files Browse the repository at this point in the history
Thanks to @zaguiini for tracking this regression (#7443) back to my
type/field policy inheritance PR (#7065).
  • Loading branch information
benjamn committed Dec 11, 2020
1 parent 2244dbd commit 4e66eaa
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/cache/inmemory/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,31 @@ export class Policies {

public addTypePolicies(typePolicies: TypePolicies) {
Object.keys(typePolicies).forEach(typename => {
const incoming = typePolicies[typename];
const {
queryType,
mutationType,
subscriptionType,
...incoming
} = typePolicies[typename];

// Though {query,mutation,subscription}Type configurations are rare,
// it's important to call setRootTypename as early as possible,
// since these configurations should apply consistently for the
// entire lifetime of the cache. Also, since only one __typename can
// qualify as one of these root types, these three properties cannot
// be inherited, unlike the rest of the incoming properties. That
// restriction is convenient, because the purpose of this.toBeAdded
// is to delay the processing of type/field policies until the first
// time they're used, allowing policies to be added in any order as
// long as all relevant policies (including policies for supertypes)
// have been added by the time a given policy is used for the first
// time. In other words, since inheritance doesn't matter for these
// properties, there's also no need to delay their processing using
// the this.toBeAdded queue.
if (queryType) this.setRootTypename("Query", typename);
if (mutationType) this.setRootTypename("Mutation", typename);
if (subscriptionType) this.setRootTypename("Subscription", typename);

if (hasOwn.call(this.toBeAdded, typename)) {
this.toBeAdded[typename].push(incoming);
} else {
Expand Down Expand Up @@ -390,10 +414,6 @@ export class Policies {
// using field policies to merge child objects.
setMerge(existing, incoming.merge);

if (incoming.queryType) this.setRootTypename("Query", typename);
if (incoming.mutationType) this.setRootTypename("Mutation", typename);
if (incoming.subscriptionType) this.setRootTypename("Subscription", typename);

existing.keyFn =
// Pass false to disable normalization for this typename.
keyFields === false ? nullKeyFieldsFn :
Expand Down

0 comments on commit 4e66eaa

Please sign in to comment.