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

graphql

Package Overview
Dependencies
Maintainers
9
Versions
270
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 16.9.0-canary.pr.4159.0fa29326c53fcd63c6473c7357c28aa13fa0019d to 16.9.0-canary.pr.4192.1813397076f44a55e5798478e7321db9877de97a

10

execution/collectFields.d.ts

@@ -9,6 +9,2 @@ import type { ObjMap } from '../jsutils/ObjMap';

import type { GraphQLSchema } from '../type/schema';
export interface FieldDetails {
node: FieldNode;
fragmentVariableValues?: ObjMap<unknown> | undefined;
}
/**

@@ -31,3 +27,3 @@ * Given a selectionSet, collects all of the fields and returns them.

selectionSet: SelectionSetNode,
): Map<string, ReadonlyArray<FieldDetails>>;
): Map<string, ReadonlyArray<FieldNode>>;
/**

@@ -50,3 +46,3 @@ * Given an array of field nodes, collects all of the subfields of the passed

returnType: GraphQLObjectType,
fieldEntries: ReadonlyArray<FieldDetails>,
): Map<string, ReadonlyArray<FieldDetails>>;
fieldNodes: ReadonlyArray<FieldNode>,
): Map<string, ReadonlyArray<FieldNode>>;

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

new Set(),
undefined,
);

@@ -65,9 +64,9 @@ return fields;

returnType,
fieldEntries,
fieldNodes,
) {
const subFieldEntries = new Map();
const subFieldNodes = new Map();
const visitedFragmentNames = new Set();
for (const entry of fieldEntries) {
if (entry.node.selectionSet) {
for (const node of fieldNodes) {
if (node.selectionSet) {
collectFieldsImpl(

@@ -78,4 +77,4 @@ schema,

returnType,
entry.node.selectionSet,
subFieldEntries,
node.selectionSet,
subFieldNodes,
visitedFragmentNames,

@@ -86,3 +85,3 @@ );

return subFieldEntries;
return subFieldNodes;
}

@@ -98,3 +97,2 @@

visitedFragmentNames,
localVariableValues,
) {

@@ -104,8 +102,3 @@ for (const selection of selectionSet.selections) {

case _kinds.Kind.FIELD: {
const vars =
localVariableValues !== null && localVariableValues !== void 0
? localVariableValues
: variableValues;
if (!shouldIncludeNode(vars, selection)) {
if (!shouldIncludeNode(variableValues, selection)) {
continue;

@@ -118,19 +111,5 @@ }

if (fieldList !== undefined) {
fieldList.push({
node: selection,
fragmentVariableValues:
localVariableValues !== null && localVariableValues !== void 0
? localVariableValues
: undefined,
});
fieldList.push(selection);
} else {
fields.set(name, [
{
node: selection,
fragmentVariableValues:
localVariableValues !== null && localVariableValues !== void 0
? localVariableValues
: undefined,
},
]);
fields.set(name, [selection]);
}

@@ -179,21 +158,4 @@

continue;
} // We need to introduce a concept of shadowing:
//
// - when a fragment defines a variable that is in the parent scope but not given
// in the fragment-spread we need to look at this variable as undefined and check
// whether the definition has a defaultValue, if not remove it from the variableValues.
// - when a fragment does not define a variable we need to copy it over from the parent
// scope as that variable can still get used in spreads later on in the selectionSet.
// - when a value is passed in through the fragment-spread we need to copy over the key-value
// into our variable-values.
}
const fragmentVariableValues = fragment.variableDefinitions
? (0, _values.getArgumentValuesFromSpread)(
selection,
schema,
fragment.variableDefinitions,
variableValues,
localVariableValues,
)
: undefined;
collectFieldsImpl(

@@ -207,3 +169,2 @@ schema,

visitedFragmentNames,
fragmentVariableValues,
);

@@ -210,0 +171,0 @@ break;

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

DocumentNode,
FieldNode,
FragmentDefinitionNode,

@@ -21,3 +22,2 @@ OperationDefinitionNode,

import type { GraphQLSchema } from '../type/schema';
import type { FieldDetails } from './collectFields';
/**

@@ -61,2 +61,3 @@ * Terminology

errors: Array<GraphQLError>;
errorPropagation: boolean;
}

@@ -98,2 +99,8 @@ /**

subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
/**
* Set to `false` to disable error propagation. Experimental.
*
* @experimental
*/
errorPropagation?: boolean;
}

