Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql

Package Overview
Dependencies
Maintainers
8
Versions
265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql - npm Package Compare versions

Comparing version 17.0.0-alpha.3.canary.pr.3969.83688beb16ecba5a0495158c3c2b3684730579bf to 17.0.0-alpha.3.canary.pr.4002.b3f6af2e83280d7830b2a01265e0977b7b68e2f4

execution/buildFieldPlan.d.ts

34

execution/collectFields.d.ts

@@ -11,26 +11,8 @@ import type { ObjMap } from '../jsutils/ObjMap.js';

label: string | undefined;
ancestors: ReadonlyArray<Target>;
parentDeferUsage: DeferUsage | undefined;
}
export declare const NON_DEFERRED_TARGET_SET: TargetSet;
export type Target = DeferUsage | undefined;
export type TargetSet = ReadonlySet<Target>;
export type DeferUsageSet = ReadonlySet<DeferUsage>;
export interface FieldDetails {
node: FieldNode;
target: Target;
deferUsage: DeferUsage | undefined;
}
export interface FieldGroup {
fields: ReadonlyArray<FieldDetails>;
targets: TargetSet;
}
export type GroupedFieldSet = Map<string, FieldGroup>;
export interface GroupedFieldSetDetails {
groupedFieldSet: GroupedFieldSet;
shouldInitiateDefer: boolean;
}
export interface CollectFieldsResult {
groupedFieldSet: GroupedFieldSet;
newGroupedFieldSetDetails: Map<DeferUsageSet, GroupedFieldSetDetails>;
newDeferUsages: ReadonlyArray<DeferUsage>;
}
/**

@@ -53,3 +35,6 @@ * Given a selectionSet, collects all of the fields and returns them.

operation: OperationDefinitionNode,
): CollectFieldsResult;
): {
fields: Map<string, ReadonlyArray<FieldDetails>>;
newDeferUsages: ReadonlyArray<DeferUsage>;
};
/**

@@ -73,3 +58,6 @@ * Given an array of field nodes, collects all of the subfields of the passed

returnType: GraphQLObjectType,
fieldGroup: FieldGroup,
): CollectFieldsResult;
fieldDetails: ReadonlyArray<FieldDetails>,
): {
fields: Map<string, ReadonlyArray<FieldDetails>>;
newDeferUsages: ReadonlyArray<DeferUsage>;
};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.collectSubfields =
exports.collectFields =
exports.NON_DEFERRED_TARGET_SET =
void 0;
exports.collectSubfields = exports.collectFields = void 0;
const AccumulatorMap_js_1 = require('../jsutils/AccumulatorMap.js');
const getBySet_js_1 = require('../jsutils/getBySet.js');
const invariant_js_1 = require('../jsutils/invariant.js');
const isSameSet_js_1 = require('../jsutils/isSameSet.js');
const ast_js_1 = require('../language/ast.js');

@@ -17,3 +12,2 @@ const kinds_js_1 = require('../language/kinds.js');

const values_js_1 = require('./values.js');
exports.NON_DEFERRED_TARGET_SET = new Set([undefined]);
/**

@@ -35,2 +29,4 @@ * Given a selectionSet, collects all of the fields and returns them.

) {
const groupedFieldSet = new AccumulatorMap_js_1.AccumulatorMap();
const newDeferUsages = [];
const context = {

@@ -42,12 +38,11 @@ schema,

operation,
fieldsByTarget: new Map(),
targetsByKey: new Map(),
newDeferUsages: [],
visitedFragmentNames: new Set(),
};
collectFieldsImpl(context, operation.selectionSet);
return {
...buildGroupedFieldSets(context.targetsByKey, context.fieldsByTarget),
newDeferUsages: context.newDeferUsages,
};
collectFieldsImpl(
context,
operation.selectionSet,
groupedFieldSet,
newDeferUsages,
);
return { fields: groupedFieldSet, newDeferUsages };
}

@@ -72,3 +67,3 @@ exports.collectFields = collectFields;

returnType,
fieldGroup,
fieldDetails,
) {

@@ -81,24 +76,31 @@ const context = {

operation,
fieldsByTarget: new Map(),
targetsByKey: new Map(),
newDeferUsages: [],
visitedFragmentNames: new Set(),
};
for (const fieldDetails of fieldGroup.fields) {
const node = fieldDetails.node;
const subGroupedFieldSet = new AccumulatorMap_js_1.AccumulatorMap();
const newDeferUsages = [];
for (const fieldDetail of fieldDetails) {
const node = fieldDetail.node;
if (node.selectionSet) {
collectFieldsImpl(context, node.selectionSet, fieldDetails.target);
collectFieldsImpl(
context,
node.selectionSet,
subGroupedFieldSet,
newDeferUsages,
fieldDetail.deferUsage,
);
}
}
return {
...buildGroupedFieldSets(
context.targetsByKey,
context.fieldsByTarget,
fieldGroup.targets,
),
newDeferUsages: context.newDeferUsages,
fields: subGroupedFieldSet,
newDeferUsages,
};
}
exports.collectSubfields = collectSubfields;
function collectFieldsImpl(context, selectionSet, parentTarget, newTarget) {
function collectFieldsImpl(
context,
selectionSet,
groupedFieldSet,
newDeferUsages,
deferUsage,
) {
const {

@@ -110,5 +112,2 @@ schema,

operation,
targetsByKey,
fieldsByTarget,
newDeferUsages,
visitedFragmentNames,

@@ -122,16 +121,6 @@ } = context;

}
const key = getFieldEntryKey(selection);
const target = newTarget ?? parentTarget;
let keyTargets = targetsByKey.get(key);
if (keyTargets === undefined) {
keyTargets = new Set();
targetsByKey.set(key, keyTargets);
}
keyTargets.add(target);
let targetFields = fieldsByTarget.get(target);
if (targetFields === undefined) {
targetFields = new AccumulatorMap_js_1.AccumulatorMap();
fieldsByTarget.set(target, targetFields);
}
targetFields.add(key, selection);
groupedFieldSet.add(getFieldEntryKey(selection), {
node: selection,
deferUsage,
});
break;

@@ -146,20 +135,26 @@ }

}
const defer = getDeferValues(operation, variableValues, selection);
let target;
if (!defer) {
target = newTarget;
const newDeferUsage = getDeferUsage(
operation,
variableValues,
selection,
deferUsage,
);
if (!newDeferUsage) {
collectFieldsImpl(
context,
selection.selectionSet,
groupedFieldSet,
newDeferUsages,
deferUsage,
);
} else {
const ancestors =
parentTarget === undefined
? [parentTarget]
: [parentTarget, ...parentTarget.ancestors];
target = { ...defer, ancestors };
newDeferUsages.push(target);
newDeferUsages.push(newDeferUsage);
collectFieldsImpl(
context,
selection.selectionSet,
groupedFieldSet,
newDeferUsages,
newDeferUsage,
);
}
collectFieldsImpl(
context,
selection.selectionSet,
parentTarget,
target,
);
break;

@@ -169,9 +164,15 @@ }

const fragName = selection.name.value;
if (!shouldIncludeNode(variableValues, selection)) {
const newDeferUsage = getDeferUsage(
operation,
variableValues,
selection,
deferUsage,
);
if (
!newDeferUsage &&
(visitedFragmentNames.has(fragName) ||
!shouldIncludeNode(variableValues, selection))
) {
continue;
}
const defer = getDeferValues(operation, variableValues, selection);
if (visitedFragmentNames.has(fragName) && !defer) {
continue;
}
const fragment = fragments[fragName];

@@ -184,15 +185,21 @@ if (

}
let target;
if (!defer) {
if (!newDeferUsage) {
visitedFragmentNames.add(fragName);
target = newTarget;
collectFieldsImpl(
context,
fragment.selectionSet,
groupedFieldSet,
newDeferUsages,
deferUsage,
);
} else {
const ancestors =
parentTarget === undefined
? [parentTarget]
: [parentTarget, ...parentTarget.ancestors];
target = { ...defer, ancestors };
newDeferUsages.push(target);
newDeferUsages.push(newDeferUsage);
collectFieldsImpl(
context,
fragment.selectionSet,
groupedFieldSet,
newDeferUsages,
newDeferUsage,
);
}
collectFieldsImpl(context, fragment.selectionSet, parentTarget, target);
break;

@@ -208,3 +215,3 @@ }

*/
function getDeferValues(operation, variableValues, node) {
function getDeferUsage(operation, variableValues, node, parentDeferUsage) {
const defer = (0, values_js_1.getDirectiveValues)(

@@ -228,2 +235,3 @@ directives_js_1.GraphQLDeferDirective,

label: typeof defer.label === 'string' ? defer.label : undefined,
parentDeferUsage,
};

@@ -280,109 +288,1 @@ }

}
function buildGroupedFieldSets(
targetsByKey,
fieldsByTarget,
parentTargets = exports.NON_DEFERRED_TARGET_SET,
) {
const { parentTargetKeys, targetSetDetailsMap } = getTargetSetDetails(
targetsByKey,
parentTargets,
);
const groupedFieldSet =
parentTargetKeys.size > 0
? getOrderedGroupedFieldSet(
parentTargetKeys,
parentTargets,
targetsByKey,
fieldsByTarget,
)
: new Map();
const newGroupedFieldSetDetails = new Map();
for (const [maskingTargets, targetSetDetails] of targetSetDetailsMap) {
const { keys, shouldInitiateDefer } = targetSetDetails;
const newGroupedFieldSet = getOrderedGroupedFieldSet(
keys,
maskingTargets,
targetsByKey,
fieldsByTarget,
);
// All TargetSets that causes new grouped field sets consist only of DeferUsages
// and have shouldInitiateDefer defined
newGroupedFieldSetDetails.set(maskingTargets, {
groupedFieldSet: newGroupedFieldSet,
shouldInitiateDefer,
});
}
return {
groupedFieldSet,
newGroupedFieldSetDetails,
};
}
function getTargetSetDetails(targetsByKey, parentTargets) {
const parentTargetKeys = new Set();
const targetSetDetailsMap = new Map();
for (const [responseKey, targets] of targetsByKey) {
const maskingTargetList = [];
for (const target of targets) {
if (
target === undefined ||
target.ancestors.every((ancestor) => !targets.has(ancestor))
) {
maskingTargetList.push(target);
}
}
const maskingTargets = new Set(maskingTargetList);
if ((0, isSameSet_js_1.isSameSet)(maskingTargets, parentTargets)) {
parentTargetKeys.add(responseKey);
continue;
}
let targetSetDetails = (0, getBySet_js_1.getBySet)(
targetSetDetailsMap,
maskingTargets,
);
if (targetSetDetails === undefined) {
targetSetDetails = {
keys: new Set(),
shouldInitiateDefer: maskingTargetList.some(
(deferUsage) => !parentTargets.has(deferUsage),
),
};
targetSetDetailsMap.set(maskingTargets, targetSetDetails);
}
targetSetDetails.keys.add(responseKey);
}
return {
parentTargetKeys,
targetSetDetailsMap,
};
}
function getOrderedGroupedFieldSet(
keys,
maskingTargets,
targetsByKey,
fieldsByTarget,
) {
const groupedFieldSet = new Map();
const firstTarget = maskingTargets.values().next().value;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const firstFields = fieldsByTarget.get(firstTarget);
for (const [key] of firstFields) {
if (keys.has(key)) {
let fieldGroup = groupedFieldSet.get(key);
if (fieldGroup === undefined) {
fieldGroup = { fields: [], targets: maskingTargets };
groupedFieldSet.set(key, fieldGroup);
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const target of targetsByKey.get(key)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const fieldsForTarget = fieldsByTarget.get(target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const nodes = fieldsForTarget.get(key);
// the following line is an optional minor optimization
fieldsForTarget.delete(key);
fieldGroup.fields.push(...nodes.map((node) => ({ node, target })));
}
}
}
return groupedFieldSet;
}

@@ -8,2 +8,3 @@ import type { Maybe } from '../jsutils/Maybe.js';

DocumentNode,
FieldNode,
FragmentDefinitionNode,

@@ -20,3 +21,3 @@ OperationDefinitionNode,

import type { GraphQLSchema } from '../type/schema.js';
import type { FieldGroup } from './collectFields.js';
import type { FieldGroup } from './buildFieldPlan.js';
import type {

@@ -143,3 +144,3 @@ ExecutionResult,

fieldDef: GraphQLField<unknown, unknown>,
fieldGroup: FieldGroup,
fieldNodes: ReadonlyArray<FieldNode>,
parentType: GraphQLObjectType,

@@ -146,0 +147,0 @@ path: Path,

@@ -30,2 +30,3 @@ 'use strict';

const validate_js_1 = require('../type/validate.js');
const buildFieldPlan_js_1 = require('./buildFieldPlan.js');
const collectFields_js_1 = require('./collectFields.js');

@@ -39,9 +40,10 @@ const IncrementalPublisher_js_1 = require('./IncrementalPublisher.js');

/**
* A memoized collection of relevant subfields with regard to the return
* type. Memoizing ensures the subfields are not repeatedly calculated, which
* A memoized function for building subfield plans with regard to the return
* type. Memoizing ensures the subfield plans are not repeatedly calculated, which
* saves overhead when resolving lists of values.
*/
const collectSubfields = (0, memoize3_js_1.memoize3)(
(exeContext, returnType, fieldGroup) =>
(0, collectFields_js_1.collectSubfields)(
const buildSubFieldPlan = (0, memoize3_js_1.memoize3)(
(exeContext, returnType, fieldGroup) => {
const { fields: subFields, newDeferUsages } = (0,
collectFields_js_1.collectSubfields)(
exeContext.schema,

@@ -52,4 +54,12 @@ exeContext.fragments,

returnType,
fieldGroup,
),
fieldGroup.fields,
);
return {
...(0, buildFieldPlan_js_1.buildFieldPlan)(
subFields,
fieldGroup.deferUsages,
),
newDeferUsages,
};
},
);

@@ -276,4 +286,3 @@ const UNEXPECTED_EXPERIMENTAL_DIRECTIVES =

}
const { groupedFieldSet, newGroupedFieldSetDetails, newDeferUsages } = (0,
collectFields_js_1.collectFields)(
const { fields, newDeferUsages } = (0, collectFields_js_1.collectFields)(
schema,

@@ -285,2 +294,4 @@ fragments,

);
const { groupedFieldSet, newGroupedFieldSetDetailsMap } = (0,
buildFieldPlan_js_1.buildFieldPlan)(fields);
const newDeferMap = addNewDeferredFragments(

@@ -294,3 +305,3 @@ incrementalPublisher,

incrementalPublisher,
newGroupedFieldSetDetails,
newGroupedFieldSetDetailsMap,
newDeferMap,

@@ -477,3 +488,3 @@ path,

fieldDef,
fieldGroup,
toNodes(fieldGroup),
parentType,

@@ -553,3 +564,3 @@ path,

*/
function buildResolveInfo(exeContext, fieldDef, fieldGroup, parentType, path) {
function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
// The resolve function's optional fourth argument is a collection of

@@ -559,3 +570,3 @@ // information about the current execution state.

fieldName: fieldDef.name,
fieldNodes: toNodes(fieldGroup),
fieldNodes,
returnType: fieldDef.type,

@@ -789,5 +800,4 @@ parentType,

node: fieldDetails.node,
target: undefined,
deferUsage: undefined,
})),
targets: collectFields_js_1.NON_DEFERRED_TARGET_SET,
};

@@ -1256,13 +1266,10 @@ const streamUsage = {

for (const newDeferUsage of newDeferUsages) {
// DeferUsage objects track their parent targets; the immediate parent is always the first member of this list.
const parentTarget = newDeferUsage.ancestors[0];
// If the parent target is defined, the parent target is a DeferUsage object and
// the parent result record is the DeferredFragmentRecord corresponding to that DeferUsage.
// If the parent target is not defined, the parent result record is either:
const parentDeferUsage = newDeferUsage.parentDeferUsage;
// If the parent defer usage is not defined, the parent result record is either:
// - the InitialResultRecord, or
// - a StreamItemsRecord, as `@defer` may be nested under `@stream`.
const parent =
parentTarget === undefined
parentDeferUsage === undefined
? incrementalDataRecord
: deferredFragmentRecordFromDeferUsage(parentTarget, newDeferMap);
: deferredFragmentRecordFromDeferUsage(parentDeferUsage, newDeferMap);
// Instantiate the new record.

@@ -1290,3 +1297,3 @@ const deferredFragmentRecord =

incrementalPublisher,
newGroupedFieldSetDetails,
newGroupedFieldSetDetailsMap,
deferMap,

@@ -1297,7 +1304,7 @@ path,

for (const [
newGroupedFieldSetDeferUsages,
deferUsageSet,
{ groupedFieldSet, shouldInitiateDefer },
] of newGroupedFieldSetDetails) {
] of newGroupedFieldSetDetailsMap) {
const deferredFragmentRecords = getDeferredFragmentRecords(
newGroupedFieldSetDeferUsages,
deferUsageSet,
deferMap,

@@ -1334,4 +1341,4 @@ );

// Collect sub-fields to execute to complete this value.
const { groupedFieldSet, newGroupedFieldSetDetails, newDeferUsages } =
collectSubfields(exeContext, returnType, fieldGroup);
const { groupedFieldSet, newGroupedFieldSetDetailsMap, newDeferUsages } =
buildSubFieldPlan(exeContext, returnType, fieldGroup);
const incrementalPublisher = exeContext.incrementalPublisher;

@@ -1347,3 +1354,3 @@ const newDeferMap = addNewDeferredFragments(

incrementalPublisher,
newGroupedFieldSetDetails,
newGroupedFieldSetDetailsMap,
newDeferMap,

@@ -1553,3 +1560,3 @@ path,

}
const { groupedFieldSet } = (0, collectFields_js_1.collectFields)(
const { fields } = (0, collectFields_js_1.collectFields)(
schema,

@@ -1561,10 +1568,11 @@ fragments,

);
const firstRootField = groupedFieldSet.entries().next().value;
const [responseName, fieldGroup] = firstRootField;
const fieldName = fieldGroup.fields[0].node.name.value;
const firstRootField = fields.entries().next().value;
const [responseName, fieldDetailsList] = firstRootField;
const fieldName = fieldDetailsList[0].node.name.value;
const fieldDef = schema.getField(rootType, fieldName);
const fieldNodes = fieldDetailsList.map((fieldDetails) => fieldDetails.node);
if (!fieldDef) {
throw new GraphQLError_js_1.GraphQLError(
`The subscription field "${fieldName}" is not defined.`,
{ nodes: toNodes(fieldGroup) },
{ nodes: fieldNodes },
);

@@ -1576,3 +1584,3 @@ }

fieldDef,
fieldGroup,
fieldNodes,
rootType,

@@ -1588,3 +1596,3 @@ path,

fieldDef,
fieldGroup.fields[0].node,
fieldNodes[0],
variableValues,

@@ -1604,3 +1612,3 @@ );

error,
toNodes(fieldGroup),
fieldNodes,
(0, Path_js_1.pathToArray)(path),

@@ -1614,3 +1622,3 @@ );

error,
toNodes(fieldGroup),
fieldNodes,
(0, Path_js_1.pathToArray)(path),

@@ -1617,0 +1625,0 @@ );

@@ -7,3 +7,3 @@ import type { ObjMap } from '../jsutils/ObjMap.js';

} from '../error/GraphQLError.js';
import type { GroupedFieldSet } from './collectFields.js';
import type { GroupedFieldSet } from './buildFieldPlan.js';
interface IncrementalUpdate<TData = unknown, TExtensions = ObjMap<unknown>> {

@@ -10,0 +10,0 @@ pending: ReadonlyArray<PendingResult>;

@@ -351,18 +351,16 @@ 'use strict';

const { data, deferredFragmentRecords } = deferredGroupedFieldSetRecord;
let maxLength = deferredFragmentRecords[0].path.length;
let maxIndex = 0;
for (let i = 1; i < deferredFragmentRecords.length; i++) {
const deferredFragmentRecord = deferredFragmentRecords[i];
let maxLength;
let idWithLongestPath;
for (const deferredFragmentRecord of deferredFragmentRecords) {
const id = deferredFragmentRecord.id;
if (id === undefined) {
continue;
}
const length = deferredFragmentRecord.path.length;
if (length > maxLength) {
if (maxLength === undefined || length > maxLength) {
maxLength = length;
maxIndex = i;
idWithLongestPath = id;
}
}
const recordWithLongestPath = deferredFragmentRecords[maxIndex];
const longestPath = recordWithLongestPath.path;
const subPath = deferredGroupedFieldSetRecord.path.slice(
longestPath.length,
);
const id = recordWithLongestPath.id;
const subPath = deferredGroupedFieldSetRecord.path.slice(maxLength);
const incrementalDeferResult = {

@@ -372,5 +370,7 @@ // safe because `data``is always defined when the record is completed

data: data,
// safe because `id` is defined once the fragment has been released as pending
// safe because `id` is always defined once the fragment has been released
// as pending and at least one fragment has been completed, so must have been
// released as pending
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: id,
id: idWithLongestPath,
};

@@ -402,6 +402,9 @@ if (subPath.length > 0) {

}
if (subsequentResultRecord._pending.size === 0) {
if (subsequentResultRecord._pending.size > 0) {
this._introduce(subsequentResultRecord);
} else if (
subsequentResultRecord.deferredGroupedFieldSetRecords.size > 0 ||
subsequentResultRecord.children.size > 0
) {
this._push(subsequentResultRecord);
} else {
this._introduce(subsequentResultRecord);
}

@@ -408,0 +411,0 @@ }

{
"name": "graphql",
"version": "17.0.0-alpha.3.canary.pr.3969.83688beb16ecba5a0495158c3c2b3684730579bf",
"version": "17.0.0-alpha.3.canary.pr.4002.b3f6af2e83280d7830b2a01265e0977b7b68e2f4",
"description": "A Query Language and Runtime which can target any service.",

@@ -35,7 +35,7 @@ "license": "MIT",

"publishConfig": {
"tag": "canary-pr-3969"
"tag": "canary-pr-4002"
},
"main": "index",
"module": "index.mjs",
"deprecated": "You are using canary version build from https://github.com/graphql/graphql-js/pull/3969, no gurantees provided so please use your own discretion."
"deprecated": "You are using canary version build from https://github.com/graphql/graphql-js/pull/4002, no gurantees provided so please use your own discretion."
}

@@ -7,4 +7,4 @@ 'use strict';

const collectFields_js_1 = require('../../execution/collectFields.js');
function toNodes(fieldGroup) {
return fieldGroup.fields.map((fieldDetails) => fieldDetails.node);
function toNodes(fieldDetailsList) {
return fieldDetailsList.map((fieldDetails) => fieldDetails.node);
}

@@ -35,3 +35,3 @@ /**

}
const { groupedFieldSet } = (0, collectFields_js_1.collectFields)(
const { fields } = (0, collectFields_js_1.collectFields)(
schema,

@@ -43,4 +43,4 @@ fragments,

);
if (groupedFieldSet.size > 1) {
const fieldGroups = [...groupedFieldSet.values()];
if (fields.size > 1) {
const fieldGroups = [...fields.values()];
const extraFieldGroups = fieldGroups.slice(1);

@@ -59,3 +59,3 @@ const extraFieldSelections = extraFieldGroups.flatMap(

}
for (const fieldGroup of groupedFieldSet.values()) {
for (const fieldGroup of fields.values()) {
const fieldName = toNodes(fieldGroup)[0].name.value;

@@ -62,0 +62,0 @@ if (fieldName.startsWith('__')) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc