diff --git a/.eslintrc.yml b/.eslintrc.yml index e18d27e027..50fd1f85f9 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -538,7 +538,7 @@ overrides: '@typescript-eslint/restrict-template-expressions': off #TODO temporarily disabled '@typescript-eslint/sort-type-union-intersection-members': off # TODO consider '@typescript-eslint/strict-boolean-expressions': off # TODO consider - '@typescript-eslint/switch-exhaustiveness-check': off #TODO temporarily disabled + '@typescript-eslint/switch-exhaustiveness-check': error '@typescript-eslint/triple-slash-reference': error '@typescript-eslint/typedef': off '@typescript-eslint/unbound-method': off # TODO consider diff --git a/src/__tests__/starWarsSchema.ts b/src/__tests__/starWarsSchema.ts index 2cc586a6ac..7bd8fb3e8f 100644 --- a/src/__tests__/starWarsSchema.ts +++ b/src/__tests__/starWarsSchema.ts @@ -1,5 +1,3 @@ -import { invariant } from '../jsutils/invariant'; - import { GraphQLSchema } from '../type/schema'; import { GraphQLString } from '../type/scalars'; import { @@ -137,9 +135,6 @@ const characterInterface: GraphQLInterfaceType = new GraphQLInterfaceType({ case 'Droid': return droidType.name; } - - // istanbul ignore next (Not reachable. All possible types have been considered) - invariant(false); }, }); diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 3dbb6c5cdd..cab22dfd13 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -309,6 +309,8 @@ export function buildExecutionContext( case Kind.FRAGMENT_DEFINITION: fragments[definition.name.value] = definition; break; + default: + // ignore non-executable definitions } } diff --git a/src/language/parser.ts b/src/language/parser.ts index 1b0bc75f92..4c1725cce4 100644 --- a/src/language/parser.ts +++ b/src/language/parser.ts @@ -619,8 +619,9 @@ export class Parser { } } return this.parseVariable(); + default: + throw this.unexpected(); } - throw this.unexpected(); } parseConstValueLiteral(): ConstValueNode { diff --git a/src/type/schema.ts b/src/type/schema.ts index d8a749dfd4..1842857905 100644 --- a/src/type/schema.ts +++ b/src/type/schema.ts @@ -9,10 +9,10 @@ import type { Maybe } from '../jsutils/Maybe'; import type { GraphQLError } from '../error/GraphQLError'; import type { - OperationTypeNode, SchemaDefinitionNode, SchemaExtensionNode, } from '../language/ast'; +import { OperationTypeNode } from '../language/ast'; import type { GraphQLType, @@ -282,11 +282,11 @@ export class GraphQLSchema { getRootType(operation: OperationTypeNode): Maybe { switch (operation) { - case 'query': + case OperationTypeNode.QUERY: return this.getQueryType(); - case 'mutation': + case OperationTypeNode.MUTATION: return this.getMutationType(); - case 'subscription': + case OperationTypeNode.SUBSCRIPTION: return this.getSubscriptionType(); } } diff --git a/src/utilities/TypeInfo.ts b/src/utilities/TypeInfo.ts index a737db8c39..7b316b963f 100644 --- a/src/utilities/TypeInfo.ts +++ b/src/utilities/TypeInfo.ts @@ -247,6 +247,8 @@ export class TypeInfo { this._enumValue = enumValue; break; } + default: + // Ignore other nodes } } @@ -283,6 +285,8 @@ export class TypeInfo { case Kind.ENUM: this._enumValue = null; break; + default: + // Ignore other nodes } } } diff --git a/src/utilities/__tests__/separateOperations-test.ts b/src/utilities/__tests__/separateOperations-test.ts index 3ebe1a5f57..2f14bae9ac 100644 --- a/src/utilities/__tests__/separateOperations-test.ts +++ b/src/utilities/__tests__/separateOperations-test.ts @@ -201,6 +201,34 @@ describe('separateOperations', () => { }); }); + it('ignores type definitions', () => { + const ast = parse(` + query Foo { + ...Bar + } + + fragment Bar on T { + baz + } + + scalar Foo + type Bar + `); + + const separatedASTs = mapValue(separateOperations(ast), print); + expect(separatedASTs).to.deep.equal({ + Foo: dedent` + query Foo { + ...Bar + } + + fragment Bar on T { + baz + } + `, + }); + }); + it('handles unknown fragments', () => { const ast = parse(` { diff --git a/src/utilities/buildClientSchema.ts b/src/utilities/buildClientSchema.ts index e2d55eecb1..138f7f2625 100644 --- a/src/utilities/buildClientSchema.ts +++ b/src/utilities/buildClientSchema.ts @@ -173,6 +173,8 @@ export function buildClientSchema( function buildType(type: IntrospectionType): GraphQLNamedType { // eslint-disable-next-line @typescript-eslint/prefer-optional-chain if (type != null && type.name != null && type.kind != null) { + // FIXME: Properly type IntrospectionType, it's a breaking change so fix in v17 + // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check switch (type.kind) { case TypeKind.SCALAR: return buildScalarDef(type); diff --git a/src/utilities/extendSchema.ts b/src/utilities/extendSchema.ts index 6a96ddb3f5..c952a4b40e 100644 --- a/src/utilities/extendSchema.ts +++ b/src/utilities/extendSchema.ts @@ -649,9 +649,6 @@ export function extendSchemaImpl( }); } } - - // istanbul ignore next (Not reachable. All possible type definition nodes have been considered) - invariant(false, 'Unexpected type definition node: ' + inspect(astNode)); } } diff --git a/src/utilities/separateOperations.ts b/src/utilities/separateOperations.ts index ece8c2739d..84a8b774f9 100644 --- a/src/utilities/separateOperations.ts +++ b/src/utilities/separateOperations.ts @@ -31,6 +31,8 @@ export function separateOperations( definitionNode.selectionSet, ); break; + default: + // ignore non-executable definitions } } diff --git a/src/utilities/valueFromASTUntyped.ts b/src/utilities/valueFromASTUntyped.ts index c3e2e92e49..678ea15128 100644 --- a/src/utilities/valueFromASTUntyped.ts +++ b/src/utilities/valueFromASTUntyped.ts @@ -1,6 +1,4 @@ import type { ObjMap } from '../jsutils/ObjMap'; -import { inspect } from '../jsutils/inspect'; -import { invariant } from '../jsutils/invariant'; import { keyValMap } from '../jsutils/keyValMap'; import type { Maybe } from '../jsutils/Maybe'; @@ -51,7 +49,4 @@ export function valueFromASTUntyped( case Kind.VARIABLE: return variables?.[valueNode.name.value]; } - - // istanbul ignore next (Not reachable. All possible value nodes have been considered) - invariant(false, 'Unexpected value node: ' + inspect(valueNode)); } diff --git a/src/validation/rules/KnownDirectivesRule.ts b/src/validation/rules/KnownDirectivesRule.ts index 53c98db3a8..20cf7fa024 100644 --- a/src/validation/rules/KnownDirectivesRule.ts +++ b/src/validation/rules/KnownDirectivesRule.ts @@ -120,6 +120,9 @@ function getDirectiveLocationForASTPath( ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION; } + // istanbul ignore next (Not reachable. All possible types have been considered) + default: + invariant(false, 'Unexpected kind: ' + inspect(appliedTo.kind)); } } @@ -134,7 +137,4 @@ function getDirectiveLocationForOperation( case OperationTypeNode.SUBSCRIPTION: return DirectiveLocation.SUBSCRIPTION; } - - // istanbul ignore next (Not reachable. All possible types have been considered) - invariant(false, 'Unexpected operation: ' + inspect(operation)); } diff --git a/src/validation/rules/PossibleTypeExtensionsRule.ts b/src/validation/rules/PossibleTypeExtensionsRule.ts index 27016fffd8..fe014fe7d6 100644 --- a/src/validation/rules/PossibleTypeExtensionsRule.ts +++ b/src/validation/rules/PossibleTypeExtensionsRule.ts @@ -137,8 +137,8 @@ function extensionKindToTypeName(kind: Kind): string { return 'enum'; case Kind.INPUT_OBJECT_TYPE_EXTENSION: return 'input object'; + // istanbul ignore next (Not reachable. All possible types have been considered) + default: + invariant(false, 'Unexpected kind: ' + inspect(kind)); } - - // istanbul ignore next (Not reachable. All possible types have been considered) - invariant(false, 'Unexpected kind: ' + inspect(kind)); }