Skip to content

Commit 3083fc5

Browse files
committed
Additional flow issues corrected in anticipation of Flow v0.28
1 parent 8871834 commit 3083fc5

16 files changed

+60
-41
lines changed

src/type/definition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class GraphQLScalarType<InternalType> {
232232
this._scalarConfig = config;
233233
}
234234

235-
serialize(value: mixed): ?InternalType {
235+
serialize(value: InternalType): mixed {
236236
const serializer = this._scalarConfig.serialize;
237237
return serializer(value);
238238
}
@@ -361,7 +361,7 @@ function defineInterfaces(
361361
invariant(
362362
iface instanceof GraphQLInterfaceType,
363363
`${type.name} may only implement Interface types, it cannot ` +
364-
`implement: ${iface.name}.`
364+
`implement: ${String(iface)}.`
365365
);
366366
if (typeof iface.resolveType !== 'function') {
367367
invariant(

src/type/directives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class GraphQLDirective {
7878
invariant(
7979
isInputType(arg.type),
8080
`@${config.name}(${argName}:) argument type must be ` +
81-
`Input Type but got: ${arg.type}.`
81+
`Input Type but got: ${String(arg.type)}.`
8282
);
8383
return {
8484
name: argName,

src/type/schema.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,28 @@ export class GraphQLSchema {
6868

6969
invariant(
7070
config.query instanceof GraphQLObjectType,
71-
`Schema query must be Object Type but got: ${config.query}.`
71+
`Schema query must be Object Type but got: ${
72+
String(config.query)}.`
7273
);
7374
this._queryType = config.query;
7475

7576
invariant(
7677
!config.mutation || config.mutation instanceof GraphQLObjectType,
7778
`Schema mutation must be Object Type if provided but got: ${
78-
config.mutation}.`
79+
String(config.mutation)}.`
7980
);
8081
this._mutationType = config.mutation;
8182

8283
invariant(
8384
!config.subscription || config.subscription instanceof GraphQLObjectType,
8485
`Schema subscription must be Object Type if provided but got: ${
85-
config.subscription}.`
86+
String(config.subscription)}.`
8687
);
8788
this._subscriptionType = config.subscription;
8889

8990
invariant(
9091
!config.types || Array.isArray(config.types),
91-
`Schema types must be Array if provided but got: ${config.types}.`
92+
`Schema types must be Array if provided but got: ${String(config.types)}.`
9293
);
9394

9495
invariant(
@@ -97,7 +98,7 @@ export class GraphQLSchema {
9798
directive => directive instanceof GraphQLDirective
9899
),
99100
`Schema directives must be Array<GraphQLDirective> if provided but got: ${
100-
config.directives}.`
101+
String(config.directives)}.`
101102
);
102103
// Provide specified directives (e.g. @include and @skip) by default.
103104
this._directives = config.directives || specifiedDirectives;
@@ -190,8 +191,8 @@ export class GraphQLSchema {
190191
const possibleTypes = this.getPossibleTypes(abstractType);
191192
invariant(
192193
Array.isArray(possibleTypes),
193-
`Could not find possible implementing types for ${abstractType} in ` +
194-
'schema. Check that schema.types is defined and is an array of ' +
194+
`Could not find possible implementing types for ${abstractType.name} ` +
195+
'in schema. Check that schema.types is defined and is an array of ' +
195196
'all possible types in the schema.'
196197
);
197198
possibleTypeMap[abstractType.name] =
@@ -234,7 +235,7 @@ function typeMapReducer(map: TypeMap, type: ?GraphQLType): TypeMap {
234235
invariant(
235236
map[type.name] === type,
236237
'Schema must contain unique named types but contains multiple ' +
237-
`types named "${type}".`
238+
`types named "${type.name}".`
238239
);
239240
return map;
240241
}

src/utilities/buildASTSchema.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ import {
7171
GraphQLDeprecatedDirective,
7272
} from '../type/directives';
7373

74+
import type {
75+
DirectiveLocationEnum
76+
} from '../type/directives';
77+
7478
import {
7579
__Schema,
7680
__Directive,
@@ -254,7 +258,9 @@ export function buildASTSchema(ast: Document): GraphQLSchema {
254258
function getDirective(directiveAST: DirectiveDefinition): GraphQLDirective {
255259
return new GraphQLDirective({
256260
name: directiveAST.name.value,
257-
locations: directiveAST.locations.map(node => node.value),
261+
locations: directiveAST.locations.map(
262+
node => (node.value: DirectiveLocationEnum)
263+
),
258264
args: makeInputValues(directiveAST.arguments),
259265
});
260266
}

src/utilities/buildClientSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export function buildClientSchema(
222222

223223
function buildScalarDef(
224224
scalarIntrospection: IntrospectionScalarType
225-
): GraphQLScalarType {
225+
): GraphQLScalarType<boolean> {
226226
return new GraphQLScalarType({
227227
name: scalarIntrospection.name,
228228
description: scalarIntrospection.description,

src/utilities/extendSchema.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ export function extendSchema(
185185
__TypeKind,
186186
};
187187

188-
// Get the root Query, Mutation, and Subscription types.
189-
const queryType = getTypeFromDef(schema.getQueryType());
188+
// Get the root Query, Mutation, and Subscription object types.
189+
const queryType = getObjectTypeFromDef(schema.getQueryType());
190190

191191
const existingMutationType = schema.getMutationType();
192192
const mutationType = existingMutationType ?
193-
getTypeFromDef(existingMutationType) :
193+
getObjectTypeFromDef(existingMutationType) :
194194
null;
195195

196196
const existingSubscriptionType = schema.getSubscriptionType();
197197
const subscriptionType = existingSubscriptionType ?
198-
getTypeFromDef(existingSubscriptionType) :
198+
getObjectTypeFromDef(existingSubscriptionType) :
199199
null;
200200

201201
// Iterate through all types, getting the type definition for each, ensuring
@@ -228,6 +228,12 @@ export function extendSchema(
228228
return type;
229229
}
230230

231+
function getObjectTypeFromDef(typeDef: GraphQLObjectType): GraphQLObjectType {
232+
const type = _getNamedType(typeDef.name);
233+
invariant(type instanceof GraphQLObjectType, 'Invalid schema');
234+
return type;
235+
}
236+
231237
function getTypeFromAST(astNode: NamedType): GraphQLNamedType {
232238
const type = _getNamedType(astNode.name.value);
233239
if (!type) {
@@ -302,7 +308,7 @@ export function extendSchema(
302308
return new GraphQLUnionType({
303309
name: type.name,
304310
description: type.description,
305-
types: type.getTypes().map(getTypeFromDef),
311+
types: type.getTypes().map(getObjectTypeFromDef),
306312
resolveType: cannotExecuteClientSchema,
307313
});
308314
}

src/utilities/schemaPrinter.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ function printSchemaDefinition(schema: GraphQLSchema): string {
8282

8383
const queryType = schema.getQueryType();
8484
if (queryType) {
85-
operationTypes.push(` query: ${queryType}`);
85+
operationTypes.push(` query: ${queryType.name}`);
8686
}
8787

8888
const mutationType = schema.getMutationType();
8989
if (mutationType) {
90-
operationTypes.push(` mutation: ${mutationType}`);
90+
operationTypes.push(` mutation: ${mutationType.name}`);
9191
}
9292

9393
const subscriptionType = schema.getSubscriptionType();
9494
if (subscriptionType) {
95-
operationTypes.push(` subscription: ${subscriptionType}`);
95+
operationTypes.push(` subscription: ${subscriptionType.name}`);
9696
}
9797

9898
return `schema {\n${operationTypes.join('\n')}\n}`;
@@ -114,7 +114,7 @@ function printType(type: GraphQLType): string {
114114
return printInputObject(type);
115115
}
116116

117-
function printScalar(type: GraphQLScalarType): string {
117+
function printScalar(type: GraphQLScalarType<any>): string {
118118
return `scalar ${type.name}`;
119119
}
120120

@@ -156,7 +156,8 @@ function printFields(type) {
156156
const fieldMap = type.getFields();
157157
const fields = Object.keys(fieldMap).map(fieldName => fieldMap[fieldName]);
158158
return fields.map(
159-
f => ` ${f.name}${printArgs(f)}: ${f.type}${printDeprecated(f)}`
159+
f => ' ' + f.name + printArgs(f) + ': ' +
160+
String(f.type) + printDeprecated(f)
160161
).join('\n');
161162
}
162163

@@ -182,7 +183,7 @@ function printArgs(fieldOrDirectives) {
182183
}
183184

184185
function printInputValue(arg) {
185-
let argDecl = `${arg.name}: ${arg.type}`;
186+
let argDecl = arg.name + ': ' + String(arg.type);
186187
if (!isNullish(arg.defaultValue)) {
187188
argDecl += ` = ${print(astFromValue(arg.defaultValue, arg.type))}`;
188189
}

src/validation/rules/DefaultValuesOfCorrectType.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export function defaultForNonNullArgMessage(
2121
type: GraphQLType,
2222
guessType: GraphQLType
2323
): string {
24-
return `Variable "$${varName}" of type "${type}" is required and will not ` +
25-
`use the default value. Perhaps you meant to use type "${guessType}".`;
24+
return `Variable "$${varName}" of type "${String(type)}" is required and ` +
25+
'will not use the default value. ' +
26+
`Perhaps you meant to use type "${String(guessType)}".`;
2627
}
2728

2829
export function badValueForDefaultArgMessage(
@@ -32,7 +33,8 @@ export function badValueForDefaultArgMessage(
3233
verboseErrors?: [string]
3334
): string {
3435
const message = verboseErrors ? '\n' + verboseErrors.join('\n') : '';
35-
return `Variable "$${varName}" has invalid default value ${value}.${message}`;
36+
return `Variable "$${varName}" of type "${String(type)}" has invalid ` +
37+
`default value ${value}.${message}`;
3638
}
3739

3840
/**

src/validation/rules/FragmentsOnCompositeTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import type { GraphQLType } from '../../type/definition';
1818
export function inlineFragmentOnNonCompositeErrorMessage(
1919
type: GraphQLType
2020
): string {
21-
return `Fragment cannot condition on non composite type "${type}".`;
21+
return `Fragment cannot condition on non composite type "${String(type)}".`;
2222
}
2323

2424
export function fragmentOnNonCompositeErrorMessage(
2525
fragName: string,
2626
type: GraphQLType
2727
): string {
2828
return `Fragment "${fragName}" cannot condition on non composite ` +
29-
`type "${type}".`;
29+
`type "${String(type)}".`;
3030
}
3131

3232
/**

src/validation/rules/KnownArgumentNames.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function unknownArgMessage(
2828
suggestedArgs: Array<string>
2929
): string {
3030
let message = `Unknown argument "${argName}" on field "${fieldName}" of ` +
31-
`type "${type}".`;
31+
`type "${String(type)}".`;
3232
if (suggestedArgs.length) {
3333
message += ` Did you mean ${quotedOrList(suggestedArgs)}?`;
3434
}

0 commit comments

Comments
 (0)