diff --git a/.eslintrc.yml b/.eslintrc.yml index 0334c49211..496ee220c2 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -112,8 +112,7 @@ rules: max-classes-per-file: off no-alert: error no-caller: error - # TODO: recommended rule but disable due to errors in existing code - # no-case-declarations: error + no-case-declarations: error no-div-regex: error no-else-return: error no-empty-function: off # TODO diff --git a/src/execution/execute.js b/src/execution/execute.js index 113bf9bfd2..61e6dee709 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -528,7 +528,7 @@ export function collectFields( for (let i = 0; i < selectionSet.selections.length; i++) { const selection = selectionSet.selections[i]; switch (selection.kind) { - case Kind.FIELD: + case Kind.FIELD: { if (!shouldIncludeNode(exeContext, selection)) { continue; } @@ -538,7 +538,8 @@ export function collectFields( } fields[name].push(selection); break; - case Kind.INLINE_FRAGMENT: + } + case Kind.INLINE_FRAGMENT: { if ( !shouldIncludeNode(exeContext, selection) || !doesFragmentConditionMatch(exeContext, selection, runtimeType) @@ -553,7 +554,8 @@ export function collectFields( visitedFragmentNames, ); break; - case Kind.FRAGMENT_SPREAD: + } + case Kind.FRAGMENT_SPREAD: { const fragName = selection.name.value; if ( visitedFragmentNames[fragName] || @@ -577,6 +579,7 @@ export function collectFields( visitedFragmentNames, ); break; + } } } return fields; diff --git a/src/language/lexer.js b/src/language/lexer.js index 780233e051..aee0e73cd9 100644 --- a/src/language/lexer.js +++ b/src/language/lexer.js @@ -597,7 +597,8 @@ function readString(source, start, line, col, prev): Token { case 116: value += '\t'; break; - case 117: // u + case 117: { + // uXXXX const charCode = uniCharCode( body.charCodeAt(position + 1), body.charCodeAt(position + 2), @@ -615,6 +616,7 @@ function readString(source, start, line, col, prev): Token { value += String.fromCharCode(charCode); position += 4; break; + } default: throw syntaxError( source, diff --git a/src/utilities/TypeInfo.js b/src/utilities/TypeInfo.js index a74d52725b..95df418c06 100644 --- a/src/utilities/TypeInfo.js +++ b/src/utilities/TypeInfo.js @@ -144,13 +144,14 @@ export class TypeInfo { // checked before continuing since TypeInfo is used as part of validation // which occurs before guarantees of schema and document validity. switch (node.kind) { - case Kind.SELECTION_SET: + case Kind.SELECTION_SET: { const namedType: mixed = getNamedType(this.getType()); this._parentTypeStack.push( isCompositeType(namedType) ? namedType : undefined, ); break; - case Kind.FIELD: + } + case Kind.FIELD: { const parentType = this.getParentType(); let fieldDef; let fieldType: mixed; @@ -163,10 +164,11 @@ export class TypeInfo { this._fieldDefStack.push(fieldDef); this._typeStack.push(isOutputType(fieldType) ? fieldType : undefined); break; + } case Kind.DIRECTIVE: this._directive = schema.getDirective(node.name.value); break; - case Kind.OPERATION_DEFINITION: + case Kind.OPERATION_DEFINITION: { let type: mixed; if (node.operation === 'query') { type = schema.getQueryType(); @@ -177,21 +179,24 @@ export class TypeInfo { } this._typeStack.push(isObjectType(type) ? type : undefined); break; + } case Kind.INLINE_FRAGMENT: - case Kind.FRAGMENT_DEFINITION: + case Kind.FRAGMENT_DEFINITION: { const typeConditionAST = node.typeCondition; const outputType: mixed = typeConditionAST ? typeFromAST(schema, typeConditionAST) : getNamedType(this.getType()); this._typeStack.push(isOutputType(outputType) ? outputType : undefined); break; - case Kind.VARIABLE_DEFINITION: + } + case Kind.VARIABLE_DEFINITION: { const inputType: mixed = typeFromAST(schema, node.type); this._inputTypeStack.push( isInputType(inputType) ? inputType : undefined, ); break; - case Kind.ARGUMENT: + } + case Kind.ARGUMENT: { let argDef; let argType: mixed; const fieldOrDirective = this.getDirective() || this.getFieldDef(); @@ -208,7 +213,8 @@ export class TypeInfo { this._defaultValueStack.push(argDef ? argDef.defaultValue : undefined); this._inputTypeStack.push(isInputType(argType) ? argType : undefined); break; - case Kind.LIST: + } + case Kind.LIST: { const listType: mixed = getNullableType(this.getInputType()); const itemType: mixed = isListType(listType) ? listType.ofType @@ -217,7 +223,8 @@ export class TypeInfo { this._defaultValueStack.push(undefined); this._inputTypeStack.push(isInputType(itemType) ? itemType : undefined); break; - case Kind.OBJECT_FIELD: + } + case Kind.OBJECT_FIELD: { const objectType: mixed = getNamedType(this.getInputType()); let inputFieldType: GraphQLInputType | void; let inputField: GraphQLInputField | void; @@ -234,7 +241,8 @@ export class TypeInfo { isInputType(inputFieldType) ? inputFieldType : undefined, ); break; - case Kind.ENUM: + } + case Kind.ENUM: { const enumType: mixed = getNamedType(this.getInputType()); let enumValue; if (isEnumType(enumType)) { @@ -242,6 +250,7 @@ export class TypeInfo { } this._enumValue = enumValue; break; + } } } diff --git a/src/utilities/getOperationRootType.js b/src/utilities/getOperationRootType.js index 06690f857d..d6b4cf0017 100644 --- a/src/utilities/getOperationRootType.js +++ b/src/utilities/getOperationRootType.js @@ -22,38 +22,41 @@ export function getOperationRootType( schema: GraphQLSchema, operation: OperationDefinitionNode | OperationTypeDefinitionNode, ): GraphQLObjectType { - switch (operation.operation) { - case 'query': - const queryType = schema.getQueryType(); - if (!queryType) { - throw new GraphQLError( - 'Schema does not define the required query root type.', - operation, - ); - } - return queryType; - case 'mutation': - const mutationType = schema.getMutationType(); - if (!mutationType) { - throw new GraphQLError( - 'Schema is not configured for mutations.', - operation, - ); - } - return mutationType; - case 'subscription': - const subscriptionType = schema.getSubscriptionType(); - if (!subscriptionType) { - throw new GraphQLError( - 'Schema is not configured for subscriptions.', - operation, - ); - } - return subscriptionType; - default: + if (operation.operation === 'query') { + const queryType = schema.getQueryType(); + if (!queryType) { throw new GraphQLError( - 'Can only have query, mutation and subscription operations.', + 'Schema does not define the required query root type.', operation, ); + } + return queryType; } + + if (operation.operation === 'mutation') { + const mutationType = schema.getMutationType(); + if (!mutationType) { + throw new GraphQLError( + 'Schema is not configured for mutations.', + operation, + ); + } + return mutationType; + } + + if (operation.operation === 'subscription') { + const subscriptionType = schema.getSubscriptionType(); + if (!subscriptionType) { + throw new GraphQLError( + 'Schema is not configured for subscriptions.', + operation, + ); + } + return subscriptionType; + } + + throw new GraphQLError( + 'Can only have query, mutation and subscription operations.', + operation, + ); } diff --git a/src/utilities/valueFromASTUntyped.js b/src/utilities/valueFromASTUntyped.js index 0758581254..4fe85b91b9 100644 --- a/src/utilities/valueFromASTUntyped.js +++ b/src/utilities/valueFromASTUntyped.js @@ -53,11 +53,12 @@ export function valueFromASTUntyped( field => field.name.value, field => valueFromASTUntyped(field.value, variables), ); - case Kind.VARIABLE: + case Kind.VARIABLE: { const variableName = valueNode.name.value; return variables && !isInvalid(variables[variableName]) ? variables[variableName] : undefined; + } } // Not reachable. All possible value nodes have been considered. diff --git a/src/validation/rules/KnownDirectives.js b/src/validation/rules/KnownDirectives.js index b2f0253b8f..cebf684920 100644 --- a/src/validation/rules/KnownDirectives.js +++ b/src/validation/rules/KnownDirectives.js @@ -127,11 +127,12 @@ function getDirectiveLocationForASTPath(ancestors) { case Kind.INPUT_OBJECT_TYPE_DEFINITION: case Kind.INPUT_OBJECT_TYPE_EXTENSION: return DirectiveLocation.INPUT_OBJECT; - case Kind.INPUT_VALUE_DEFINITION: + case Kind.INPUT_VALUE_DEFINITION: { const parentNode = ancestors[ancestors.length - 3]; return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION; + } } } } diff --git a/src/validation/rules/OverlappingFieldsCanBeMerged.js b/src/validation/rules/OverlappingFieldsCanBeMerged.js index 30ac039fae..dcf6407dfe 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMerged.js +++ b/src/validation/rules/OverlappingFieldsCanBeMerged.js @@ -747,7 +747,7 @@ function _collectFieldsAndFragmentNames( for (let i = 0; i < selectionSet.selections.length; i++) { const selection = selectionSet.selections[i]; switch (selection.kind) { - case Kind.FIELD: + case Kind.FIELD: { const fieldName = selection.name.value; let fieldDef; if (isObjectType(parentType) || isInterfaceType(parentType)) { @@ -761,10 +761,11 @@ function _collectFieldsAndFragmentNames( } nodeAndDefs[responseName].push([parentType, selection, fieldDef]); break; + } case Kind.FRAGMENT_SPREAD: fragmentNames[selection.name.value] = true; break; - case Kind.INLINE_FRAGMENT: + case Kind.INLINE_FRAGMENT: { const typeCondition = selection.typeCondition; const inlineFragmentType = typeCondition ? typeFromAST(context.getSchema(), typeCondition) @@ -777,6 +778,7 @@ function _collectFieldsAndFragmentNames( fragmentNames, ); break; + } } } }