@@ -149,3 +156,3 @@ /**

fieldDef: GraphQLField<unknown, unknown>,
fieldEntries: ReadonlyArray<FieldDetails>,
fieldNodes: ReadonlyArray<FieldNode>,
parentType: GraphQLObjectType,

@@ -189,3 +196,3 @@ path: Path,

parentType: GraphQLObjectType,
entry: FieldDetails,
fieldNode: FieldNode,
): Maybe<GraphQLField<unknown, unknown>>;

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

subscribeFieldResolver,
errorPropagation,
} = args;

@@ -316,2 +317,6 @@ let operation;

errors: [],
errorPropagation:
errorPropagation !== null && errorPropagation !== void 0
? errorPropagation
: true,
};

@@ -458,6 +463,6 @@ }

function executeField(exeContext, parentType, source, fieldEntries, path) {
function executeField(exeContext, parentType, source, fieldNodes, path) {
var _fieldDef$resolve;
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldEntries[0]);
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);

@@ -477,3 +482,3 @@ if (!fieldDef) {

fieldDef,
fieldEntries,
fieldNodes,
parentType,

@@ -488,6 +493,5 @@ path,

const args = (0, _values.getArgumentValues)(
fieldEntries[0].node,
fieldDef.args,
fieldDef,
fieldNodes[0],
exeContext.variableValues,
fieldEntries[0].fragmentVariableValues,
); // The resolve function's optional third argument is a context value that

@@ -503,10 +507,3 @@ // is provided to every resolve function within an execution. It is commonly

completed = result.then((resolved) =>
completeValue(
exeContext,
returnType,
fieldEntries,
info,
path,
resolved,
),
completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
);

@@ -517,3 +514,3 @@ } else {

returnType,
fieldEntries,
fieldNodes,
info,

@@ -531,3 +528,3 @@ path,

rawError,
fieldEntries.map((entry) => entry.node),
fieldNodes,
(0, _Path.pathToArray)(path),

@@ -543,3 +540,3 @@ );

rawError,
fieldEntries.map((entry) => entry.node),
fieldNodes,
(0, _Path.pathToArray)(path),

@@ -554,9 +551,3 @@ );

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

@@ -566,3 +557,3 @@ // information about the current execution state.

fieldName: fieldDef.name,
fieldNodes: fieldEntries.map((entry) => entry.node),
fieldNodes,
returnType: fieldDef.type,

@@ -576,2 +567,3 @@ parentType,

variableValues: exeContext.variableValues,
errorPropagation: exeContext.errorPropagation,
};

@@ -583,3 +575,6 @@ }

// protection from errors, however it still properly locates the error.
if ((0, _definition.isNonNullType)(returnType)) {
if (
exeContext.errorPropagation &&
(0, _definition.isNonNullType)(returnType)
) {
throw error;

@@ -638,2 +633,22 @@ } // Otherwise, error protection is applied, logging the error and resolving

return completed;
} // If field type is SemanticNonNull, complete for inner type, and throw field error
// if result is null.
if ((0, _definition.isSemanticNonNullType)(returnType)) {
const completed = completeValue(
exeContext,
returnType.ofType,
fieldNodes,
info,
path,
result,
);
if (completed === null) {
throw new Error(
`Cannot return null for semantic-non-nullable field ${info.parentType.name}.${info.fieldName}.`,
);
}
return completed;
} // If result value is null or undefined then return null.

@@ -701,3 +716,3 @@

returnType,
fieldEntries,
fieldNodes,
info,

@@ -729,3 +744,3 @@ path,

itemType,
fieldEntries,
fieldNodes,
info,

@@ -740,3 +755,3 @@ itemPath,

itemType,
fieldEntries,
fieldNodes,
info,

@@ -755,3 +770,3 @@ itemPath,

rawError,
fieldEntries.map((entry) => entry.node),
fieldNodes,
(0, _Path.pathToArray)(itemPath),

@@ -767,3 +782,3 @@ );

rawError,
fieldEntries.map((entry) => entry.node),
fieldNodes,
(0, _Path.pathToArray)(itemPath),

@@ -804,3 +819,3 @@ );

returnType,
fieldEntries,
fieldNodes,
info,

@@ -819,3 +834,2 @@ path,

const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
const fieldNodes = fieldEntries.map((entry) => entry.node);

@@ -834,3 +848,3 @@ if ((0, _isPromise.isPromise)(runtimeType)) {

),
fieldEntries,
fieldNodes,
info,

@@ -853,3 +867,3 @@ path,

),
fieldEntries,
fieldNodes,
info,

@@ -929,3 +943,3 @@ path,

returnType,
fieldEntries,
fieldNodes,
info,

@@ -936,3 +950,3 @@ path,

// Collect sub-fields to execute to complete this value.
const subFieldNodes = collectSubfields(exeContext, returnType, fieldEntries); // If there is an isTypeOf predicate function, call it with the
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes); // If there is an isTypeOf predicate function, call it with the
// current result. If isTypeOf returns false, then raise an error rather

@@ -947,7 +961,3 @@ // than continuing execution.

if (!resolvedIsTypeOf) {
throw invalidReturnTypeError(
returnType,
result,
fieldEntries.map((entry) => entry.node),
);
throw invalidReturnTypeError(returnType, result, fieldNodes);
}

@@ -966,7 +976,3 @@

if (!isTypeOf) {
throw invalidReturnTypeError(
returnType,
result,
fieldEntries.map((entry) => entry.node),
);
throw invalidReturnTypeError(returnType, result, fieldNodes);
}

@@ -1069,4 +1075,4 @@ }

function getFieldDef(schema, parentType, entry) {
const fieldName = entry.node.name.value;
function getFieldDef(schema, parentType, fieldNode) {
const fieldName = fieldNode.name.value;

@@ -1073,0 +1079,0 @@ if (

@@ -185,11 +185,11 @@ 'use strict';

);
const [responseName, fieldEntries] = [...rootFields.entries()][0];
const fieldDef = (0, _execute.getFieldDef)(schema, rootType, fieldEntries[0]);
const [responseName, fieldNodes] = [...rootFields.entries()][0];
const fieldDef = (0, _execute.getFieldDef)(schema, rootType, fieldNodes[0]);
if (!fieldDef) {
const fieldName = fieldEntries[0].node.name.value;
const fieldName = fieldNodes[0].name.value;
throw new _GraphQLError.GraphQLError(
`The subscription field "${fieldName}" is not defined.`,
{
nodes: fieldEntries.map((entry) => entry.node),
nodes: fieldNodes,
},

@@ -203,3 +203,3 @@ );

fieldDef,
fieldEntries,
fieldNodes,
rootType,

@@ -217,4 +217,4 @@ path,

const args = (0, _values.getArgumentValues)(
fieldEntries[0].node,
fieldDef.args,
fieldDef,
fieldNodes[0],
variableValues,

@@ -243,3 +243,3 @@ ); // The resolve function's optional third argument is a context value that

error,
fieldEntries.map((entry) => entry.node),
fieldNodes,
(0, _Path.pathToArray)(path),

@@ -246,0 +246,0 @@ );

@@ -7,6 +7,5 @@ import type { Maybe } from '../jsutils/Maybe';

FieldNode,
FragmentSpreadNode,
VariableDefinitionNode,
} from '../language/ast';
import type { GraphQLArgument } from '../type/definition';
import type { GraphQLField } from '../type/definition';
import type { GraphQLDirective } from '../type/directives';

@@ -53,19 +52,8 @@ import type { GraphQLSchema } from '../type/schema';

export declare function getArgumentValues(
def: GraphQLField<unknown, unknown> | GraphQLDirective,
node: FieldNode | DirectiveNode,
argDefs: ReadonlyArray<GraphQLArgument>,
variableValues?: Maybe<ObjMap<unknown>>,
fragmentArgValues?: Maybe<ObjMap<unknown>>,
): {
[argument: string]: unknown;
};
export declare function getArgumentValuesFromSpread(
/** NOTE: For error annotations only */
node: FragmentSpreadNode,
schema: GraphQLSchema,
fragmentVarDefs: ReadonlyArray<VariableDefinitionNode>,
variableValues: Maybe<ObjMap<unknown>>,
fragmentArgValues?: Maybe<ObjMap<unknown>>,
): {
[argument: string]: unknown;
};
/**

@@ -72,0 +60,0 @@ * Prepares an object map of argument values given a directive definition

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

exports.getArgumentValues = getArgumentValues;
exports.getArgumentValuesFromSpread = getArgumentValuesFromSpread;
exports.getDirectiveValues = getDirectiveValues;

@@ -32,4 +31,2 @@ exports.getVariableValues = getVariableValues;

var _valueFromASTUntyped = require('../utilities/valueFromASTUntyped.js');
/**

@@ -172,3 +169,3 @@ * Prepares an object map of variableValues of the correct type based on the

function getArgumentValues(node, argDefs, variableValues, fragmentArgValues) {
function getArgumentValues(def, node, variableValues) {
var _node$arguments;

@@ -189,3 +186,3 @@

for (const argDef of argDefs) {
for (const argDef of def.args) {
const name = argDef.name;

@@ -213,3 +210,3 @@ const argType = argDef.type;

const valueNode = argumentNode.value;
let hasValue = valueNode.kind !== _kinds.Kind.NULL;
let isNull = valueNode.kind === _kinds.Kind.NULL;

@@ -220,35 +217,26 @@ if (valueNode.kind === _kinds.Kind.VARIABLE) {

if (
fragmentArgValues != null &&
hasOwnProperty(fragmentArgValues, variableName)
variableValues == null ||
!hasOwnProperty(variableValues, variableName)
) {
hasValue = fragmentArgValues[variableName] != null;
if (!hasValue && argDef.defaultValue !== undefined) {
if (argDef.defaultValue !== undefined) {
coercedValues[name] = argDef.defaultValue;
continue;
} else if ((0, _definition.isNonNullType)(argType)) {
throw new _GraphQLError.GraphQLError(
`Argument "${name}" of required type "${(0, _inspect.inspect)(
argType,
)}" ` +
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
{
nodes: valueNode,
},
);
}
} else if (
variableValues != null &&
hasOwnProperty(variableValues, variableName)
) {
hasValue = variableValues[variableName] != null;
} else if (argDef.defaultValue !== undefined) {
coercedValues[name] = argDef.defaultValue;
continue;
} else if ((0, _definition.isNonNullType)(argType)) {
throw new _GraphQLError.GraphQLError(
`Argument "${name}" of required type "${(0, _inspect.inspect)(
argType,
)}" ` +
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
{
nodes: valueNode,
},
);
} else {
continue;
}
isNull = variableValues[variableName] == null;
}
if (!hasValue && (0, _definition.isNonNullType)(argType)) {
if (isNull && (0, _definition.isNonNullType)(argType)) {
throw new _GraphQLError.GraphQLError(

@@ -264,6 +252,7 @@ `Argument "${name}" of non-null type "${(0, _inspect.inspect)(

const coercedValue = (0, _valueFromAST.valueFromAST)(valueNode, argType, {
...variableValues,
...fragmentArgValues,
});
const coercedValue = (0, _valueFromAST.valueFromAST)(
valueNode,
argType,
variableValues,
);

@@ -289,93 +278,2 @@ if (coercedValue === undefined) {

}
function getArgumentValuesFromSpread(
/** NOTE: For error annotations only */
node,
schema,
fragmentVarDefs,
variableValues,
fragmentArgValues,
) {
var _node$arguments2;
const coercedValues = {};
const argNodeMap = (0, _keyMap.keyMap)(
(_node$arguments2 =
node === null || node === void 0 ? void 0 : node.arguments) !== null &&
_node$arguments2 !== void 0
? _node$arguments2
: [],
(arg) => arg.name.value,
);
for (const varDef of fragmentVarDefs) {
const name = varDef.variable.name.value;
const argType = (0, _typeFromAST.typeFromAST)(schema, varDef.type);
const argumentNode = argNodeMap[name];
if (argumentNode == null) {
if (varDef.defaultValue !== undefined) {
coercedValues[name] = (0, _valueFromASTUntyped.valueFromASTUntyped)(
varDef.defaultValue,
);
} else if ((0, _definition.isNonNullType)(argType)) {
throw new _GraphQLError.GraphQLError(
`Argument "${name}" of required type "${(0, _inspect.inspect)(
argType,
)}" ` + 'was not provided.',
{
nodes: node,
},
);
} else {
coercedValues[name] = undefined;
}
continue;
}
const valueNode = argumentNode.value;
let hasValue = valueNode.kind !== _kinds.Kind.NULL;
if (valueNode.kind === _kinds.Kind.VARIABLE) {
const variableName = valueNode.name.value;
if (
fragmentArgValues != null &&
hasOwnProperty(fragmentArgValues, variableName)
) {
hasValue = fragmentArgValues[variableName] != null;
} else if (
variableValues != null &&
hasOwnProperty(variableValues, variableName)
) {
hasValue = variableValues[variableName] != null;
}
}
if (!hasValue && (0, _definition.isNonNullType)(argType)) {
throw new _GraphQLError.GraphQLError(
`Argument "${name}" of non-null type "${(0, _inspect.inspect)(
argType,
)}" ` + 'must not be null.',
{
nodes: valueNode,
},
);
}
let coercedValue;
if (argType && (0, _definition.isInputType)(argType)) {
coercedValue = (0, _valueFromAST.valueFromAST)(valueNode, argType, {
...variableValues,
...fragmentArgValues,
});
}
coercedValues[name] = coercedValue;
}
return coercedValues;
}
/**

@@ -404,3 +302,3 @@ * Prepares an object map of argument values given a directive definition

if (directiveNode) {
return getArgumentValues(directiveNode, directiveDef.args, variableValues);
return getArgumentValues(directiveDef, directiveNode, variableValues);
}

@@ -407,0 +305,0 @@ }

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

typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
/**
* Set to `false` to disable error propagation. Experimental.
*
* @experimental
*/
errorPropagation?: boolean;
}

@@ -61,0 +67,0 @@ export declare function graphql(args: GraphQLArgs): Promise<ExecutionResult>;

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

typeResolver,
errorPropagation,
} = args; // Validate Schema

@@ -96,3 +97,4 @@

typeResolver,
errorPropagation,
});
}

