Skip to content

Commit 8871834

Browse files
committed
Fix some flow issues in anticipation of Flow v0.28
1 parent 63f9985 commit 8871834

File tree

5 files changed

+75
-68
lines changed

5 files changed

+75
-68
lines changed

src/execution/execute.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function executeFieldsSerially(
307307
return results;
308308
}
309309
if (isThenable(result)) {
310-
return ((result: any): Promise).then(resolvedResult => {
310+
return ((result: any): Promise<*>).then(resolvedResult => {
311311
results[responseName] = resolvedResult;
312312
return results;
313313
});
@@ -648,7 +648,7 @@ function completeValueCatchingError(
648648
// error and resolve to null.
649649
// Note: we don't rely on a `catch` method, but we do expect "thenable"
650650
// to take a second callback for the error case.
651-
return ((completed: any): Promise).then(undefined, error => {
651+
return ((completed: any): Promise<*>).then(undefined, error => {
652652
exeContext.errors.push(error);
653653
return Promise.resolve(null);
654654
});
@@ -693,7 +693,7 @@ function completeValue(
693693
): mixed {
694694
// If result is a Promise, apply-lift over completeValue.
695695
if (isThenable(result)) {
696-
return ((result: any): Promise).then(
696+
return ((result: any): Promise<*>).then(
697697
// Once resolved to a value, complete that value.
698698
resolved => completeValue(
699699
exeContext,
@@ -727,7 +727,7 @@ function completeValue(
727727
if (completed === null) {
728728
throw new GraphQLError(
729729
`Cannot return null for non-nullable field ${
730-
info.parentType}.${info.fieldName}.`,
730+
info.parentType.name}.${info.fieldName}.`,
731731
fieldASTs
732732
);
733733
}
@@ -787,7 +787,7 @@ function completeValue(
787787
// Not reachable. All possible output types have been considered.
788788
invariant(
789789
false,
790-
`Cannot complete value of unexpected type "${returnType}".`
790+
`Cannot complete value of unexpected type "${String(returnType)}".`
791791
);
792792
}
793793

@@ -797,7 +797,7 @@ function completeValue(
797797
*/
798798
function completeListValue(
799799
exeContext: ExecutionContext,
800-
returnType: GraphQLList,
800+
returnType: GraphQLList<*>,
801801
fieldASTs: Array<Field>,
802802
info: GraphQLResolveInfo,
803803
path: Array<string | number>,
@@ -806,7 +806,7 @@ function completeListValue(
806806
invariant(
807807
Array.isArray(result),
808808
`User Error: expected iterable, but did not find one for field ${
809-
info.parentType}.${info.fieldName}.`
809+
info.parentType.name}.${info.fieldName}.`
810810
);
811811

812812
// This is specified as a simple map, however we're optimizing the path
@@ -866,17 +866,17 @@ function completeAbstractValue(
866866

867867
if (!(runtimeType instanceof GraphQLObjectType)) {
868868
throw new GraphQLError(
869-
`Abstract type ${returnType} must resolve to an Object type at runtime ` +
870-
`for field ${info.parentType}.${info.fieldName} with value "${result}",` +
871-
`received "${runtimeType}".`,
869+
`Abstract type ${returnType.name} must resolve to an Object type at ` +
870+
`runtime for field ${info.parentType.name}.${info.fieldName} with ` +
871+
`value "${String(result)}", received "${String(runtimeType)}".`,
872872
fieldASTs
873873
);
874874
}
875875

876876
if (!exeContext.schema.isPossibleType(returnType, runtimeType)) {
877877
throw new GraphQLError(
878-
`Runtime Object type "${runtimeType}" is not a possible type ` +
879-
`for "${returnType}".`,
878+
`Runtime Object type "${runtimeType.name}" is not a possible type ` +
879+
`for "${returnType.name}".`,
880880
fieldASTs
881881
);
882882
}
@@ -908,7 +908,7 @@ function completeObjectValue(
908908
if (returnType.isTypeOf &&
909909
!returnType.isTypeOf(result, exeContext.contextValue, info)) {
910910
throw new GraphQLError(
911-
`Expected value of type "${returnType}" but got: ${result}.`,
911+
`Expected value of type "${returnType.name}" but got: ${String(result)}.`,
912912
fieldASTs
913913
);
914914
}

src/language/lexer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ export const TokenKind = {
7575
* A helper function to describe a token as a string for debugging
7676
*/
7777
export function getTokenDesc(token: Token): string {
78-
return token.value ?
79-
`${getTokenKindDesc(token.kind)} "${token.value}"` :
78+
const value = token.value;
79+
return value ?
80+
`${getTokenKindDesc(token.kind)} "${value}"` :
8081
getTokenKindDesc(token.kind);
8182
}
8283

src/language/parser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,36 +492,36 @@ function parseValueLiteral(parser: Parser, isConst: boolean): Value {
492492
case TokenKind.INT:
493493
advance(parser);
494494
return {
495-
kind: INT,
495+
kind: (INT: 'IntValue'),
496496
value: ((token.value: any): string),
497497
loc: loc(parser, token.start)
498498
};
499499
case TokenKind.FLOAT:
500500
advance(parser);
501501
return {
502-
kind: FLOAT,
502+
kind: (FLOAT: 'FloatValue'),
503503
value: ((token.value: any): string),
504504
loc: loc(parser, token.start)
505505
};
506506
case TokenKind.STRING:
507507
advance(parser);
508508
return {
509-
kind: STRING,
509+
kind: (STRING: 'StringValue'),
510510
value: ((token.value: any): string),
511511
loc: loc(parser, token.start)
512512
};
513513
case TokenKind.NAME:
514514
if (token.value === 'true' || token.value === 'false') {
515515
advance(parser);
516516
return {
517-
kind: BOOLEAN,
517+
kind: (BOOLEAN: 'BooleanValue'),
518518
value: token.value === 'true',
519519
loc: loc(parser, token.start)
520520
};
521521
} else if (token.value !== 'null') {
522522
advance(parser);
523523
return {
524-
kind: ENUM,
524+
kind: (ENUM: 'EnumValue'),
525525
value: ((token.value: any): string),
526526
loc: loc(parser, token.start)
527527
};

src/type/definition.js

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,16 @@ export class GraphQLScalarType<InternalType> {
217217
this.description = config.description;
218218
invariant(
219219
typeof config.serialize === 'function',
220-
`${this} must provide "serialize" function. If this custom Scalar is ` +
221-
'also used as an input type, ensure "parseValue" and "parseLiteral" ' +
220+
`${this.name} must provide "serialize" function. If this custom Scalar ` +
221+
'is also used as an input type, ensure "parseValue" and "parseLiteral" ' +
222222
'functions are also provided.'
223223
);
224224
if (config.parseValue || config.parseLiteral) {
225225
invariant(
226226
typeof config.parseValue === 'function' &&
227227
typeof config.parseLiteral === 'function',
228-
`${this} must provide both "parseValue" and "parseLiteral" functions.`
228+
`${this.name} must provide both "parseValue" and "parseLiteral" ` +
229+
'functions.'
229230
);
230231
}
231232
this._scalarConfig = config;
@@ -315,7 +316,7 @@ export class GraphQLObjectType {
315316
if (config.isTypeOf) {
316317
invariant(
317318
typeof config.isTypeOf === 'function',
318-
`${this} must provide "isTypeOf" as a function.`
319+
`${this.name} must provide "isTypeOf" as a function.`
319320
);
320321
}
321322
this.isTypeOf = config.isTypeOf;
@@ -353,21 +354,22 @@ function defineInterfaces(
353354
}
354355
invariant(
355356
Array.isArray(interfaces),
356-
`${type} interfaces must be an Array or a function which returns an Array.`
357+
`${type.name} interfaces must be an Array or a function which returns ` +
358+
'an Array.'
357359
);
358360
interfaces.forEach(iface => {
359361
invariant(
360362
iface instanceof GraphQLInterfaceType,
361-
`${type} may only implement Interface types, it cannot ` +
362-
`implement: ${iface}.`
363+
`${type.name} may only implement Interface types, it cannot ` +
364+
`implement: ${iface.name}.`
363365
);
364366
if (typeof iface.resolveType !== 'function') {
365367
invariant(
366368
typeof type.isTypeOf === 'function',
367-
`Interface Type ${iface} does not provide a "resolveType" function ` +
368-
`and implementing Type ${type} does not provide a "isTypeOf" ` +
369-
'function. There is no way to resolve this implementing type ' +
370-
'during execution.'
369+
`Interface Type ${iface.name} does not provide a "resolveType" ` +
370+
`function and implementing Type ${type.name} does not provide a ` +
371+
'"isTypeOf" function. There is no way to resolve this implementing ' +
372+
'type during execution.'
371373
);
372374
}
373375
});
@@ -381,14 +383,14 @@ function defineFieldMap(
381383
const fieldMap: any = resolveMaybeThunk(fields);
382384
invariant(
383385
isPlainObj(fieldMap),
384-
`${type} fields must be an object with field names as keys or a ` +
386+
`${type.name} fields must be an object with field names as keys or a ` +
385387
'function which returns such an object.'
386388
);
387389

388390
const fieldNames = Object.keys(fieldMap);
389391
invariant(
390392
fieldNames.length > 0,
391-
`${type} fields must be an object with field names as keys or a ` +
393+
`${type.name} fields must be an object with field names as keys or a ` +
392394
'function which returns such an object.'
393395
);
394396

@@ -401,29 +403,29 @@ function defineFieldMap(
401403
};
402404
invariant(
403405
!field.hasOwnProperty('isDeprecated'),
404-
`${type}.${fieldName} should provide "deprecationReason" instead ` +
406+
`${type.name}.${fieldName} should provide "deprecationReason" instead ` +
405407
'of "isDeprecated".'
406408
);
407409
invariant(
408410
isOutputType(field.type),
409-
`${type}.${fieldName} field type must be Output Type but ` +
410-
`got: ${field.type}.`
411+
`${type.name}.${fieldName} field type must be Output Type but ` +
412+
`got: ${String(field.type)}.`
411413
);
412414
if (!field.args) {
413415
field.args = [];
414416
} else {
415417
invariant(
416418
isPlainObj(field.args),
417-
`${type}.${fieldName} args must be an object with argument names ` +
418-
'as keys.'
419+
`${type.name}.${fieldName} args must be an object with argument ` +
420+
'names as keys.'
419421
);
420422
field.args = Object.keys(field.args).map(argName => {
421423
assertValidName(argName);
422424
const arg = field.args[argName];
423425
invariant(
424426
isInputType(arg.type),
425-
`${type}.${fieldName}(${argName}:) argument type must be ` +
426-
`Input Type but got: ${arg.type}.`
427+
`${type.name}.${fieldName}(${argName}:) argument type must be ` +
428+
`Input Type but got: ${String(arg.type)}.`
427429
);
428430
return {
429431
name: argName,
@@ -564,7 +566,7 @@ export class GraphQLInterfaceType {
564566
if (config.resolveType) {
565567
invariant(
566568
typeof config.resolveType === 'function',
567-
`${this} must provide "resolveType" as a function.`
569+
`${this.name} must provide "resolveType" as a function.`
568570
);
569571
}
570572
this.resolveType = config.resolveType;
@@ -635,7 +637,7 @@ export class GraphQLUnionType {
635637
if (config.resolveType) {
636638
invariant(
637639
typeof config.resolveType === 'function',
638-
`${this} must provide "resolveType" as a function.`
640+
`${this.name} must provide "resolveType" as a function.`
639641
);
640642
}
641643
this.resolveType = config.resolveType;
@@ -646,13 +648,14 @@ export class GraphQLUnionType {
646648
config.types.forEach(type => {
647649
invariant(
648650
type instanceof GraphQLObjectType,
649-
`${this} may only contain Object types, it cannot contain: ${type}.`
651+
`${this.name} may only contain Object types, it cannot contain: ` +
652+
`${String(type)}.`
650653
);
651654
if (typeof this.resolveType !== 'function') {
652655
invariant(
653656
typeof type.isTypeOf === 'function',
654-
`Union Type ${this} does not provide a "resolveType" function ` +
655-
`and possible Type ${type} does not provide a "isTypeOf" ` +
657+
`Union Type ${this.name} does not provide a "resolveType" function ` +
658+
`and possible Type ${type.name} does not provide a "isTypeOf" ` +
656659
'function. There is no way to resolve this possible type ' +
657660
'during execution.'
658661
);
@@ -783,24 +786,24 @@ function defineEnumValues(
783786
): Array<GraphQLEnumValueDefinition/* <T> */> {
784787
invariant(
785788
isPlainObj(valueMap),
786-
`${type} values must be an object with value names as keys.`
789+
`${type.name} values must be an object with value names as keys.`
787790
);
788791
const valueNames = Object.keys(valueMap);
789792
invariant(
790793
valueNames.length > 0,
791-
`${type} values must be an object with value names as keys.`
794+
`${type.name} values must be an object with value names as keys.`
792795
);
793796
return valueNames.map(valueName => {
794797
assertValidName(valueName);
795798
const value = valueMap[valueName];
796799
invariant(
797800
isPlainObj(value),
798-
`${type}.${valueName} must refer to an object with a "value" key ` +
799-
`representing an internal value but got: ${value}.`
801+
`${type.name}.${valueName} must refer to an object with a "value" key ` +
802+
`representing an internal value but got: ${String(value)}.`
800803
);
801804
invariant(
802805
!value.hasOwnProperty('isDeprecated'),
803-
`${type}.${valueName} should provide "deprecationReason" instead ` +
806+
`${type.name}.${valueName} should provide "deprecationReason" instead ` +
804807
'of "isDeprecated".'
805808
);
806809
return {
@@ -880,13 +883,13 @@ export class GraphQLInputObjectType {
880883
const fieldMap: any = resolveMaybeThunk(this._typeConfig.fields);
881884
invariant(
882885
isPlainObj(fieldMap),
883-
`${this} fields must be an object with field names as keys or a ` +
886+
`${this.name} fields must be an object with field names as keys or a ` +
884887
'function which returns such an object.'
885888
);
886889
const fieldNames = Object.keys(fieldMap);
887890
invariant(
888891
fieldNames.length > 0,
889-
`${this} fields must be an object with field names as keys or a ` +
892+
`${this.name} fields must be an object with field names as keys or a ` +
890893
'function which returns such an object.'
891894
);
892895
const resultFieldMap = {};
@@ -898,8 +901,8 @@ export class GraphQLInputObjectType {
898901
};
899902
invariant(
900903
isInputType(field.type),
901-
`${this}.${fieldName} field type must be Input Type but ` +
902-
`got: ${field.type}.`
904+
`${this.name}.${fieldName} field type must be Input Type but ` +
905+
`got: ${String(field.type)}.`
903906
);
904907
resultFieldMap[fieldName] = field;
905908
});
@@ -966,7 +969,7 @@ export class GraphQLList<T: GraphQLType> {
966969
constructor(type: T) {
967970
invariant(
968971
isType(type),
969-
`Can only create List of a GraphQLType but got: ${type}.`
972+
`Can only create List of a GraphQLType but got: ${String(type)}.`
970973
);
971974
this.ofType = type;
972975
}
@@ -1003,7 +1006,8 @@ export class GraphQLNonNull<T: GraphQLNullableType> {
10031006
constructor(type: T) {
10041007
invariant(
10051008
isType(type) && !(type instanceof GraphQLNonNull),
1006-
`Can only create NonNull of a Nullable GraphQLType but got: ${type}.`
1009+
'Can only create NonNull of a Nullable GraphQLType but got: ' +
1010+
`${String(type)}.`
10071011
);
10081012
this.ofType = type;
10091013
}

0 commit comments

Comments
 (0)