Skip to content

Works without experimental flow #1157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/error/GraphQLError.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ export function GraphQLError( // eslint-disable-line no-redeclare
}

let _locations;
if (positions && source) {
_locations = positions.map(pos => getLocation(source, pos));
const immutableSource = source;
if (positions && immutableSource) {
_locations = positions.map(pos => getLocation(immutableSource, pos));
} else if (_nodes) {
_locations = _nodes.reduce((list, node) => {
if (node.loc) {
Expand Down
23 changes: 18 additions & 5 deletions src/type/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
isListType,
isNonNullType,
isAbstractType,
isNamedType,
} from './definition';
import { GraphQLList, GraphQLNonNull } from '../type/wrappers';
import { GraphQLString, GraphQLBoolean } from './scalars';
Expand Down Expand Up @@ -467,9 +466,23 @@ export const introspectionTypes: $ReadOnlyArray<*> = [

export function isIntrospectionType(type: ?GraphQLType): boolean %checks {
return (
isNamedType(type) &&
introspectionTypes.some(
introspectionType => introspectionType.name === type.name,
)
// Cannot use function calls to %checks unless flow's
// experimental.const_params=true is set.

// isNamedType(type)
type !== null &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!type && prettiers to Boolean(type) && which is a function call which makes flow fail without experimental.const_params=true. And type && fails because it's not returning a boolean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably Boolean wrap the whole expression then. But also it would be great to avoid the additional instanceof checks - we've managed to corral them into their individual predicate functions so far

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fvchbvgg

type !== undefined &&
!(type instanceof GraphQLList || type instanceof GraphQLNonNull) &&
// introspectionTypes.some(
// introspectionType => introspectionType.name === 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 === type.name)
);
}
23 changes: 17 additions & 6 deletions src/type/scalars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import { GraphQLScalarType, isNamedType } from './definition';
import { GraphQLScalarType } from './definition';
import * as Kind from '../language/kinds';
import type { GraphQLType } from './definition';

Expand Down Expand Up @@ -145,11 +145,22 @@ export const specifiedScalarTypes: $ReadOnlyArray<*> = [
GraphQLID,
];

export function isSpecifiedScalarType(type: ?GraphQLType): boolean %checks {
export function isSpecifiedScalarType(
type: $ReadOnly<?GraphQLType>,
): boolean %checks {
return (
isNamedType(type) &&
specifiedScalarTypes.some(
specifiedScalarType => specifiedScalarType.name === type.name,
)
// Cannot use function calls to %checks unless flow's
// experimental.const_params=true is set.

// equivalent of isNamedType(type), given we only care about scalars
type instanceof GraphQLScalarType &&
// specifiedScalarTypes.some(
// specifiedScalarType => specifiedScalarType.name === type.name
// )
(GraphQLString.name === type.name ||
GraphQLInt.name === type.name ||
GraphQLFloat.name === type.name ||
GraphQLBoolean.name === type.name ||
GraphQLID.name === type.name)
);
}