@@ -44,2 +44,3 @@ /**

GraphQLNonNull,
GraphQLSemanticNonNull,
specifiedScalarTypes,

@@ -65,2 +66,3 @@ GraphQLInt,

__DirectiveLocation,
__TypeNullability,
__Type,

@@ -85,2 +87,3 @@ __Field,

isNonNullType,
isSemanticNonNullType,
isInputType,

@@ -110,2 +113,3 @@ isOutputType,

assertNonNullType,
assertSemanticNonNullType,
assertInputType,

@@ -262,2 +266,3 @@ assertOutputType,

NonNullTypeNode,
SemanticNonNullTypeNode,
TypeSystemDefinitionNode,

@@ -413,2 +418,3 @@ SchemaDefinitionNode,

IntrospectionNonNullTypeRef,
IntrospectionSemanticNonNullTypeRef,
IntrospectionField,

@@ -415,0 +421,0 @@ IntrospectionInputValue,

@@ -168,2 +168,8 @@ 'use strict';

});
Object.defineProperty(exports, 'GraphQLSemanticNonNull', {
enumerable: true,
get: function () {
return _index.GraphQLSemanticNonNull;
},
});
Object.defineProperty(exports, 'GraphQLSkipDirective', {

@@ -523,2 +529,8 @@ enumerable: true,

});
Object.defineProperty(exports, '__TypeNullability', {
enumerable: true,
get: function () {
return _index.__TypeNullability;
},
});
Object.defineProperty(exports, 'assertAbstractType', {

@@ -632,2 +644,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'assertSemanticNonNullType', {
enumerable: true,
get: function () {
return _index.assertSemanticNonNullType;
},
});
Object.defineProperty(exports, 'assertType', {

@@ -993,2 +1011,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'isSemanticNonNullType', {
enumerable: true,
get: function () {
return _index.isSemanticNonNullType;
},
});
Object.defineProperty(exports, 'isSpecifiedDirective', {

@@ -995,0 +1019,0 @@ enumerable: true,

@@ -119,2 +119,3 @@ import type { Kind } from './kinds';

| NonNullTypeNode
| SemanticNonNullTypeNode
| SchemaDefinitionNode

@@ -237,3 +238,2 @@ | OperationTypeDefinitionNode

readonly name: NameNode;
readonly arguments?: ReadonlyArray<ArgumentNode>;
readonly directives?: ReadonlyArray<DirectiveNode>;

@@ -252,2 +252,3 @@ }

readonly name: NameNode;
/** @deprecated variableDefinitions will be removed in v17.0.0 */
readonly variableDefinitions?: ReadonlyArray<VariableDefinitionNode>;

@@ -354,3 +355,7 @@ readonly typeCondition: NamedTypeNode;

/** Type Reference */
export declare type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
export declare type TypeNode =
| NamedTypeNode
| ListTypeNode
| NonNullTypeNode
| SemanticNonNullTypeNode;
export interface NamedTypeNode {

@@ -371,2 +376,7 @@ readonly kind: Kind.NAMED_TYPE;

}
export interface SemanticNonNullTypeNode {
readonly kind: Kind.SEMANTIC_NON_NULL_TYPE;
readonly loc?: Location;
readonly type: NamedTypeNode | ListTypeNode;
}
/** Type System Definition */

@@ -373,0 +383,0 @@ export declare type TypeSystemDefinitionNode =

@@ -144,6 +144,6 @@ 'use strict';

Argument: ['name', 'value'],
FragmentSpread: ['name', 'arguments', 'directives'],
FragmentSpread: ['name', 'directives'],
InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
FragmentDefinition: [
'name',
'name', // Note: fragment variable definitions are deprecated and will removed in v17.0.0
'variableDefinitions',

@@ -167,2 +167,3 @@ 'typeCondition',

NonNullType: ['type'],
SemanticNonNullType: ['type'],
SchemaDefinition: ['description', 'directives', 'operationTypes'],

@@ -169,0 +170,0 @@ OperationTypeDefinition: ['type'],

@@ -26,3 +26,2 @@ /**

INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION',
FRAGMENT_VARIABLE_DEFINITION = 'FRAGMENT_VARIABLE_DEFINITION',
}

@@ -29,0 +28,0 @@ export { DirectiveLocation };

@@ -34,4 +34,2 @@ 'use strict';

DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
DirectiveLocation['FRAGMENT_VARIABLE_DEFINITION'] =
'FRAGMENT_VARIABLE_DEFINITION';
})(DirectiveLocation || (exports.DirectiveLocation = DirectiveLocation = {}));

@@ -38,0 +36,0 @@ /**

@@ -60,2 +60,3 @@ export { Source } from './source';

NonNullTypeNode,
SemanticNonNullTypeNode,
TypeSystemDefinitionNode,

@@ -62,0 +63,0 @@ SchemaDefinitionNode,

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

NON_NULL_TYPE = 'NonNullType',
SEMANTIC_NON_NULL_TYPE = 'SemanticNonNullType',
/** Type System Definitions */

@@ -37,0 +38,0 @@ SCHEMA_DEFINITION = 'SchemaDefinition',

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

Kind['NON_NULL_TYPE'] = 'NonNullType';
Kind['SEMANTIC_NON_NULL_TYPE'] = 'SemanticNonNullType';
Kind['SCHEMA_DEFINITION'] = 'SchemaDefinition';

@@ -41,0 +42,0 @@ Kind['OPERATION_TYPE_DEFINITION'] = 'OperationTypeDefinition';

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

kind === _tokenKind.TokenKind.BANG ||
kind === _tokenKind.TokenKind.ASTERISK ||
kind === _tokenKind.TokenKind.DOLLAR ||

@@ -265,3 +266,3 @@ kind === _tokenKind.TokenKind.AMP ||

//
// Punctuator :: one of ! $ & ( ) ... : = @ [ ] { | }
// Punctuator :: one of ! $ & ( ) * ... : = @ [ ] { | }

@@ -313,2 +314,11 @@ case 0x0021:

case 0x002a:
// *
return createToken(
lexer,
_tokenKind.TokenKind.ASTERISK,
position,
position + 1,
);
case 0x002e:

@@ -315,0 +325,0 @@ // .

@@ -91,22 +91,2 @@ import type { Maybe } from '../jsutils/Maybe';

allowLegacyFragmentVariables?: boolean;
/**
* EXPERIMENTAL:
*
* If enabled, the parser will understand and parse fragment variable definitions
* and arguments on fragment spreads. Fragment variable definitions will be represented
* in the `variableDefinitions` field of the FragmentDefinitionNode.
* Fragment spread arguments will be represented in the `arguments` field of FragmentSpreadNode.
*
* For example:
*
* ```graphql
* {
* t { ...A(var: true) }
* }
* fragment A($var: Boolean = false) on T {
* ...B(x: $var)
* }
* ```
*/
experimentalFragmentArguments?: boolean | undefined;
}

@@ -260,3 +240,3 @@ /**

*
* FragmentSpread : ... FragmentName Arguments? Directives?
* FragmentSpread : ... FragmentName Directives?
*

@@ -268,3 +248,3 @@ * InlineFragment : ... TypeCondition? Directives? SelectionSet

* FragmentDefinition :
* - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
* - fragment FragmentName on TypeCondition Directives? SelectionSet
*

@@ -339,2 +319,3 @@ * TypeCondition : NamedType

* - NonNullType
* - SemanticNonNullType
*/

@@ -341,0 +322,0 @@ parseTypeReference(): TypeNode;

@@ -403,3 +403,3 @@ 'use strict';

*
* FragmentSpread : ... FragmentName Arguments? Directives?
* FragmentSpread : ... FragmentName Directives?
*

@@ -415,19 +415,5 @@ * InlineFragment : ... TypeCondition? Directives? SelectionSet

if (!hasTypeCondition && this.peek(_tokenKind.TokenKind.NAME)) {
const name = this.parseFragmentName();
if (
this.peek(_tokenKind.TokenKind.PAREN_L) &&
this._options.experimentalFragmentArguments
) {
return this.node(start, {
kind: _kinds.Kind.FRAGMENT_SPREAD,
name,
arguments: this.parseArguments(false),
directives: this.parseDirectives(false),
});
}
return this.node(start, {
kind: _kinds.Kind.FRAGMENT_SPREAD,
name,
name: this.parseFragmentName(),
directives: this.parseDirectives(false),

@@ -446,3 +432,3 @@ });

* FragmentDefinition :
* - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
* - fragment FragmentName on TypeCondition Directives? SelectionSet
*

@@ -454,11 +440,20 @@ * TypeCondition : NamedType

const start = this._lexer.token;
this.expectKeyword('fragment');
this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
// the grammar of FragmentDefinition:
// - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
if (this._options.allowLegacyFragmentVariables === true) {
return this.node(start, {
kind: _kinds.Kind.FRAGMENT_DEFINITION,
name: this.parseFragmentName(),
variableDefinitions: this.parseVariableDefinitions(),
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
directives: this.parseDirectives(false),
selectionSet: this.parseSelectionSet(),
});
}
return this.node(start, {
kind: _kinds.Kind.FRAGMENT_DEFINITION,
name: this.parseFragmentName(),
variableDefinitions:
this._options.experimentalFragmentArguments === true ||
this._options.allowLegacyFragmentVariables === true
? this.parseVariableDefinitions()
: undefined,
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),

@@ -683,2 +678,3 @@ directives: this.parseDirectives(false),

* - NonNullType
* - SemanticNonNullType
*/

@@ -708,2 +704,9 @@

if (this.expectOptionalToken(_tokenKind.TokenKind.ASTERISK)) {
return this.node(start, {
kind: _kinds.Kind.SEMANTIC_NON_NULL_TYPE,
type,
});
}
return type;

@@ -710,0 +713,0 @@ }

@@ -71,3 +71,4 @@ 'use strict';

node.kind === _kinds.Kind.LIST_TYPE ||
node.kind === _kinds.Kind.NON_NULL_TYPE
node.kind === _kinds.Kind.NON_NULL_TYPE ||
node.kind === _kinds.Kind.SEMANTIC_NON_NULL_TYPE
);

@@ -74,0 +75,0 @@ }

@@ -64,6 +64,9 @@ 'use strict';

