Skip to content

Commit

Permalink
use groupedFieldSet as variable name
Browse files Browse the repository at this point in the history
to match type
  • Loading branch information
yaacovCR authored and IvanGoncharov committed Apr 6, 2023
1 parent 45f2a59 commit a074400
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
28 changes: 14 additions & 14 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export type GroupedFieldSet = Map<string, FieldGroup>;

export interface PatchFields {
label: string | undefined;
fields: GroupedFieldSet;
groupedFieldSet: GroupedFieldSet;
}

export interface FieldsAndPatches {
fields: GroupedFieldSet;
groupedFieldSet: GroupedFieldSet;
patches: Array<PatchFields>;
}

Expand All @@ -56,7 +56,7 @@ export function collectFields(
runtimeType: GraphQLObjectType,
operation: OperationDefinitionNode,
): FieldsAndPatches {
const fields = new AccumulatorMap<string, FieldNode>();
const groupedFieldSet = new AccumulatorMap<string, FieldNode>();
const patches: Array<PatchFields> = [];
collectFieldsImpl(
schema,
Expand All @@ -65,11 +65,11 @@ export function collectFields(
operation,
runtimeType,
operation.selectionSet,
fields,
groupedFieldSet,
patches,
new Set(),
);
return { fields, patches };
return { groupedFieldSet, patches };
}

/**
Expand All @@ -91,12 +91,12 @@ export function collectSubfields(
returnType: GraphQLObjectType,
fieldGroup: FieldGroup,
): FieldsAndPatches {
const subFieldNodes = new AccumulatorMap<string, FieldNode>();
const subGroupedFieldSet = new AccumulatorMap<string, FieldNode>();
const visitedFragmentNames = new Set<string>();

const subPatches: Array<PatchFields> = [];
const subFieldsAndPatches = {
fields: subFieldNodes,
groupedFieldSet: subGroupedFieldSet,
patches: subPatches,
};

Expand All @@ -109,7 +109,7 @@ export function collectSubfields(
operation,
returnType,
node.selectionSet,
subFieldNodes,
subGroupedFieldSet,
subPatches,
visitedFragmentNames,
);
Expand All @@ -126,7 +126,7 @@ function collectFieldsImpl(
operation: OperationDefinitionNode,
runtimeType: GraphQLObjectType,
selectionSet: SelectionSetNode,
fields: AccumulatorMap<string, FieldNode>,
groupedFieldSet: AccumulatorMap<string, FieldNode>,
patches: Array<PatchFields>,
visitedFragmentNames: Set<string>,
): void {
Expand All @@ -136,7 +136,7 @@ function collectFieldsImpl(
if (!shouldIncludeNode(variableValues, selection)) {
continue;
}
fields.add(getFieldEntryKey(selection), selection);
groupedFieldSet.add(getFieldEntryKey(selection), selection);
break;
}
case Kind.INLINE_FRAGMENT: {
Expand Down Expand Up @@ -164,7 +164,7 @@ function collectFieldsImpl(
);
patches.push({
label: defer.label,
fields: patchFields,
groupedFieldSet: patchFields,
});
} else {
collectFieldsImpl(
Expand All @@ -174,7 +174,7 @@ function collectFieldsImpl(
operation,
runtimeType,
selection.selectionSet,
fields,
groupedFieldSet,
patches,
visitedFragmentNames,
);
Expand Down Expand Up @@ -220,7 +220,7 @@ function collectFieldsImpl(
);
patches.push({
label: defer.label,
fields: patchFields,
groupedFieldSet: patchFields,
});
} else {
collectFieldsImpl(
Expand All @@ -230,7 +230,7 @@ function collectFieldsImpl(
operation,
runtimeType,
fragment.selectionSet,
fields,
groupedFieldSet,
patches,
visitedFragmentNames,
);
Expand Down
41 changes: 25 additions & 16 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function executeOperation(
);
}

const { fields: rootFields, patches } = collectFields(
const { groupedFieldSet, patches } = collectFields(
schema,
fragments,
variableValues,
Expand All @@ -548,30 +548,42 @@ function executeOperation(

switch (operation.operation) {
case OperationTypeNode.QUERY:
result = executeFields(exeContext, rootType, rootValue, path, rootFields);
result = executeFields(
exeContext,
rootType,
rootValue,
path,
groupedFieldSet,
);
break;
case OperationTypeNode.MUTATION:
result = executeFieldsSerially(
exeContext,
rootType,
rootValue,
path,
rootFields,
groupedFieldSet,
);
break;
case OperationTypeNode.SUBSCRIPTION:
// TODO: deprecate `subscribe` and move all logic here
// Temporary solution until we finish merging execute and subscribe together
result = executeFields(exeContext, rootType, rootValue, path, rootFields);
result = executeFields(
exeContext,
rootType,
rootValue,
path,
groupedFieldSet,
);
}

for (const patch of patches) {
const { label, fields: patchFields } = patch;
const { label, groupedFieldSet: patchGroupedFieldSet } = patch;
executeDeferredFragment(
exeContext,
rootType,
rootValue,
patchFields,
patchGroupedFieldSet,
label,
path,
);
Expand Down Expand Up @@ -1447,28 +1459,25 @@ function collectAndExecuteSubfields(
asyncPayloadRecord?: AsyncPayloadRecord,
): PromiseOrValue<ObjMap<unknown>> {
// Collect sub-fields to execute to complete this value.
const { fields: subFieldNodes, patches: subPatches } = collectSubfields(
exeContext,
returnType,
fieldGroup,
);
const { groupedFieldSet: subGroupedFieldSet, patches: subPatches } =
collectSubfields(exeContext, returnType, fieldGroup);

const subFields = executeFields(
exeContext,
returnType,
result,
path,
subFieldNodes,
subGroupedFieldSet,
asyncPayloadRecord,
);

for (const subPatch of subPatches) {
const { label, fields: subPatchFieldNodes } = subPatch;
const { label, groupedFieldSet: subPatchGroupedFieldSet } = subPatch;
executeDeferredFragment(
exeContext,
returnType,
result,
subPatchFieldNodes,
subPatchGroupedFieldSet,
label,
path,
asyncPayloadRecord,
Expand Down Expand Up @@ -1691,15 +1700,15 @@ function executeSubscription(
);
}

const { fields: rootFields } = collectFields(
const { groupedFieldSet } = collectFields(
schema,
fragments,
variableValues,
rootType,
operation,
);

const firstRootField = rootFields.entries().next().value;
const firstRootField = groupedFieldSet.entries().next().value;
const [responseName, fieldGroup] = firstRootField;
const fieldName = fieldGroup[0].name.value;
const fieldDef = schema.getField(rootType, fieldName);
Expand Down
8 changes: 4 additions & 4 deletions src/validation/rules/SingleFieldSubscriptionsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export function SingleFieldSubscriptionsRule(
fragments[definition.name.value] = definition;
}
}
const { fields } = collectFields(
const { groupedFieldSet } = collectFields(
schema,
fragments,
variableValues,
subscriptionType,
node,
);
if (fields.size > 1) {
const fieldSelectionLists = [...fields.values()];
if (groupedFieldSet.size > 1) {
const fieldSelectionLists = [...groupedFieldSet.values()];
const extraFieldSelectionLists = fieldSelectionLists.slice(1);
const extraFieldSelections = extraFieldSelectionLists.flat();
context.reportError(
Expand All @@ -61,7 +61,7 @@ export function SingleFieldSubscriptionsRule(
),
);
}
for (const fieldGroup of fields.values()) {
for (const fieldGroup of groupedFieldSet.values()) {
const fieldName = fieldGroup[0].name.value;
if (fieldName.startsWith('__')) {
context.reportError(
Expand Down

0 comments on commit a074400

Please sign in to comment.