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

Add parentType to path to avoid path ambiguity #2669

Merged
merged 7 commits into from Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/execution/__tests__/executor-test.js
Expand Up @@ -306,7 +306,7 @@ describe('Execute: Handles basic execution tasks', () => {
const field = operation.selectionSet.selections[0];
expect(resolvedInfo).to.deep.include({
fieldNodes: [field],
path: { prev: undefined, key: 'result' },
path: { prev: undefined, key: 'result', parentType: 'Test' },
variableValues: { var: 'abc' },
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/execution/execute.js
Expand Up @@ -400,7 +400,7 @@ function executeFieldsSerially(
Object.keys(fields),
(results, responseName) => {
const fieldNodes = fields[responseName];
const fieldPath = addPath(path, responseName);
const fieldPath = addPath(path, responseName, parentType.name);
const result = resolveField(
exeContext,
parentType,
Expand Down Expand Up @@ -440,7 +440,7 @@ function executeFields(

for (const responseName of Object.keys(fields)) {
const fieldNodes = fields[responseName];
const fieldPath = addPath(path, responseName);
const fieldPath = addPath(path, responseName, parentType.name);
const result = resolveField(
exeContext,
parentType,
Expand Down Expand Up @@ -918,7 +918,7 @@ function completeListValue(
const completedResults = arrayFrom(result, (item, index) => {
// No need to modify the info object containing the path,
// since from here on it is not ever accessed by resolver functions.
const fieldPath = addPath(path, index);
const fieldPath = addPath(path, index, undefined);
const completedItem = completeValueCatchingError(
exeContext,
itemType,
Expand Down
7 changes: 6 additions & 1 deletion src/jsutils/Path.d.ts
@@ -1,12 +1,17 @@
export interface Path {
prev: Path | undefined;
key: string | number;
parentType: string | undefined;
benjie marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Given a Path and a key, return a new Path containing the new key.
*/
export function addPath(prev: Path | undefined, key: string | number): Path;
export function addPath(
prev: Path | undefined,
key: string | number,
parentType: string | undefined,
): Path;

/**
* Given a Path, return an Array of the path keys.
Expand Down
4 changes: 3 additions & 1 deletion src/jsutils/Path.js
Expand Up @@ -3,6 +3,7 @@
export type Path = {|
+prev: Path | void,
+key: string | number,
+parentType: string | void,
|};

/**
Expand All @@ -11,8 +12,9 @@ export type Path = {|
export function addPath(
prev: $ReadOnly<Path> | void,
key: string | number,
parentType: string | void,
): Path {
return { prev, key };
return { prev, key, parentType };
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/subscribe.js
Expand Up @@ -253,7 +253,7 @@ export function createSourceEventStream(
// AsyncIterable yielding raw payloads.
const resolveFn = fieldDef.subscribe ?? exeContext.fieldResolver;

const path = addPath(undefined, responseName);
const path = addPath(undefined, responseName, type.name);

const info = buildResolveInfo(exeContext, fieldDef, fieldNodes, type, path);

Expand Down
4 changes: 2 additions & 2 deletions src/utilities/coerceInputValue.js
Expand Up @@ -82,7 +82,7 @@ function coerceInputValueImpl(
const itemType = type.ofType;
if (isCollection(inputValue)) {
return arrayFrom(inputValue, (itemValue, index) => {
const itemPath = addPath(path, index);
const itemPath = addPath(path, index, undefined);
return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
});
}
Expand Down Expand Up @@ -126,7 +126,7 @@ function coerceInputValueImpl(
fieldValue,
field.type,
onError,
addPath(path, field.name),
addPath(path, field.name, undefined),
benjie marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down