···11+---
22+'@urql/exchange-graphcache': minor
33+---
44+55+Allow scalar values on the parent to be accessed from `parent[info.fieldName]` consistently. Prior to this change `parent[fieldAlias]` would get populated, which wouldn’t always result in a field that’s consistently accessible.
+5
.changeset/tame-ways-obey.md
···11+---
22+'@urql/exchange-graphcache': patch
33+---
44+55+Fix cases where `ResolveInfo`’s `parentFieldKey` was incorrectly populated with a key that isn’t a field key (allowing for `cache.resolve(info.parentKey, info.parentFieldKey)` to be possible) but was instead set to `info.parentKey` combined with the field key.
-6
exchanges/graphcache/src/helpers/dict.ts
···11-export const makeDict = (): any => Object.create(null);
22-33-export const isDictEmpty = (x: any) => {
44- for (const _ in x) return false;
55- return true;
66-};
+15-8
exchanges/graphcache/src/operations/query.ts
···421421 // The field is a scalar and can be retrieved directly from the result
422422 dataFieldValue = resultValue;
423423 } else if (InMemoryData.currentOperation === 'read' && resolver) {
424424+ // We have a resolver for this field.
425425+ // Prepare the actual fieldValue, so that the resolver can use it,
426426+ // as to avoid the user having to do `cache.resolve(parent, info.fieldKey)`
427427+ // only to get a scalar value.
428428+ let parent = output;
429429+ if (node.selectionSet === undefined && fieldValue !== undefined) {
430430+ parent = {
431431+ ...output,
432432+ [fieldAlias]: fieldValue,
433433+ [fieldName]: fieldValue,
434434+ };
435435+ }
436436+424437 // We have to update the information in context to reflect the info
425438 // that the resolver will receive
426426- updateContext(ctx, output, typename, entityKey, key, fieldName);
427427-428428- // We have a resolver for this field.
429429- // Prepare the actual fieldValue, so that the resolver can use it
430430- if (fieldValue !== undefined) {
431431- output[fieldAlias] = fieldValue;
432432- }
439439+ updateContext(ctx, parent, typename, entityKey, fieldKey, fieldName);
433440434441 dataFieldValue = resolver(
435435- output,
442442+ parent,
436443 fieldArgs || ({} as Variables),
437444 store,
438445 ctx