const prefix = wrap('', alias, ': ') + name;
return join(
[wrappedLineAndArgs(prefix, args), join(directives, ' '), selectionSet],
' ',
);
let argsLine = prefix + wrap('(', join(args, ', '), ')');
if (argsLine.length > MAX_LINE_LENGTH) {
argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
}
return join([argsLine, join(directives, ' '), selectionSet], ' ');
},

@@ -76,8 +79,4 @@ },

FragmentSpread: {
leave: ({ name, arguments: args, directives }) => {
const prefix = '...' + name;
return (
wrappedLineAndArgs(prefix, args) + wrap(' ', join(directives, ' '))
);
},
leave: ({ name, directives }) =>
'...' + name + wrap(' ', join(directives, ' ')),
},

@@ -151,2 +150,5 @@ InlineFragment: {

},
SemanticNonNullType: {
leave: ({ type }) => type + '*',
},
// Type System Definitions

@@ -356,11 +358,1 @@ SchemaDefinition: {

}
function wrappedLineAndArgs(prefix, args) {
let argsLine = prefix + wrap('(', join(args, ', '), ')');
if (argsLine.length > MAX_LINE_LENGTH) {
argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
}
return argsLine;
}

@@ -9,2 +9,3 @@ /**

BANG = '!',
ASTERISK = '*',
DOLLAR = '$',

@@ -11,0 +12,0 @@ AMP = '&',

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

TokenKind['BANG'] = '!';
TokenKind['ASTERISK'] = '*';
TokenKind['DOLLAR'] = '$';

@@ -21,0 +22,0 @@ TokenKind['AMP'] = '&';

{
"name": "graphql",
"version": "16.9.0-canary.pr.4159.0fa29326c53fcd63c6473c7357c28aa13fa0019d",
"version": "16.9.0-canary.pr.4192.1813397076f44a55e5798478e7321db9877de97a",
"description": "A Query Language and Runtime which can target any service.",

@@ -37,5 +37,5 @@ "license": "MIT",

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

@@ -46,2 +46,11 @@ import type { Maybe } from '../jsutils/Maybe';

| GraphQLList<GraphQLType>
>
| GraphQLSemanticNonNull<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>;

@@ -95,2 +104,14 @@ export declare function isType(type: unknown): type is GraphQLType;

): GraphQLNonNull<GraphQLType>;
export declare function isSemanticNonNullType(
type: GraphQLInputType,
): type is GraphQLSemanticNonNull<GraphQLInputType>;
export declare function isSemanticNonNullType(
type: GraphQLOutputType,
): type is GraphQLSemanticNonNull<GraphQLOutputType>;
export declare function isSemanticNonNullType(
type: unknown,
): type is GraphQLSemanticNonNull<GraphQLType>;
export declare function assertSemanticNonNullType(
type: unknown,
): GraphQLSemanticNonNull<GraphQLType>;
/**

@@ -129,2 +150,10 @@ * These types may be used as input types for arguments and directives.

| GraphQLList<GraphQLOutputType>
>
| GraphQLSemanticNonNull<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLList<GraphQLOutputType>
>;

@@ -217,2 +246,33 @@ export declare function isOutputType(type: unknown): type is GraphQLOutputType;

/**
* Semantic-Non-Null Type Wrapper
*
* A semantic-non-null is a wrapping type which points to another type.
* Semantic-non-null types enforce that their values are never null unless
* caused by an error being raised. It is useful for fields which you can make
* a guarantee on non-nullability in a no-error case, for example when you know
* that a related entity must exist (but acknowledge that retrieving it may
* produce an error).
*
* Example:
*
* ```ts
* const RowType = new GraphQLObjectType({
* name: 'Row',
* fields: () => ({
* email: { type: new GraphQLSemanticNonNull(GraphQLString) },
* })
* })
* ```
* Note: the enforcement of non-nullability occurs within the executor.
*
* @experimental
*/
export declare class GraphQLSemanticNonNull<T extends GraphQLNullableType> {
readonly ofType: T;
constructor(ofType: T);
get [Symbol.toStringTag](): string;
toString(): string;
toJSON(): string;
}
/**
* These types wrap and modify other types

@@ -222,3 +282,4 @@ */

| GraphQLList<GraphQLType>
| GraphQLNonNull<GraphQLType>;
| GraphQLNonNull<GraphQLType>
| GraphQLSemanticNonNull<GraphQLType>;
export declare function isWrappingType(

@@ -245,3 +306,3 @@ type: unknown,

export declare function getNullableType<T extends GraphQLNullableType>(
type: T | GraphQLNonNull<T>,
type: T | GraphQLNonNull<T> | GraphQLSemanticNonNull<T>,
): T;

@@ -252,3 +313,3 @@ export declare function getNullableType(

/**
* These named types do not include modifiers like List or NonNull.
* These named types do not include modifiers like List, NonNull, or SemanticNonNull
*/

@@ -520,2 +581,4 @@ export declare type GraphQLNamedType =

};
/** @experimental */
readonly errorPropagation: boolean;
}

@@ -522,0 +585,0 @@ /**

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

exports.GraphQLUnionType =
exports.GraphQLSemanticNonNull =
exports.GraphQLScalarType =

@@ -31,2 +32,3 @@ exports.GraphQLObjectType =

exports.assertScalarType = assertScalarType;
exports.assertSemanticNonNullType = assertSemanticNonNullType;
exports.assertType = assertType;

@@ -54,2 +56,3 @@ exports.assertUnionType = assertUnionType;

exports.isScalarType = isScalarType;
exports.isSemanticNonNullType = isSemanticNonNullType;
exports.isType = isType;

@@ -102,3 +105,4 @@ exports.isUnionType = isUnionType;

isListType(type) ||
isNonNullType(type)
isNonNullType(type) ||
isSemanticNonNullType(type)
);

@@ -233,2 +237,18 @@ }

}
function isSemanticNonNullType(type) {
return (0, _instanceOf.instanceOf)(type, GraphQLSemanticNonNull);
}
function assertSemanticNonNullType(type) {
if (!isSemanticNonNullType(type)) {
throw new Error(
`Expected ${(0, _inspect.inspect)(
type,
)} to be a GraphQL Semantic-Non-Null type.`,
);
}
return type;
}
/**

@@ -238,2 +258,3 @@ * These types may be used as input types for arguments and directives.

// Note: GraphQLSemanticNonNull is currently not allowed for input types
function isInputType(type) {

@@ -244,3 +265,5 @@ return (

isInputObjectType(type) ||
(isWrappingType(type) && isInputType(type.ofType))
(!isSemanticNonNullType(type) &&
isWrappingType(type) &&
isInputType(type.ofType))
);

@@ -424,3 +447,24 @@ }

/**
* These types wrap and modify other types
* Semantic-Non-Null Type Wrapper
*
* A semantic-non-null is a wrapping type which points to another type.
* Semantic-non-null types enforce that their values are never null unless
* caused by an error being raised. It is useful for fields which you can make
* a guarantee on non-nullability in a no-error case, for example when you know
* that a related entity must exist (but acknowledge that retrieving it may
* produce an error).
*
* Example:
*
* ```ts
* const RowType = new GraphQLObjectType({
* name: 'Row',
* fields: () => ({
* email: { type: new GraphQLSemanticNonNull(GraphQLString) },
* })
* })
* ```
* Note: the enforcement of non-nullability occurs within the executor.
*
* @experimental
*/

@@ -430,4 +474,34 @@

class GraphQLSemanticNonNull {
constructor(ofType) {
isNullableType(ofType) ||
(0, _devAssert.devAssert)(
false,
`Expected ${(0, _inspect.inspect)(
ofType,
)} to be a GraphQL nullable type.`,
);
this.ofType = ofType;
}
get [Symbol.toStringTag]() {
return 'GraphQLSemanticNonNull';
}
toString() {
return String(this.ofType) + '*';
}
toJSON() {
return this.toString();
}
}
/**
* These types wrap and modify other types
*/
exports.GraphQLSemanticNonNull = GraphQLSemanticNonNull;
function isWrappingType(type) {
return isListType(type) || isNonNullType(type);
return isListType(type) || isNonNullType(type) || isSemanticNonNullType(type);
}

@@ -449,3 +523,3 @@

function isNullableType(type) {
return isType(type) && !isNonNullType(type);
return isType(type) && !isNonNullType(type) && !isSemanticNonNullType(type);
}

@@ -465,7 +539,9 @@

if (type) {
return isNonNullType(type) ? type.ofType : type;
return isNonNullType(type) || isSemanticNonNullType(type)
? type.ofType
: type;
}
}
/**
* These named types do not include modifiers like List or NonNull.
* These named types do not include modifiers like List, NonNull, or SemanticNonNull
*/

@@ -870,2 +946,3 @@

function isRequiredArgument(arg) {
// Note: input types cannot be SemanticNonNull
return isNonNullType(arg.type) && arg.defaultValue === undefined;

@@ -1373,3 +1450,4 @@ }

function isRequiredInputField(field) {
// Note: input types cannot be SemanticNonNull
return isNonNullType(field.type) && field.defaultValue === undefined;
}

@@ -16,2 +16,3 @@ export type { Path as ResponsePath } from '../jsutils/Path';

isNonNullType,
isSemanticNonNullType,
isInputType,

@@ -36,2 +37,3 @@ isOutputType,

assertNonNullType,
assertSemanticNonNullType,
assertInputType,

@@ -55,2 +57,3 @@ assertOutputType,

GraphQLNonNull,
GraphQLSemanticNonNull,
} from './definition';

