From de4272c6f9f2dc5ed6e791111ea4b9ef11ab3bdd Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Sat, 16 Dec 2017 18:07:25 -0800 Subject: [PATCH] Remove flow option experimental.const_params Merges #1157 Codebases which don't enable this experiment show flow errors --- .flowconfig | 1 - src/error/GraphQLError.js | 3 ++- src/type/introspection.js | 17 ++++++++++++----- src/type/scalars.js | 13 ++++++++----- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.flowconfig b/.flowconfig index 3a5fc72f9d..5271361e9a 100644 --- a/.flowconfig +++ b/.flowconfig @@ -9,7 +9,6 @@ [libs] [options] -experimental.const_params=true [version] ^0.61.0 diff --git a/src/error/GraphQLError.js b/src/error/GraphQLError.js index dbec9a1255..21698305b3 100644 --- a/src/error/GraphQLError.js +++ b/src/error/GraphQLError.js @@ -125,7 +125,8 @@ export function GraphQLError( // eslint-disable-line no-redeclare let _locations; if (positions && source) { - _locations = positions.map(pos => getLocation(source, pos)); + const providedSource = source; + _locations = positions.map(pos => getLocation(providedSource, pos)); } else if (_nodes) { _locations = _nodes.reduce((list, node) => { if (node.loc) { diff --git a/src/type/introspection.js b/src/type/introspection.js index 0340c182af..759f4b8f2b 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -27,7 +27,7 @@ import { import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; import { GraphQLString, GraphQLBoolean } from './scalars'; import { DirectiveLocation } from '../language/directiveLocation'; -import type { GraphQLField, GraphQLType } from './definition'; +import type { GraphQLField } from './definition'; export const __Schema = new GraphQLObjectType({ name: '__Schema', @@ -465,11 +465,18 @@ export const introspectionTypes: $ReadOnlyArray<*> = [ __TypeKind, ]; -export function isIntrospectionType(type: ?GraphQLType): boolean %checks { +export function isIntrospectionType(type: mixed): boolean %checks { return ( isNamedType(type) && - introspectionTypes.some( - introspectionType => introspectionType.name === type.name, - ) + // Would prefer to use introspectionTypes.some(), however %checks needs + // a simple expression. + (type.name === __Schema.name || + type.name === __Directive.name || + type.name === __DirectiveLocation.name || + type.name === __Type.name || + type.name === __Field.name || + type.name === __InputValue.name || + type.name === __EnumValue.name || + type.name === __TypeKind.name) ); } diff --git a/src/type/scalars.js b/src/type/scalars.js index 34b631e4fd..eed96e2f58 100644 --- a/src/type/scalars.js +++ b/src/type/scalars.js @@ -9,7 +9,6 @@ import { GraphQLScalarType, isNamedType } from './definition'; import * as Kind from '../language/kinds'; -import type { GraphQLType } 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. @@ -145,11 +144,15 @@ export const specifiedScalarTypes: $ReadOnlyArray<*> = [ GraphQLID, ]; -export function isSpecifiedScalarType(type: ?GraphQLType): boolean %checks { +export function isSpecifiedScalarType(type: mixed): boolean %checks { return ( isNamedType(type) && - specifiedScalarTypes.some( - specifiedScalarType => specifiedScalarType.name === type.name, - ) + // Would prefer to use specifiedScalarTypes.some(), however %checks needs + // a simple expression. + (type.name === GraphQLString.name || + type.name === GraphQLInt.name || + type.name === GraphQLFloat.name || + type.name === GraphQLBoolean.name || + type.name === GraphQLID.name) ); }