Skip to content

Commit e590dd2

Browse files
committed
coverage: ignore uncovered branches caused by #2203
1 parent 635a13c commit e590dd2

File tree

10 files changed

+169
-144
lines changed

10 files changed

+169
-144
lines changed

src/execution/execute.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,12 @@ export function buildExecutionContext(
312312
return [new GraphQLError('Must provide an operation.')];
313313
}
314314

315+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
316+
const variableDefinitions = operation.variableDefinitions || [];
317+
315318
const coercedVariableValues = getVariableValues(
316319
schema,
317-
operation.variableDefinitions || [],
320+
variableDefinitions,
318321
rawVariableValues || {},
319322
{ maxErrors: 50 },
320323
);

src/execution/values.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ export function getArgumentValues(
164164
variableValues?: ?ObjMap<mixed>,
165165
): { [argument: string]: mixed, ... } {
166166
const coercedValues = {};
167-
const argNodeMap = keyMap(node.arguments || [], arg => arg.name.value);
167+
168+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
169+
const argumentNodes = node.arguments || [];
170+
const argNodeMap = keyMap(argumentNodes, arg => arg.name.value);
168171

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

src/type/validate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
591591
object: SDLDefinedObject<T, K>,
592592
getter: (T | K) => ?(L | $ReadOnlyArray<L>),
593593
): $ReadOnlyArray<L> {
594+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
594595
return flatMap(getAllNodes(object), item => getter(item) || []);
595596
}
596597

src/utilities/extendSchema.js