@@ -143,2 +146,3 @@ export type {

__DirectiveLocation,
__TypeNullability,
__Type,

@@ -145,0 +149,0 @@ __Field,

@@ -120,2 +120,8 @@ 'use strict';

});
Object.defineProperty(exports, 'GraphQLSemanticNonNull', {
enumerable: true,
get: function () {
return _definition.GraphQLSemanticNonNull;
},
});
Object.defineProperty(exports, 'GraphQLSkipDirective', {

@@ -217,2 +223,8 @@ enumerable: true,

});
Object.defineProperty(exports, '__TypeNullability', {
enumerable: true,
get: function () {
return _introspection.__TypeNullability;
},
});
Object.defineProperty(exports, 'assertAbstractType', {

@@ -326,2 +338,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'assertSemanticNonNullType', {
enumerable: true,
get: function () {
return _definition.assertSemanticNonNullType;
},
});
Object.defineProperty(exports, 'assertType', {

@@ -483,2 +501,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'isSemanticNonNullType', {
enumerable: true,
get: function () {
return _definition.isSemanticNonNullType;
},
});
Object.defineProperty(exports, 'isSpecifiedDirective', {

@@ -485,0 +509,0 @@ enumerable: true,

@@ -6,2 +6,3 @@ import type { GraphQLField, GraphQLNamedType } from './definition';

export declare const __DirectiveLocation: GraphQLEnumType;
export declare const __TypeNullability: GraphQLEnumType;
export declare const __Type: GraphQLObjectType;

@@ -20,2 +21,3 @@ export declare const __Field: GraphQLObjectType;

NON_NULL = 'NON_NULL',
SEMANTIC_NON_NULL = 'SEMANTIC_NON_NULL',
}

@@ -22,0 +24,0 @@ export { TypeKind };

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

exports.introspectionTypes =
exports.__TypeNullability =
exports.__TypeKind =

@@ -171,8 +172,4 @@ exports.__Type =

value: _directiveLocation.DirectiveLocation.VARIABLE_DEFINITION,
description: 'Location adjacent to an operation variable definition.',
description: 'Location adjacent to a variable definition.',
},
FRAGMENT_VARIABLE_DEFINITION: {
value: _directiveLocation.DirectiveLocation.FRAGMENT_VARIABLE_DEFINITION,
description: 'Location adjacent to a fragment variable definition.',
},
SCHEMA: {

@@ -223,6 +220,41 @@ value: _directiveLocation.DirectiveLocation.SCHEMA,

},
});
}); // TODO: rename enum and options
exports.__DirectiveLocation = __DirectiveLocation;
var TypeNullability; // TODO: rename
(function (TypeNullability) {
TypeNullability['AUTO'] = 'AUTO';
TypeNullability['TRADITIONAL'] = 'TRADITIONAL';
TypeNullability['SEMANTIC'] = 'SEMANTIC';
TypeNullability['FULL'] = 'FULL';
})(TypeNullability || (TypeNullability = {}));
const __TypeNullability = new _definition.GraphQLEnumType({
name: '__TypeNullability',
description: 'TODO',
values: {
AUTO: {
value: TypeNullability.AUTO,
description:
'Determines nullability mode based on errorPropagation mode.',
},
TRADITIONAL: {
value: TypeNullability.TRADITIONAL,
description: 'Turn semantic-non-null types into nullable types.',
},
SEMANTIC: {
value: TypeNullability.SEMANTIC,
description: 'Turn non-null types into semantic-non-null types.',
},
FULL: {
value: TypeNullability.FULL,
description:
'Render the true nullability in the schema; be prepared for new types of nullability in future!',
},
},
});
exports.__TypeNullability = __TypeNullability;
const __Type = new _definition.GraphQLObjectType({

@@ -268,2 +300,6 @@ name: '__Type',

}
if ((0, _definition.isSemanticNonNullType)(type)) {
return TypeKind.SEMANTIC_NON_NULL;
}
/* c8 ignore next 3 */

@@ -431,3 +467,21 @@ // Not reachable, all possible types have been considered)

type: new _definition.GraphQLNonNull(__Type),
resolve: (field) => field.type,
args: {
nullability: {
type: new _definition.GraphQLNonNull(__TypeNullability),
defaultValue: TypeNullability.AUTO,
},
},
resolve: (field, { nullability }, _context, info) => {
if (nullability === TypeNullability.FULL) {
return field.type;
}
const mode =
nullability === TypeNullability.AUTO
? info.errorPropagation
? TypeNullability.TRADITIONAL
: TypeNullability.SEMANTIC
: nullability;
return convertOutputTypeToNullabilityMode(field.type, mode);
},
},

@@ -443,6 +497,39 @@ isDeprecated: {

}),
});
}); // TODO: move this elsewhere, rename, memoize
exports.__Field = __Field;
function convertOutputTypeToNullabilityMode(type, mode) {
if (mode === TypeNullability.TRADITIONAL) {
if ((0, _definition.isNonNullType)(type)) {
return new _definition.GraphQLNonNull(
convertOutputTypeToNullabilityMode(type.ofType, mode),
);
} else if ((0, _definition.isSemanticNonNullType)(type)) {
return convertOutputTypeToNullabilityMode(type.ofType, mode);
} else if ((0, _definition.isListType)(type)) {
return new _definition.GraphQLList(
convertOutputTypeToNullabilityMode(type.ofType, mode),
);
}
return type;
}
if (
(0, _definition.isNonNullType)(type) ||
(0, _definition.isSemanticNonNullType)(type)
) {
return new _definition.GraphQLSemanticNonNull(
convertOutputTypeToNullabilityMode(type.ofType, mode),
);
} else if ((0, _definition.isListType)(type)) {
return new _definition.GraphQLList(
convertOutputTypeToNullabilityMode(type.ofType, mode),
);
}
return type;
}
const __InputValue = new _definition.GraphQLObjectType({

@@ -526,2 +613,3 @@ name: '__InputValue',

TypeKind['NON_NULL'] = 'NON_NULL';
TypeKind['SEMANTIC_NON_NULL'] = 'SEMANTIC_NON_NULL';
})(TypeKind || (exports.TypeKind = TypeKind = {}));

@@ -571,2 +659,7 @@

},
SEMANTIC_NON_NULL: {
value: TypeKind.SEMANTIC_NON_NULL,
description:
'Indicates this type is a semantic-non-null. `ofType` is a valid field.',
},
},

@@ -627,2 +720,3 @@ });

__DirectiveLocation,
__TypeNullability,
__Type,

@@ -629,0 +723,0 @@ __Field,

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

function astFromValue(value, type) {
// Note: input types cannot be SemanticNonNull
if ((0, _definition.isNonNullType)(type)) {

@@ -46,0 +47,0 @@ const astValue = astFromValue(value, type.ofType);

@@ -108,6 +108,2 @@ 'use strict';

: options.allowLegacyFragmentVariables,
experimentalFragmentArguments:
options === null || options === void 0
? void 0
: options.experimentalFragmentArguments,
});

@@ -114,0 +110,0 @@ return buildASTSchema(document, {

@@ -119,2 +119,15 @@ 'use strict';

if (typeRef.kind === _introspection.TypeKind.SEMANTIC_NON_NULL) {
const nullableRef = typeRef.ofType;
if (!nullableRef) {
throw new Error('Decorated type deeper than introspection query.');
}
const nullableType = getType(nullableRef);
return new _definition.GraphQLSemanticNonNull(
(0, _definition.assertNullableType)(nullableType),
);
}
return getNamedType(typeRef);

@@ -121,0 +134,0 @@ }

@@ -185,2 +185,7 @@ 'use strict';

return new _definition.GraphQLNonNull(replaceType(type.ofType));
}
if ((0, _definition.isSemanticNonNullType)(type)) {
// @ts-expect-error
return new _definition.GraphQLSemanticNonNull(replaceType(type.ofType));
} // @ts-expect-error FIXME

@@ -443,2 +448,6 @@

if (node.kind === _kinds.Kind.SEMANTIC_NON_NULL_TYPE) {
return new _definition.GraphQLSemanticNonNull(getWrappedType(node.type));
}
return getNamedType(node);

@@ -445,0 +454,0 @@ }

@@ -433,2 +433,4 @@ 'use strict';

((0, _definition.isNonNullType)(newType) &&
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)) || // moving from nullable to semantic-non-null of the same underlying type is safe
((0, _definition.isSemanticNonNullType)(newType) &&
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))

@@ -446,2 +448,15 @@ );

if ((0, _definition.isSemanticNonNullType)(oldType)) {
return (
// if they're both semantic-non-null, make sure the underlying types are compatible
((0, _definition.isSemanticNonNullType)(newType) &&
isChangeSafeForObjectOrInterfaceField(
oldType.ofType,
newType.ofType,
)) || // moving from semantic-non-null to non-null of the same underlying type is safe
((0, _definition.isNonNullType)(newType) &&
isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType))
);
}
return (

@@ -451,2 +466,4 @@ // if they're both named types, see if their names are equivalent

((0, _definition.isNonNullType)(newType) &&
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)) || // moving from nullable to semantic-non-null of the same underlying type is safe
((0, _definition.isSemanticNonNullType)(newType) &&
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))

@@ -453,0 +470,0 @@ );

@@ -34,2 +34,12 @@ import type { Maybe } from '../jsutils/Maybe';

oneOf?: boolean;
/**
* Choose the type of nullability you would like to see.
*
* - AUTO: SEMANTIC if errorPropagation is set to false, otherwise TRADITIONAL
* - TRADITIONAL: all GraphQLSemanticNonNull will be unwrapped
* - SEMANTIC: all GraphQLNonNull will be converted to GraphQLSemanticNonNull
* - FULL: the true nullability will be returned
*
*/
nullability?: 'AUTO' | 'TRADITIONAL' | 'SEMANTIC' | 'FULL';
}

