diff --git a/src/type/__tests__/predicate-test.js b/src/type/__tests__/predicate-test.js index a825db0e6c..ed9fba43d0 100644 --- a/src/type/__tests__/predicate-test.js +++ b/src/type/__tests__/predicate-test.js @@ -157,35 +157,6 @@ describe('Type predicates', () => { it('returns false for custom scalar', () => { expect(isSpecifiedScalarType(ScalarType)).to.equal(false); }); - - it('returns false for scalar class (rather than specified instance)', () => { - expect(isSpecifiedScalarType(GraphQLScalarType)).to.equal(false); - }); - - it('returns false for wrapped specified scalar', () => { - expect(isSpecifiedScalarType(GraphQLList(GraphQLString))).to.equal(false); - }); - - it('returns false for non-scalar', () => { - expect(isSpecifiedScalarType(EnumType)).to.equal(false); - expect(isSpecifiedScalarType(Directive)).to.equal(false); - }); - - it('returns false for spec defined directive', () => { - expect(isSpecifiedScalarType(GraphQLSkipDirective)).to.equal(false); - }); - - it('returns false for object type named like specified scalar', () => { - const ObjectNamedLikeScalar = new GraphQLObjectType({ - name: 'String', - fields: { serialize: { type: GraphQLString } }, - }); - expect(isSpecifiedScalarType(ObjectNamedLikeScalar)).to.equal(false); - }); - - it('returns false for random garbage', () => { - expect(isSpecifiedScalarType({ what: 'is this' })).to.equal(false); - }); }); describe('isObjectType', () => { @@ -700,29 +671,5 @@ describe('Directive predicates', () => { it('returns false for custom directive', () => { expect(isSpecifiedDirective(Directive)).to.equal(false); }); - - it('returns false for directive class (rather than specified instance)', () => { - expect(isSpecifiedDirective(GraphQLDirective)).to.equal(false); - }); - - it('returns false for non-directive', () => { - expect(isSpecifiedDirective(EnumType)).to.equal(false); - expect(isSpecifiedDirective(ScalarType)).to.equal(false); - }); - - it('returns false for spec defined scalar type', () => { - expect(isSpecifiedDirective(GraphQLString)).to.equal(false); - }); - - it('returns false for scalar type named like specified directive', () => { - const ScalarNamedLikeDirective = new GraphQLScalarType({ - name: 'deprecated', - }); - expect(isSpecifiedDirective(ScalarNamedLikeDirective)).to.equal(false); - }); - - it('returns false for random garbage', () => { - expect(isSpecifiedDirective({ what: 'is this' })).to.equal(false); - }); }); }); diff --git a/src/type/directives.js b/src/type/directives.js index bd11613dac..6b42a5e870 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -198,9 +198,8 @@ export const specifiedDirectives = Object.freeze([ GraphQLDeprecatedDirective, ]); -export function isSpecifiedDirective(directive: mixed): boolean %checks { - return ( - isDirective(directive) && - specifiedDirectives.some(({ name }) => name === directive.name) - ); +export function isSpecifiedDirective( + directive: GraphQLDirective, +): boolean %checks { + return specifiedDirectives.some(({ name }) => name === directive.name); } diff --git a/src/type/introspection.js b/src/type/introspection.js index d899648bac..2a6ddd2173 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -14,6 +14,7 @@ import { type GraphQLDirective } from './directives'; import { GraphQLString, GraphQLBoolean } from './scalars'; import { type GraphQLType, + type GraphQLNamedType, type GraphQLInputField, type GraphQLEnumValue, type GraphQLField, @@ -31,7 +32,6 @@ import { isListType, isNonNullType, isAbstractType, - isNamedType, } from './definition'; export const __Schema = new GraphQLObjectType({ @@ -485,9 +485,6 @@ export const introspectionTypes = Object.freeze([ __TypeKind, ]); -export function isIntrospectionType(type: mixed): boolean %checks { - return ( - isNamedType(type) && - introspectionTypes.some(({ name }) => type.name === name) - ); +export function isIntrospectionType(type: GraphQLNamedType): boolean %checks { + return introspectionTypes.some(({ name }) => type.name === name); } diff --git a/src/type/scalars.js b/src/type/scalars.js index 7505827923..17d418c746 100644 --- a/src/type/scalars.js +++ b/src/type/scalars.js @@ -11,7 +11,7 @@ import { print } from '../language/printer'; import { GraphQLError } from '../error/GraphQLError'; -import { GraphQLScalarType, isScalarType } from './definition'; +import { type GraphQLNamedType, GraphQLScalarType } from './definition'; // As per the GraphQL Spec, Integers are only treated as valid when a valid // 32-bit signed integer, providing the broadest support across platforms. @@ -271,9 +271,6 @@ export const specifiedScalarTypes = Object.freeze([ GraphQLID, ]); -export function isSpecifiedScalarType(type: mixed): boolean %checks { - return ( - isScalarType(type) && - specifiedScalarTypes.some(({ name }) => type.name === name) - ); +export function isSpecifiedScalarType(type: GraphQLNamedType): boolean %checks { + return specifiedScalarTypes.some(({ name }) => type.name === name); } diff --git a/tstypes/type/directives.d.ts b/tstypes/type/directives.d.ts index 7608cd8884..c6b8689810 100644 --- a/tstypes/type/directives.d.ts +++ b/tstypes/type/directives.d.ts @@ -69,6 +69,4 @@ export const GraphQLDeprecatedDirective: GraphQLDirective; */ export const specifiedDirectives: ReadonlyArray; -export function isSpecifiedDirective( - directive: any, -): directive is GraphQLDirective; +export function isSpecifiedDirective(directive: GraphQLDirective): boolean; diff --git a/tstypes/type/introspection.d.ts b/tstypes/type/introspection.d.ts index 3acfe6e210..72ccb75937 100644 --- a/tstypes/type/introspection.d.ts +++ b/tstypes/type/introspection.d.ts @@ -37,4 +37,4 @@ export const TypeNameMetaFieldDef: GraphQLField; export const introspectionTypes: ReadonlyArray; -export function isIntrospectionType(type: any): boolean; +export function isIntrospectionType(type: GraphQLType): boolean; diff --git a/tstypes/type/scalars.d.ts b/tstypes/type/scalars.d.ts index fe16fd5cad..71593d10c2 100644 --- a/tstypes/type/scalars.d.ts +++ b/tstypes/type/scalars.d.ts @@ -1,4 +1,4 @@ -import { GraphQLScalarType } from './definition'; +import { GraphQLScalarType, GraphQLNamedType } from './definition'; export const GraphQLInt: GraphQLScalarType; export const GraphQLFloat: GraphQLScalarType; @@ -8,4 +8,4 @@ export const GraphQLID: GraphQLScalarType; export const specifiedScalarTypes: ReadonlyArray; -export function isSpecifiedScalarType(type: any): type is GraphQLScalarType; +export function isSpecifiedScalarType(type: GraphQLNamedType): boolean;