Lines changed: 76 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,11 @@ export function extendSchemaImpl(
433433
// validation with validateSchema() will produce more actionable results.
434434
const opTypes: any = {};
435435
for (const node of nodes) {
436-
if (node.operationTypes != null) {
437-
for (const operationType of node.operationTypes) {
438-
opTypes[operationType.operation] = getNamedType(operationType.type);
439-
}
436+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
437+
const operationTypesNodes = node.operationTypes || [];
438+
439+
for (const operationType of operationTypesNodes) {
440+
opTypes[operationType.operation] = getNamedType(operationType.type);
440441
}
441442
}
442443
return opTypes;
@@ -487,19 +488,20 @@ export function extendSchemaImpl(
487488
): GraphQLFieldConfigMap<mixed, mixed> {
488489
const fieldConfigMap = Object.create(null);
489490
for (const node of nodes) {
490-
if (node.fields != null) {
491-
for (const field of node.fields) {
492-
fieldConfigMap[field.name.value] = {
493-
// Note: While this could make assertions to get the correctly typed
494-
// value, that would throw immediately while type system validation
495-
// with validateSchema() will produce more actionable results.
496-
type: (getWrappedType(field.type): any),
497-
description: getDescription(field, options),
498-
args: buildArgumentMap(field.arguments),
499-
deprecationReason: getDeprecationReason(field),
500-
astNode: field,
501-
};
502-
}
491+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
492+
const nodeFields = node.fields || [];
493+
494+
for (const field of nodeFields) {
495+
fieldConfigMap[field.name.value] = {
496+
// Note: While this could make assertions to get the correctly typed
497+
// value, that would throw immediately while type system validation
498+
// with validateSchema() will produce more actionable results.
499+
type: (getWrappedType(field.type): any),
500+
description: getDescription(field, options),
501+
args: buildArgumentMap(field.arguments),
502+
deprecationReason: getDeprecationReason(field),
503+
astNode: field,
504+
};
503505
}
504506
}
505507
return fieldConfigMap;
@@ -508,21 +510,22 @@ export function extendSchemaImpl(
508510
function buildArgumentMap(
509511
args: ?$ReadOnlyArray<InputValueDefinitionNode>,
510512
): GraphQLFieldConfigArgumentMap {
511-
const argConfigMap = Object.create(null);
512-
if (args != null) {
513-
for (const arg of args) {
514-
// Note: While this could make assertions to get the correctly typed
515-
// value, that would throw immediately while type system validation
516-
// with validateSchema() will produce more actionable results.
517-
const type: any = getWrappedType(arg.type);
513+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
514+
const argsNodes = args || [];
518515

519-
argConfigMap[arg.name.value] = {
520-
type,
521-
description: getDescription(arg, options),
522-
defaultValue: valueFromAST(arg.defaultValue, type),
523-
astNode: arg,
524-
};
525-
}
516+
const argConfigMap = Object.create(null);
517+
for (const arg of argsNodes) {
518+
// Note: While this could make assertions to get the correctly typed
519+
// value, that would throw immediately while type system validation
520+
// with validateSchema() will produce more actionable results.
521+
const type: any = getWrappedType(arg.type);
522+
523+
argConfigMap[arg.name.value] = {
524+
type,
525+
description: getDescription(arg, options),
526+
defaultValue: valueFromAST(arg.defaultValue, type),
527+
astNode: arg,
528+
};
526529
}
527530
return argConfigMap;
528531
}
@@ -534,20 +537,21 @@ export function extendSchemaImpl(
534537
): GraphQLInputFieldConfigMap {
535538
const inputFieldMap = Object.create(null);
536539
for (const node of nodes) {
537-
if (node.fields != null) {
538-
for (const field of node.fields) {
539-
// Note: While this could make assertions to get the correctly typed
540-
// value, that would throw immediately while type system validation
541-
// with validateSchema() will produce more actionable results.
542-
const type: any = getWrappedType(field.type);
543-
544-
inputFieldMap[field.name.value] = {
545-
type,
546-
description: getDescription(field, options),
547-
defaultValue: valueFromAST(field.defaultValue, type),
548-
astNode: field,
549-
};
550-
}
540+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
541+
const fieldsNodes = node.fields || [];
542+
543+
for (const field of fieldsNodes) {
544+
// Note: While this could make assertions to get the correctly typed
545+
// value, that would throw immediately while type system validation
546+
// with validateSchema() will produce more actionable results.
547+
const type: any = getWrappedType(field.type);
548+
549+
inputFieldMap[field.name.value] = {
550+
type,
551+
description: getDescription(field, options),
552+
defaultValue: valueFromAST(field.defaultValue, type),
553+
astNode: field,
554+
};
551555
}
552556
}
553557
return inputFieldMap;
@@ -558,14 +562,15 @@ export function extendSchemaImpl(
558562
): GraphQLEnumValueConfigMap {
559563
const enumValueMap = Object.create(null);
560564
for (const node of nodes) {
561-
if (node.values != null) {
562-
for (const value of node.values) {
563-
enumValueMap[value.name.value] = {
564-
description: getDescription(value, options),
565-
deprecationReason: getDeprecationReason(value),
566-
astNode: value,
567-
};
568-
}
565+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
566+
const valuesNodes = node.values || [];
567+
568+
for (const value of valuesNodes) {
569+
enumValueMap[value.name.value] = {
570+
description: getDescription(value, options),
571+
deprecationReason: getDeprecationReason(value),
572+
astNode: value,
573+
};
569574
}
570575
}
571576
return enumValueMap;
@@ -581,14 +586,15 @@ export function extendSchemaImpl(
581586
): Array<GraphQLInterfaceType> {
582587
const interfaces = [];
583588
for (const node of nodes) {
584-
if (node.interfaces != null) {
585-
for (const type of node.interfaces) {
586-
// Note: While this could make assertions to get the correctly typed
587-
// values below, that would throw immediately while type system
588-
// validation with validateSchema() will produce more actionable
589-
// results.
590-
interfaces.push((getNamedType(type): any));
591-
}
589+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
590+
const interfacesNodes = node.interfaces || [];
591+
592+
for (const type of interfacesNodes) {
593+
// Note: While this could make assertions to get the correctly typed
594+
// values below, that would throw immediately while type system
595+
// validation with validateSchema() will produce more actionable
596+
// results.
597+
interfaces.push((getNamedType(type): any));
592598
}
593599
}
594600
return interfaces;
@@ -599,14 +605,15 @@ export function extendSchemaImpl(
599605
): Array<GraphQLObjectType> {
600606
const types = [];
601607
for (const node of nodes) {
602-
if (node.types != null) {
603-
for (const type of node.types) {
604-
// Note: While this could make assertions to get the correctly typed
605-
// values below, that would throw immediately while type system
606-
// validation with validateSchema() will produce more actionable
607-
// results.
608-
types.push((getNamedType(type): any));
609-
}
608+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
609+
const typeNodes = node.types || [];
610+
611+
for (const type of typeNodes) {
612+
// Note: While this could make assertions to get the correctly typed
613+
// values below, that would throw immediately while type system
614+
// validation with validateSchema() will produce more actionable
615+
// results.
616+
types.push((getNamedType(type): any));
610617
}
611618
}
612619
return types;

src/validation/rules/KnownArgumentNames.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ export function KnownArgumentNamesOnDirectives(
6464
const astDefinitions = context.getDocument().definitions;
6565
for (const def of astDefinitions) {
6666
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
67-
directiveArgs[def.name.value] = def.arguments
68-
? def.arguments.map(arg => arg.name.value)
69-
: [];
67+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
68+
const argsNodes = def.arguments || [];
69+
70+
directiveArgs[def.name.value] = argsNodes.map(arg => arg.name.value);
7071
}
7172
}
7273

src/validation/rules/OverlappingFieldsCanBeMerged.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,12 @@ function findConflict(
589589
];
590590
}
591591

592+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
593+
const args1 = node1.arguments || [];
594+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
595+
const args2 = node2.arguments || [];
592596
// Two field calls must have the same arguments.
593-
if (!sameArguments(node1.arguments || [], node2.arguments || [])) {
597+
if (!sameArguments(args1, args2)) {
594598
return [
595599
[responseName, 'they have differing arguments'],
596600
[node1],

src/validation/rules/ProvidedRequiredArguments.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export function ProvidedRequiredArguments(
3535
if (!fieldDef) {
3636
return false;
3737
}
38-
const argNodes = fieldNode.arguments || [];
3938

39+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
40+
const argNodes = fieldNode.arguments || [];
4041
const argNodeMap = keyMap(argNodes, arg => arg.name.value);
4142
for (const argDef of fieldDef.args) {
4243
const argNode = argNodeMap[argDef.name];
@@ -77,8 +78,11 @@ export function ProvidedRequiredArgumentsOnDirectives(
7778
const astDefinitions = context.getDocument().definitions;
7879
for (const def of astDefinitions) {
7980
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
81+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
82+
const argNodes = def.arguments || [];
83+
8084
requiredArgsMap[def.name.value] = keyMap(
81-
def.arguments ? def.arguments.filter(isRequiredArgumentNode) : [],
85+
argNodes.filter(isRequiredArgumentNode),
8286
arg => arg.name.value,
8387
);
8488
}
@@ -91,6 +95,7 @@ export function ProvidedRequiredArgumentsOnDirectives(
9195
const directiveName = directiveNode.name.value;
9296
const requiredArgs = requiredArgsMap[directiveName];
9397
if (requiredArgs) {
98+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
9499
const argNodes = directiveNode.arguments || [];
95100
const argNodeMap = keyMap(argNodes, arg => arg.name.value);
96101
for (const argName of Object.keys(requiredArgs)) {

src/validation/rules/UniqueEnumValueNames.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ export function UniqueEnumValueNames(
3030
knownValueNames[typeName] = Object.create(null);
3131
}
3232

33-
if (node.values) {
34-
const valueNames = knownValueNames[typeName];
35-
36-
for (const valueDef of node.values) {
37-
const valueName = valueDef.name.value;
38-
39-
const existingType = existingTypeMap[typeName];
40-
if (isEnumType(existingType) && existingType.getValue(valueName)) {
41-
context.reportError(
42-
new GraphQLError(
43-
`Enum value "${typeName}.${valueName}" already exists in the schema. It cannot also be defined in this type extension.`,
44-
valueDef.name,
45-
),
46-
);
47-
} else if (valueNames[valueName]) {
48-
context.reportError(
49-
new GraphQLError(
50-
`Enum value "${typeName}.${valueName}" can only be defined once.`,
51-
[valueNames[valueName], valueDef.name],
52-
),
53-
);
54-
} else {
55-
valueNames[valueName] = valueDef.name;
56-
}
33+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
34+
const valueNodes = node.values || [];
35+
const valueNames = knownValueNames[typeName];
36+
37+
for (const valueDef of valueNodes) {
38+
const valueName = valueDef.name.value;
39+
40+
const existingType = existingTypeMap[typeName];
41+
if (isEnumType(existingType) && existingType.getValue(valueName)) {
42+
context.reportError(
43+
new GraphQLError(
44+
`Enum value "${typeName}.${valueName}" already exists in the schema. It cannot also be defined in this type extension.`,
45+
valueDef.name,
46+
),
47+
);
48+
} else if (valueNames[valueName]) {
49+
context.reportError(
50+
new GraphQLError(
51+
`Enum value "${typeName}.${valueName}" can only be defined once.`,
52+
[valueNames[valueName], valueDef.name],
53+
),
54+
);
55+
} else {
56+
valueNames[valueName] = valueDef.name;
5757
}
5858
}
5959

src/validation/rules/UniqueFieldDefinitionNames.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ export function UniqueFieldDefinitionNames(
3838
knownFieldNames[typeName] = Object.create(null);
3939
}
4040

41-
if (node.fields) {
42-
const fieldNames = knownFieldNames[typeName];
41+
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
42+
const fieldNodes = node.fields || [];
43+
const fieldNames = knownFieldNames[typeName];
4344

44-
for (const fieldDef of node.fields) {
45-
const fieldName = fieldDef.name.value;
45+
for (const fieldDef of fieldNodes) {
46+
const fieldName = fieldDef.name.value;
4647

47-
if (hasField(existingTypeMap[typeName], fieldName)) {
48-
context.reportError(
49-
new GraphQLError(
50-
`Field "${typeName}.${fieldName}" already exists in the schema. It cannot also be defined in this type extension.`,
51-
fieldDef.name,
52-
),
53-
);
54-
} else if (fieldNames[fieldName]) {
55-
context.reportError(
56-
new GraphQLError(
57-
`Field "${typeName}.${fieldName}" can only be defined once.`,
58-
[fieldNames[fieldName], fieldDef.name],
59-
),
60-
);
61-
} else {
62-
fieldNames[fieldName] = fieldDef.name;
63-
}
48+
if (hasField(existingTypeMap[typeName], fieldName)) {
49+
context.reportError(
50+
new GraphQLError(
51+
`Field "${typeName}.${fieldName}" already exists in the schema. It cannot also be defined in this type extension.`,
52+
fieldDef.name,
53+
),
54+
);
55+
} else if (fieldNames[fieldName]) {
56+
context.reportError(
57+
new GraphQLError(
58+
`Field "${typeName}.${fieldName}" can only be defined once.`,
59+
[fieldNames[fieldName], fieldDef.name],
60+
),
61+
);
62+
} else {
63+
fieldNames[fieldName] = fieldDef.name;
6464
}
6565
}
6666

0 commit comments

Comments
 (0)