@@ -135,2 +145,8 @@ /**

}
export interface IntrospectionSemanticNonNullTypeRef<
T extends IntrospectionTypeRef = IntrospectionTypeRef,
> {
readonly kind: 'SEMANTIC_NON_NULL';
readonly ofType: T;
}
export declare type IntrospectionTypeRef =

@@ -141,2 +157,5 @@ | IntrospectionNamedTypeRef

IntrospectionNamedTypeRef | IntrospectionListTypeRef
>
| IntrospectionSemanticNonNullTypeRef<
IntrospectionNamedTypeRef | IntrospectionListTypeRef
>;

@@ -143,0 +162,0 @@ export declare type IntrospectionOutputTypeRef =

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

oneOf: false,
nullability: null,
...options,

@@ -39,2 +40,3 @@ };

const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
const nullability = optionsWithDefault.nullability;
return `

@@ -74,3 +76,3 @@ query IntrospectionQuery {

}
type {
type${nullability ? `(nullability: ${nullability})` : ''} {
...TypeRef

@@ -77,0 +79,0 @@ }

@@ -21,2 +21,3 @@ export { getIntrospectionQuery } from './getIntrospectionQuery';

IntrospectionNonNullTypeRef,
IntrospectionSemanticNonNullTypeRef,
IntrospectionField,

@@ -23,0 +24,0 @@ IntrospectionInputValue,

@@ -52,2 +52,5 @@ 'use strict';

return new _definition.GraphQLNonNull(replaceType(type.ofType));
} else if ((0, _definition.isSemanticNonNullType)(type)) {
// @ts-expect-error
return new _definition.GraphQLSemanticNonNull(replaceType(type.ofType));
} // @ts-expect-error FIXME: TS Conversion

@@ -54,0 +57,0 @@

@@ -26,2 +26,9 @@ 'use strict';

return isEqualType(typeA.ofType, typeB.ofType);
} // If either type is semantic-non-null, the other must also be semantic-non-null.
if (
(0, _definition.isSemanticNonNullType)(typeA) &&
(0, _definition.isSemanticNonNullType)(typeB)
) {
return isEqualType(typeA.ofType, typeB.ofType);
} // If either type is a list, the other must also be a list.

@@ -55,6 +62,20 @@

return false;
} // If superType is semantic-non-null, maybeSubType must be semantic-non-null or non-null.
if ((0, _definition.isSemanticNonNullType)(superType)) {
if (
(0, _definition.isNonNullType)(maybeSubType) ||
(0, _definition.isSemanticNonNullType)(maybeSubType)
) {
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
}
return false;
}
if ((0, _definition.isNonNullType)(maybeSubType)) {
// If superType is nullable, maybeSubType may be non-null or nullable.
if (
(0, _definition.isNonNullType)(maybeSubType) ||
(0, _definition.isSemanticNonNullType)(maybeSubType)
) {
// If superType is nullable, maybeSubType may be non-null, semantic-non-null, or nullable.
return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);

@@ -61,0 +82,0 @@ } // If superType type is a list, maybeSubType type must also be a list.

@@ -24,2 +24,7 @@ 'use strict';

case _kinds.Kind.SEMANTIC_NON_NULL_TYPE: {
const innerType = typeFromAST(schema, typeNode.type);
return innerType && new _definition.GraphQLSemanticNonNull(innerType);
}
case _kinds.Kind.NAMED_TYPE:

@@ -26,0 +31,0 @@ return schema.getType(typeNode.name.value);

@@ -30,4 +30,2 @@ import type { Maybe } from '../jsutils/Maybe';

private _enumValue;
private _fragmentSpread;
private _fragmentDefinitions;
private _getFieldDef;

@@ -34,0 +32,0 @@ constructor(

@@ -21,4 +21,2 @@ 'use strict';

var _valueFromAST = require('./valueFromAST.js');
/**

@@ -49,4 +47,2 @@ * TypeInfo is a utility class which, given a GraphQL schema, can keep track

this._enumValue = null;
this._fragmentSpread = null;
this._fragmentDefinitions = {};
this._getFieldDef =

@@ -131,15 +127,2 @@ getFieldDefFn !== null && getFieldDefFn !== void 0

switch (node.kind) {
case _kinds.Kind.DOCUMENT: {
// A document's fragment definitions are type signatures
// referenced via fragment spreads. Ensure we can use definitions
// before visiting their call sites.
for (const astNode of node.definitions) {
if (astNode.kind === _kinds.Kind.FRAGMENT_DEFINITION) {
this._fragmentDefinitions[astNode.name.value] = astNode;
}
}
break;
}
case _kinds.Kind.SELECTION_SET: {

@@ -191,7 +174,2 @@ const namedType = (0, _definition.getNamedType)(this.getType());

case _kinds.Kind.FRAGMENT_SPREAD: {
this._fragmentSpread = node;
break;
}
case _kinds.Kind.INLINE_FRAGMENT:

@@ -222,62 +200,22 @@ case _kinds.Kind.FRAGMENT_DEFINITION: {

case _kinds.Kind.ARGUMENT: {
var _this$getDirective;
let argDef;
let argType;
const directive = this.getDirective();
const fragmentSpread = this._fragmentSpread;
const fieldDef = this.getFieldDef();
const fieldOrDirective =
(_this$getDirective = this.getDirective()) !== null &&
_this$getDirective !== void 0
? _this$getDirective
: this.getFieldDef();
if (directive) {
argDef = directive.args.find((arg) => arg.name === node.name.value);
} else if (fragmentSpread) {
var _fragmentDef$variable;
if (fieldOrDirective) {
argDef = fieldOrDirective.args.find(
(arg) => arg.name === node.name.value,
);
const fragmentDef =
this._fragmentDefinitions[fragmentSpread.name.value];
const fragVarDef =
fragmentDef === null || fragmentDef === void 0
? void 0
: (_fragmentDef$variable = fragmentDef.variableDefinitions) ===
null || _fragmentDef$variable === void 0
? void 0
: _fragmentDef$variable.find(
(varDef) => varDef.variable.name.value === node.name.value,
);
if (fragVarDef) {
const fragVarType = (0, _typeFromAST.typeFromAST)(
schema,
fragVarDef.type,
);
if ((0, _definition.isInputType)(fragVarType)) {
const fragVarDefault = fragVarDef.defaultValue
? (0, _valueFromAST.valueFromAST)(
fragVarDef.defaultValue,
fragVarType,
)
: undefined;
const schemaArgDef = {
name: fragVarDef.variable.name.value,
type: fragVarType,
defaultValue: fragVarDefault,
description: undefined,
deprecationReason: undefined,
extensions: {},
astNode: {
...fragVarDef,
kind: _kinds.Kind.INPUT_VALUE_DEFINITION,
name: fragVarDef.variable.name,
},
};
argDef = schemaArgDef;
}
if (argDef) {
argType = argDef.type;
}
} else if (fieldDef) {
argDef = fieldDef.args.find((arg) => arg.name === node.name.value);
}
if (argDef) {
argType = argDef.type;
}
this._argument = argDef;

@@ -353,6 +291,2 @@

switch (node.kind) {
case _kinds.Kind.DOCUMENT:
this._fragmentDefinitions = {};
break;
case _kinds.Kind.SELECTION_SET:

@@ -374,6 +308,2 @@ this._parentTypeStack.pop();

case _kinds.Kind.FRAGMENT_SPREAD:
this._fragmentSpread = null;
break;
case _kinds.Kind.OPERATION_DEFINITION:

@@ -380,0 +310,0 @@ case _kinds.Kind.INLINE_FRAGMENT:

@@ -20,3 +20,2 @@ export { validate } from './validate';

export { ProvidedRequiredArgumentsRule } from './rules/ProvidedRequiredArgumentsRule';
export { NoUnusedFragmentVariablesRule } from './rules/NoUnusedFragmentVariablesRule';
export { ScalarLeafsRule } from './rules/ScalarLeafsRule';

@@ -23,0 +22,0 @@ export { SingleFieldSubscriptionsRule } from './rules/SingleFieldSubscriptionsRule';

@@ -90,8 +90,2 @@ 'use strict';

});
Object.defineProperty(exports, 'NoUnusedFragmentVariablesRule', {
enumerable: true,
get: function () {
return _NoUnusedFragmentVariablesRule.NoUnusedFragmentVariablesRule;
},
});
Object.defineProperty(exports, 'NoUnusedFragmentsRule', {

@@ -296,4 +290,2 @@ enumerable: true,

var _NoUnusedFragmentVariablesRule = require('./rules/NoUnusedFragmentVariablesRule.js');
var _ScalarLeafsRule = require('./rules/ScalarLeafsRule.js');

@@ -300,0 +292,0 @@

@@ -99,9 +99,4 @@ 'use strict';

case _kinds.Kind.VARIABLE_DEFINITION: {
const parentNode = ancestors[ancestors.length - 3];
'kind' in parentNode || (0, _invariant.invariant)(false);
return parentNode.kind === _kinds.Kind.OPERATION_DEFINITION
? _directiveLocation.DirectiveLocation.VARIABLE_DEFINITION
: _directiveLocation.DirectiveLocation.FRAGMENT_VARIABLE_DEFINITION;
}
case _kinds.Kind.VARIABLE_DEFINITION:
return _directiveLocation.DirectiveLocation.VARIABLE_DEFINITION;

@@ -108,0 +103,0 @@ case _kinds.Kind.SCHEMA_DEFINITION:

@@ -29,7 +29,3 @@ 'use strict';

for (const { node, fragmentVarDef } of usages) {
if (fragmentVarDef) {
continue;
}
for (const { node } of usages) {
const varName = node.name.value;

@@ -36,0 +32,0 @@

@@ -9,3 +9,3 @@ import type { ASTVisitor } from '../../language/visitor';

*
* See https://spec.graphql.org/draft/#sec-All-Operation-Variables-Used
* See https://spec.graphql.org/draft/#sec-All-Variables-Used
*/

