Skip to content

Commit

Permalink
coverage: ignore uncovered branches caused by graphql#2203
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jan 4, 2020
1 parent 0043a7d commit 21c08f8
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 144 deletions.
5 changes: 4 additions & 1 deletion src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ export function buildExecutionContext(
return [new GraphQLError('Must provide an operation.')];
}

/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const variableDefinitions = operation.variableDefinitions || [];

const coercedVariableValues = getVariableValues(
schema,
operation.variableDefinitions || [],
variableDefinitions,
rawVariableValues || {},
{ maxErrors: 50 },
);
Expand Down
5 changes: 4 additions & 1 deletion src/execution/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export function getArgumentValues(
variableValues?: ?ObjMap<mixed>,
): { [argument: string]: mixed, ... } {
const coercedValues = {};
const argNodeMap = keyMap(node.arguments || [], arg => arg.name.value);

/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const argumentNodes = node.arguments || [];
const argNodeMap = keyMap(argumentNodes, arg => arg.name.value);

for (const argDef of def.args) {
const name = argDef.name;
Expand Down
1 change: 1 addition & 0 deletions src/type/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
object: SDLDefinedObject<T, K>,
getter: (T | K) => ?(L | $ReadOnlyArray<L>),
): $ReadOnlyArray<L> {
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
return flatMap(getAllNodes(object), item => getter(item) || []);
}

Expand Down
145 changes: 76 additions & 69 deletions src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,11 @@ export function extendSchemaImpl(
// validation with validateSchema() will produce more actionable results.
const opTypes: any = {};
for (const node of nodes) {
if (node.operationTypes != null) {
for (const operationType of node.operationTypes) {
opTypes[operationType.operation] = getNamedType(operationType.type);
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const operationTypesNodes = node.operationTypes || [];

for (const operationType of operationTypesNodes) {
opTypes[operationType.operation] = getNamedType(operationType.type);
}
}
return opTypes;
Expand Down Expand Up @@ -487,19 +488,20 @@ export function extendSchemaImpl(
): GraphQLFieldConfigMap<mixed, mixed> {
const fieldConfigMap = Object.create(null);
for (const node of nodes) {
if (node.fields != null) {
for (const field of node.fields) {
fieldConfigMap[field.name.value] = {
// Note: While this could make assertions to get the correctly typed
// value, that would throw immediately while type system validation
// with validateSchema() will produce more actionable results.
type: (getWrappedType(field.type): any),
description: getDescription(field, options),
args: buildArgumentMap(field.arguments),
deprecationReason: getDeprecationReason(field),
astNode: field,
};
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const nodeFields = node.fields || [];

for (const field of nodeFields) {
fieldConfigMap[field.name.value] = {
// Note: While this could make assertions to get the correctly typed
// value, that would throw immediately while type system validation
// with validateSchema() will produce more actionable results.
type: (getWrappedType(field.type): any),
description: getDescription(field, options),
args: buildArgumentMap(field.arguments),
deprecationReason: getDeprecationReason(field),
astNode: field,
};
}
}
return fieldConfigMap;
Expand All @@ -508,21 +510,22 @@ export function extendSchemaImpl(
function buildArgumentMap(
args: ?$ReadOnlyArray<InputValueDefinitionNode>,
): GraphQLFieldConfigArgumentMap {
const argConfigMap = Object.create(null);
if (args != null) {
for (const arg of args) {
// Note: While this could make assertions to get the correctly typed
// value, that would throw immediately while type system validation
// with validateSchema() will produce more actionable results.
const type: any = getWrappedType(arg.type);
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const argsNodes = args || [];

argConfigMap[arg.name.value] = {
type,
description: getDescription(arg, options),
defaultValue: valueFromAST(arg.defaultValue, type),
astNode: arg,
};
}
const argConfigMap = Object.create(null);
for (const arg of argsNodes) {
// Note: While this could make assertions to get the correctly typed
// value, that would throw immediately while type system validation
// with validateSchema() will produce more actionable results.
const type: any = getWrappedType(arg.type);

argConfigMap[arg.name.value] = {
type,
description: getDescription(arg, options),
defaultValue: valueFromAST(arg.defaultValue, type),
astNode: arg,
};
}
return argConfigMap;
}
Expand All @@ -534,20 +537,21 @@ export function extendSchemaImpl(
): GraphQLInputFieldConfigMap {
const inputFieldMap = Object.create(null);
for (const node of nodes) {
if (node.fields != null) {
for (const field of node.fields) {
// Note: While this could make assertions to get the correctly typed
// value, that would throw immediately while type system validation
// with validateSchema() will produce more actionable results.
const type: any = getWrappedType(field.type);

inputFieldMap[field.name.value] = {
type,
description: getDescription(field, options),
defaultValue: valueFromAST(field.defaultValue, type),
astNode: field,
};
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const fieldsNodes = node.fields || [];

for (const field of fieldsNodes) {
// Note: While this could make assertions to get the correctly typed
// value, that would throw immediately while type system validation
// with validateSchema() will produce more actionable results.
const type: any = getWrappedType(field.type);

inputFieldMap[field.name.value] = {
type,
description: getDescription(field, options),
defaultValue: valueFromAST(field.defaultValue, type),
astNode: field,
};
}
}
return inputFieldMap;
Expand All @@ -558,14 +562,15 @@ export function extendSchemaImpl(
): GraphQLEnumValueConfigMap {
const enumValueMap = Object.create(null);
for (const node of nodes) {
if (node.values != null) {
for (const value of node.values) {
enumValueMap[value.name.value] = {
description: getDescription(value, options),
deprecationReason: getDeprecationReason(value),
astNode: value,
};
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const valuesNodes = node.values || [];

for (const value of valuesNodes) {
enumValueMap[value.name.value] = {
description: getDescription(value, options),
deprecationReason: getDeprecationReason(value),
astNode: value,
};
}
}
return enumValueMap;
Expand All @@ -581,14 +586,15 @@ export function extendSchemaImpl(
): Array<GraphQLInterfaceType> {
const interfaces = [];
for (const node of nodes) {
if (node.interfaces != null) {
for (const type of node.interfaces) {
// Note: While this could make assertions to get the correctly typed
// values below, that would throw immediately while type system
// validation with validateSchema() will produce more actionable
// results.
interfaces.push((getNamedType(type): any));
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const interfacesNodes = node.interfaces || [];

for (const type of interfacesNodes) {
// Note: While this could make assertions to get the correctly typed
// values below, that would throw immediately while type system
// validation with validateSchema() will produce more actionable
// results.
interfaces.push((getNamedType(type): any));
}
}
return interfaces;
Expand All @@ -599,14 +605,15 @@ export function extendSchemaImpl(
): Array<GraphQLObjectType> {
const types = [];
for (const node of nodes) {
if (node.types != null) {
for (const type of node.types) {
// Note: While this could make assertions to get the correctly typed
// values below, that would throw immediately while type system
// validation with validateSchema() will produce more actionable
// results.
types.push((getNamedType(type): any));
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const typeNodes = node.types || [];

for (const type of typeNodes) {
// Note: While this could make assertions to get the correctly typed
// values below, that would throw immediately while type system
// validation with validateSchema() will produce more actionable
// results.
types.push((getNamedType(type): any));
}
}
return types;
Expand Down
7 changes: 4 additions & 3 deletions src/validation/rules/KnownArgumentNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ export function KnownArgumentNamesOnDirectives(
const astDefinitions = context.getDocument().definitions;
for (const def of astDefinitions) {
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
directiveArgs[def.name.value] = def.arguments
? def.arguments.map(arg => arg.name.value)
: [];
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const argsNodes = def.arguments || [];

directiveArgs[def.name.value] = argsNodes.map(arg => arg.name.value);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/validation/rules/OverlappingFieldsCanBeMerged.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,12 @@ function findConflict(
];
}

/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const args1 = node1.arguments || [];
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const args2 = node2.arguments || [];
// Two field calls must have the same arguments.
if (!sameArguments(node1.arguments || [], node2.arguments || [])) {
if (!sameArguments(args1, args2)) {
return [
[responseName, 'they have differing arguments'],
[node1],
Expand Down
9 changes: 7 additions & 2 deletions src/validation/rules/ProvidedRequiredArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export function ProvidedRequiredArguments(
if (!fieldDef) {
return false;
}
const argNodes = fieldNode.arguments || [];

/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const argNodes = fieldNode.arguments || [];
const argNodeMap = keyMap(argNodes, arg => arg.name.value);
for (const argDef of fieldDef.args) {
const argNode = argNodeMap[argDef.name];
Expand Down Expand Up @@ -77,8 +78,11 @@ export function ProvidedRequiredArgumentsOnDirectives(
const astDefinitions = context.getDocument().definitions;
for (const def of astDefinitions) {
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const argNodes = def.arguments || [];

requiredArgsMap[def.name.value] = keyMap(
def.arguments ? def.arguments.filter(isRequiredArgumentNode) : [],
argNodes.filter(isRequiredArgumentNode),
arg => arg.name.value,
);
}
Expand All @@ -91,6 +95,7 @@ export function ProvidedRequiredArgumentsOnDirectives(
const directiveName = directiveNode.name.value;
const requiredArgs = requiredArgsMap[directiveName];
if (requiredArgs) {
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const argNodes = directiveNode.arguments || [];
const argNodeMap = keyMap(argNodes, arg => arg.name.value);
for (const argName of Object.keys(requiredArgs)) {
Expand Down
48 changes: 24 additions & 24 deletions src/validation/rules/UniqueEnumValueNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ export function UniqueEnumValueNames(
knownValueNames[typeName] = Object.create(null);
}

if (node.values) {
const valueNames = knownValueNames[typeName];

for (const valueDef of node.values) {
const valueName = valueDef.name.value;

const existingType = existingTypeMap[typeName];
if (isEnumType(existingType) && existingType.getValue(valueName)) {
context.reportError(
new GraphQLError(
`Enum value "${typeName}.${valueName}" already exists in the schema. It cannot also be defined in this type extension.`,
valueDef.name,
),
);
} else if (valueNames[valueName]) {
context.reportError(
new GraphQLError(
`Enum value "${typeName}.${valueName}" can only be defined once.`,
[valueNames[valueName], valueDef.name],
),
);
} else {
valueNames[valueName] = valueDef.name;
}
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
const valueNodes = node.values || [];
const valueNames = knownValueNames[typeName];

for (const valueDef of valueNodes) {
const valueName = valueDef.name.value;

const existingType = existingTypeMap[typeName];
if (isEnumType(existingType) && existingType.getValue(valueName)) {
context.reportError(
new GraphQLError(
`Enum value "${typeName}.${valueName}" already exists in the schema. It cannot also be defined in this type extension.`,
valueDef.name,
),
);
} else if (valueNames[valueName]) {
context.reportError(
new GraphQLError(
`Enum value "${typeName}.${valueName}" can only be defined once.`,
[valueNames[valueName], valueDef.name],
),
);
} else {
valueNames[valueName] = valueDef.name;
}
}

Expand Down
42 changes: 21 additions & 21 deletions src/validation/rules/UniqueFieldDefinitionNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ export function UniqueFieldDefinitionNames(
knownFieldNames[typeName] = Object.create(null);
}

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

for (const fieldDef of node.fields) {
const fieldName = fieldDef.name.value;
for (const fieldDef of fieldNodes) {
const fieldName = fieldDef.name.value;

if (hasField(existingTypeMap[typeName], fieldName)) {
context.reportError(
new GraphQLError(
`Field "${typeName}.${fieldName}" already exists in the schema. It cannot also be defined in this type extension.`,
fieldDef.name,
),
);
} else if (fieldNames[fieldName]) {
context.reportError(
new GraphQLError(
`Field "${typeName}.${fieldName}" can only be defined once.`,
[fieldNames[fieldName], fieldDef.name],
),
);
} else {
fieldNames[fieldName] = fieldDef.name;
}
if (hasField(existingTypeMap[typeName], fieldName)) {
context.reportError(
new GraphQLError(
`Field "${typeName}.${fieldName}" already exists in the schema. It cannot also be defined in this type extension.`,
fieldDef.name,
),
);
} else if (fieldNames[fieldName]) {
context.reportError(
new GraphQLError(
`Field "${typeName}.${fieldName}" can only be defined once.`,
[fieldNames[fieldName], fieldDef.name],
),
);
} else {
fieldNames[fieldName] = fieldDef.name;
}
}

Expand Down
Loading

0 comments on commit 21c08f8

Please sign in to comment.