@@ -12,0 +12,0 @@ export declare function NoUnusedVariablesRule(

@@ -16,3 +16,3 @@ 'use strict';

*
* See https://spec.graphql.org/draft/#sec-All-Operation-Variables-Used
* See https://spec.graphql.org/draft/#sec-All-Variables-Used
*/

@@ -29,3 +29,3 @@ function NoUnusedVariablesRule(context) {

const variableNameUsed = Object.create(null);
const usages = context.getOperationVariableUsages(operation);
const usages = context.getRecursiveVariableUsages(operation);

@@ -32,0 +32,0 @@ for (const { node } of usages) {

@@ -16,4 +16,2 @@ 'use strict';

var _visitor = require('../../language/visitor.js');
var _definition = require('../../type/definition.js');

@@ -56,3 +54,3 @@

const cachedFieldsAndFragmentSpreads = new Map();
const cachedFieldsAndFragmentNames = new Map();
return {

@@ -62,3 +60,3 @@ SelectionSet(selectionSet) {

context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -84,12 +82,2 @@ context.getParentType(),

const printFragmentSpreadArguments = (fragmentSpread) => {
if (!fragmentSpread.arguments || fragmentSpread.arguments.length === 0) {
return fragmentSpread.name.value;
}
const printedArguments = fragmentSpread.arguments
.map(_printer.print)
.sort((a, b) => a.localeCompare(b));
return fragmentSpread.name.value + '(' + printedArguments.join(',') + ')';
};
/**

@@ -152,6 +140,5 @@ * Algorithm:

// GraphQL Document.
function findConflictsWithinSelectionSet(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -162,8 +149,8 @@ parentType,

const conflicts = [];
const [fieldMap, fragmentSpreadMap] = getFieldsAndFragmentSpreads(
const [fieldMap, fragmentNames] = getFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
parentType,
selectionSet,
); // (A) First find all conflicts "within" the fields and fragment-spreads of this selection set.
); // (A) Find find all conflicts "within" the fields of this selection set.
// Note: this is the *only place* `collectConflictsWithin` is called.

@@ -174,24 +161,19 @@

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
fieldMap,
);
const allFragmentSpreads = [];
for (const [, fragmentSpreads] of Object.entries(fragmentSpreadMap)) {
allFragmentSpreads.push(...fragmentSpreads);
}
if (allFragmentSpreads.length !== 0) {
if (fragmentNames.length !== 0) {
// (B) Then collect conflicts between these fields and those represented by
// each spread fragment name found.
for (let i = 0; i < allFragmentSpreads.length; i++) {
for (let i = 0; i < fragmentNames.length; i++) {
collectConflictsBetweenFieldsAndFragment(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
false,
fieldMap,
allFragmentSpreads[i],
fragmentNames[i],
); // (C) Then compare this fragment with all other fragments found in this

@@ -202,11 +184,11 @@ // selection set to collect conflicts between fragments spread together.

for (let j = i + 1; j < allFragmentSpreads.length; j++) {
for (let j = i + 1; j < fragmentNames.length; j++) {
collectConflictsBetweenFragments(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
false,
allFragmentSpreads[i],
allFragmentSpreads[j],
fragmentNames[i],
fragmentNames[j],
);

@@ -224,9 +206,8 @@ }

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fieldMap,
fragmentSpread,
fragmentName,
) {
const fragmentName = fragmentSpread.name.value;
const fragment = context.getFragment(fragmentName);

@@ -239,7 +220,6 @@

const [fieldMap2, referencedFragmentNames] =
getReferencedFieldsAndFragmentSpreads(
getReferencedFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
fragment,
fragmentSpread,
); // Do not compare a fragment's fieldMap to itself.

@@ -255,3 +235,3 @@

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -264,5 +244,3 @@ areMutuallyExclusive,

for (const [referencedFragmentName, [spread]] of Object.entries(
referencedFragmentNames,
)) {
for (const referencedFragmentName of referencedFragmentNames) {
// Memoize so two fragments are not compared for conflicts more than once.

@@ -287,7 +265,7 @@ if (

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fieldMap,
spread,
referencedFragmentName,
);

@@ -301,33 +279,19 @@ }

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fragmentSpread1,
fragmentSpread2,
fragmentName1,
fragmentName2,
) {
const fragmentName1 = fragmentSpread1.name.value;
const fragmentName2 = fragmentSpread2.name.value;
if (
fragmentName1 === fragmentName2 &&
!sameArguments(fragmentSpread1, fragmentSpread2)
) {
context.reportError(
new _GraphQLError.GraphQLError(
`Spreads "${fragmentName1}" conflict because ${printFragmentSpreadArguments(
fragmentSpread1,
)} and ${printFragmentSpreadArguments(
fragmentSpread2,
)} have different fragment arguments.`,
{
nodes: [fragmentSpread1, fragmentSpread2],
},
),
);
// No need to compare a fragment to itself.
if (fragmentName1 === fragmentName2) {
return;
} // No need to compare a fragment to itself.
} // Memoize so two fragments are not compared for conflicts more than once.
if (
fragmentName1 === fragmentName2 &&
sameArguments(fragmentSpread1, fragmentSpread2)
comparedFragmentPairs.has(
fragmentName1,
fragmentName2,
areMutuallyExclusive,
)
) {

@@ -337,10 +301,3 @@ return;

const fragKey1 = printFragmentSpreadArguments(fragmentSpread1);
const fragKey2 = printFragmentSpreadArguments(fragmentSpread2); // Memoize so two fragments are not compared for conflicts more than once.
if (comparedFragmentPairs.has(fragKey1, fragKey2, areMutuallyExclusive)) {
return;
}
comparedFragmentPairs.add(fragKey1, fragKey2, areMutuallyExclusive);
comparedFragmentPairs.add(fragmentName1, fragmentName2, areMutuallyExclusive);
const fragment1 = context.getFragment(fragmentName1);

@@ -353,15 +310,13 @@ const fragment2 = context.getFragment(fragmentName2);

const [fieldMap1, referencedFragmentSpreads1] =
getReferencedFieldsAndFragmentSpreads(
const [fieldMap1, referencedFragmentNames1] =
getReferencedFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
fragment1,
fragmentSpread1,
);
const [fieldMap2, referencedFragmentSpreads2] =
getReferencedFieldsAndFragmentSpreads(
const [fieldMap2, referencedFragmentNames2] =
getReferencedFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
fragment2,
fragmentSpread2,
); // (F) First, collect all conflicts between these two collections of fields

@@ -373,3 +328,3 @@ // (not including any nested fragments).

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -382,13 +337,11 @@ areMutuallyExclusive,

for (const [referencedFragmentSpread2] of Object.values(
referencedFragmentSpreads2,
)) {
for (const referencedFragmentName2 of referencedFragmentNames2) {
collectConflictsBetweenFragments(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fragmentSpread1,
referencedFragmentSpread2,
fragmentName1,
referencedFragmentName2,
);

@@ -398,13 +351,11 @@ } // (G) Then collect conflicts between the second fragment and any nested

for (const [referencedFragmentSpread1] of Object.values(
referencedFragmentSpreads1,
)) {
for (const referencedFragmentName1 of referencedFragmentNames1) {
collectConflictsBetweenFragments(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
referencedFragmentSpread1,
fragmentSpread2,
referencedFragmentName1,
fragmentName2,
);

@@ -418,3 +369,3 @@ }

context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -428,11 +379,11 @@ areMutuallyExclusive,

const conflicts = [];
const [fieldMap1, fragmentSpreadsByName1] = getFieldsAndFragmentSpreads(
const [fieldMap1, fragmentNames1] = getFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
parentType1,
selectionSet1,
);
const [fieldMap2, fragmentSpreadsByName2] = getFieldsAndFragmentSpreads(
const [fieldMap2, fragmentNames2] = getFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
parentType2,

@@ -445,3 +396,3 @@ selectionSet2,

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -454,11 +405,11 @@ areMutuallyExclusive,

for (const [fragmentSpread2] of Object.values(fragmentSpreadsByName2)) {
for (const fragmentName2 of fragmentNames2) {
collectConflictsBetweenFieldsAndFragment(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fieldMap1,
fragmentSpread2,
fragmentName2,
);

@@ -468,11 +419,11 @@ } // (I) Then collect conflicts between the second collection of fields and

for (const [fragmentSpread1] of Object.values(fragmentSpreadsByName1)) {
for (const fragmentName1 of fragmentNames1) {
collectConflictsBetweenFieldsAndFragment(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fieldMap2,
fragmentSpread1,
fragmentName1,
);

@@ -483,12 +434,12 @@ } // (J) Also collect conflicts between any fragment names by the first and

for (const [fragmentSpread1] of Object.values(fragmentSpreadsByName1)) {
for (const [fragmentSpread2] of Object.values(fragmentSpreadsByName2)) {
for (const fragmentName1 of fragmentNames1) {
for (const fragmentName2 of fragmentNames2) {
collectConflictsBetweenFragments(
context,
conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,
areMutuallyExclusive,
fragmentSpread1,
fragmentSpread2,
fragmentName1,
fragmentName2,
);

@@ -504,3 +455,3 @@ }

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -522,3 +473,3 @@ fieldMap,

context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -547,3 +498,3 @@ false, // within one collection is never mutually exclusive

conflicts,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -567,3 +518,3 @@ parentFieldsAreMutuallyExclusive,

context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -588,3 +539,3 @@ parentFieldsAreMutuallyExclusive,

context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -658,3 +609,3 @@ parentFieldsAreMutuallyExclusive,

context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
comparedFragmentPairs,

@@ -730,2 +681,12 @@ areMutuallyExclusive,

if ((0, _definition.isSemanticNonNullType)(type1)) {
return (0, _definition.isSemanticNonNullType)(type2)
? doTypesConflict(type1.ofType, type2.ofType)
: true;
}
if ((0, _definition.isSemanticNonNullType)(type2)) {
return true;
}
if (

@@ -743,9 +704,9 @@ (0, _definition.isLeafType)(type1) ||

function getFieldsAndFragmentSpreads(
function getFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
parentType,
selectionSet,
) {
const cached = cachedFieldsAndFragmentSpreads.get(selectionSet);
const cached = cachedFieldsAndFragmentNames.get(selectionSet);

@@ -757,3 +718,3 @@ if (cached) {

const nodeAndDefs = Object.create(null);
const fragmentSpreadsByName = Object.create(null);
const fragmentNames = Object.create(null);

@@ -765,7 +726,7 @@ _collectFieldsAndFragmentNames(

nodeAndDefs,
fragmentSpreadsByName,
fragmentNames,
);
const result = [nodeAndDefs, fragmentSpreadsByName];
cachedFieldsAndFragmentSpreads.set(selectionSet, result);
const result = [nodeAndDefs, Object.keys(fragmentNames)];
cachedFieldsAndFragmentNames.set(selectionSet, result);
return result;

@@ -775,27 +736,10 @@ } // Given a reference to a fragment, return the represented collection of fields

function getReferencedFieldsAndFragmentSpreads(
function getReferencedFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
fragment,
fragmentSpread,
) {
const args = fragmentSpread.arguments;
const fragmentSelectionSet = (0, _visitor.visit)(fragment.selectionSet, {
Variable: (node) => {
const name = node.name.value;
const argNode =
args === null || args === void 0
? void 0
: args.find((arg) => arg.name.value === name);
// Short-circuit building a type from the node if possible.
const cached = cachedFieldsAndFragmentNames.get(fragment.selectionSet);
if (argNode) {
return argNode.value;
}
return node;
},
}); // Short-circuit building a type from the node if possible.
const cached = cachedFieldsAndFragmentSpreads.get(fragmentSelectionSet);
if (cached) {

@@ -809,7 +753,7 @@ return cached;

);
return getFieldsAndFragmentSpreads(
return getFieldsAndFragmentNames(
context,
cachedFieldsAndFragmentSpreads,
cachedFieldsAndFragmentNames,
fragmentType,
fragmentSelectionSet,
fragment.selectionSet,
);

@@ -823,3 +767,3 @@ }

nodeAndDefs,
fragmentSpreadsByName,
fragmentNames,
) {

@@ -851,13 +795,5 @@ for (const selection of selectionSet.selections) {

case _kinds.Kind.FRAGMENT_SPREAD: {
const existing = fragmentSpreadsByName[selection.name.value];
if (existing) {
existing.push(selection);
} else {
fragmentSpreadsByName[selection.name.value] = [selection];
}
case _kinds.Kind.FRAGMENT_SPREAD:
fragmentNames[selection.name.value] = true;
break;
}

@@ -875,3 +811,3 @@ case _kinds.Kind.INLINE_FRAGMENT: {

nodeAndDefs,
fragmentSpreadsByName,
fragmentNames,
);

@@ -878,0 +814,0 @@

@@ -71,47 +71,2 @@ 'use strict';

},
FragmentSpread: {
// Validate on leave to allow for directive errors to appear first.
leave(spreadNode) {
var _spreadNode$arguments;
const fragmentDef = context.getFragment(spreadNode.name.value);
if (!fragmentDef) {
return false;
}
const providedArgs = new Set( // FIXME: https://github.com/graphql/graphql-js/issues/2203
/* c8 ignore next */
(_spreadNode$arguments = spreadNode.arguments) === null ||
_spreadNode$arguments === void 0
? void 0
: _spreadNode$arguments.map((arg) => arg.name.value),
); // FIXME: https://github.com/graphql/graphql-js/issues/2203
/* c8 ignore next */
for (const varDef of (_fragmentDef$variable =
fragmentDef.variableDefinitions) !== null &&
_fragmentDef$variable !== void 0
? _fragmentDef$variable
: []) {
var _fragmentDef$variable;
if (
!providedArgs.has(varDef.variable.name.value) &&
isRequiredArgumentNode(varDef)
) {
const argTypeStr = (0, _inspect.inspect)(varDef.type);
context.reportError(
new _GraphQLError.GraphQLError(
`Fragment "${spreadNode.name.value}" argument "${varDef.variable.name.value}" of type "${argTypeStr}" is required, but it was not provided.`,
{
nodes: [spreadNode, varDef],
},
),
);
}
}
},
},
};

@@ -118,0 +73,0 @@ }

@@ -59,3 +59,3 @@ 'use strict';

{
nodes: extraFieldSelections.map((entry) => entry.node),
nodes: extraFieldSelections,
},

@@ -68,3 +68,3 @@ ),

const field = fieldNodes[0];
const fieldName = field.node.name.value;
const fieldName = field.name.value;

@@ -78,3 +78,3 @@ if (fieldName.startsWith('__')) {

{
nodes: fieldNodes.map((entry) => entry.node),
nodes: fieldNodes,
},

@@ -81,0 +81,0 @@ ),

@@ -135,3 +135,3 @@ 'use strict';

);
}
} // Note: SemanticNonNull cannot happen on input.
},

@@ -138,0 +138,0 @@

@@ -38,8 +38,5 @@ 'use strict';

for (const { node, type, defaultValue, fragmentVarDef } of usages) {
for (const { node, type, defaultValue } of usages) {
const varName = node.name.value;
const varDef =
fragmentVarDef !== null && fragmentVarDef !== void 0
? fragmentVarDef
: varDefMap[varName];
const varDef = varDefMap[varName];

@@ -99,2 +96,3 @@ if (varDef && type) {

) {
// Note: SemanticNonNull cannot occur on input.
if (

@@ -101,0 +99,0 @@ (0, _definition.isNonNullType)(locationType) &&

@@ -37,4 +37,2 @@ 'use strict';

var _NoUnusedFragmentVariablesRule = require('./rules/NoUnusedFragmentVariablesRule.js');
var _NoUnusedVariablesRule = require('./rules/NoUnusedVariablesRule.js');

@@ -97,3 +95,2 @@

// Spec Section: "Fragments must be used"
// Spec Section: "All Fragment Variables Used"
// Spec Section: "All Variables Used"

@@ -149,3 +146,2 @@ // Spec Section: "Field Selection Merging"

_KnownDirectivesRule.KnownDirectivesRule,
_NoUnusedFragmentVariablesRule.NoUnusedFragmentVariablesRule,
_UniqueDirectivesPerLocationRule.UniqueDirectivesPerLocationRule,

@@ -152,0 +148,0 @@ _KnownArgumentNamesRule.KnownArgumentNamesRule,

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

SelectionSetNode,
VariableDefinitionNode,
VariableNode,

@@ -24,3 +23,3 @@ } from '../language/ast';

import type { GraphQLSchema } from '../type/schema';
import type { TypeInfo } from '../utilities/TypeInfo';
import { TypeInfo } from '../utilities/TypeInfo';
declare type NodeWithSelectionSet =

@@ -33,3 +32,2 @@ | OperationDefinitionNode

readonly defaultValue: Maybe<unknown>;
readonly fragmentVarDef: Maybe<VariableDefinitionNode>;
}

@@ -90,5 +88,2 @@ /**

): ReadonlyArray<VariableUsage>;
getOperationVariableUsages(
operation: OperationDefinitionNode,
): ReadonlyArray<VariableUsage>;
getType(): Maybe<GraphQLOutputType>;

@@ -95,0 +90,0 @@ getParentType(): Maybe<GraphQLCompositeType>;

@@ -160,7 +160,3 @@ 'use strict';

const newUsages = [];
const typeInfo = this._typeInfo;
const fragmentVariableDefinitions =
node.kind === _kinds.Kind.FRAGMENT_DEFINITION
? node.variableDefinitions
: undefined;
const typeInfo = new _TypeInfo.TypeInfo(this._schema);
(0, _visitor.visit)(

@@ -172,10 +168,2 @@ node,

Variable(variable) {
const fragmentVarDef =
fragmentVariableDefinitions === null ||
fragmentVariableDefinitions === void 0
? void 0
: fragmentVariableDefinitions.find(
(varDef) =>
varDef.variable.name.value === variable.name.value,
);
newUsages.push({

@@ -185,3 +173,2 @@ node: variable,

defaultValue: typeInfo.getDefaultValue(),
fragmentVarDef,
});

@@ -215,18 +202,2 @@ },

getOperationVariableUsages(operation) {
let usages = this._recursiveVariableUsages.get(operation);
if (!usages) {
usages = this.getVariableUsages(operation);
for (const frag of this.getRecursivelyReferencedFragments(operation)) {
usages = usages.concat(this.getVariableUsages(frag));
}
this._recursiveVariableUsages.set(operation, usages);
}
return usages.filter(({ fragmentVarDef }) => !fragmentVarDef);
}
getType() {

@@ -233,0 +204,0 @@ return this._typeInfo.getType();

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

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

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

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

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

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

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

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

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

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