Skip to content

Commit ca6c284

Browse files
committed
RFC: Add type params to Scalars.
This incrementally adds to #574, however a broader solution is needed to create a mirroring between graphql type definitions and internal flow types.
1 parent 7eae7aa commit ca6c284

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/type/definition.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type { GraphQLSchema } from './schema';
2727
* These are all of the possible kinds of types.
2828
*/
2929
export type GraphQLType =
30-
GraphQLScalarType |
30+
GraphQLScalarType<*, *> |
3131
GraphQLObjectType |
3232
GraphQLInterfaceType |
3333
GraphQLUnionType |
@@ -61,12 +61,12 @@ export function assertType(type: mixed): GraphQLType {
6161
* These types may be used as input types for arguments and directives.
6262
*/
6363
export type GraphQLInputType =
64-
GraphQLScalarType |
64+
GraphQLScalarType<*, *> |
6565
GraphQLEnumType |
6666
GraphQLInputObjectType |
6767
GraphQLList<GraphQLInputType> |
6868
GraphQLNonNull<
69-
GraphQLScalarType |
69+
GraphQLScalarType<*, *> |
7070
GraphQLEnumType |
7171
GraphQLInputObjectType |
7272
GraphQLList<GraphQLInputType>
@@ -93,14 +93,14 @@ export function assertInputType(type: ?GraphQLType): GraphQLInputType {
9393
* These types may be used as output types as the result of fields.
9494
*/
9595
export type GraphQLOutputType =
96-
GraphQLScalarType |
96+
GraphQLScalarType<*, *> |
9797
GraphQLObjectType |
9898
GraphQLInterfaceType |
9999
GraphQLUnionType |
100100
GraphQLEnumType |
101101
GraphQLList<GraphQLOutputType> |
102102
GraphQLNonNull<
103-
GraphQLScalarType |
103+
GraphQLScalarType<*, *> |
104104
GraphQLObjectType |
105105
GraphQLInterfaceType |
106106
GraphQLUnionType |
@@ -131,7 +131,7 @@ export function assertOutputType(type: ?GraphQLType): GraphQLOutputType {
131131
* These types may describe types which may be leaf values.
132132
*/
133133
export type GraphQLLeafType =
134-
GraphQLScalarType |
134+
GraphQLScalarType<*, *> |
135135
GraphQLEnumType;
136136

137137
export function isLeafType(type: ?GraphQLType): boolean {
@@ -200,7 +200,7 @@ export function assertAbstractType(type: ?GraphQLType): GraphQLAbstractType {
200200
* These types can all accept null as a value.
201201
*/
202202
export type GraphQLNullableType =
203-
GraphQLScalarType |
203+
GraphQLScalarType<*, *> |
204204
GraphQLObjectType |
205205
GraphQLInterfaceType |
206206
GraphQLUnionType |
@@ -218,7 +218,7 @@ export function getNullableType<T: GraphQLType>(
218218
* These named types do not include modifiers like List or NonNull.
219219
*/
220220
export type GraphQLNamedType =
221-
GraphQLScalarType |
221+
GraphQLScalarType<*, *> |
222222
GraphQLObjectType |
223223
GraphQLInterfaceType |
224224
GraphQLUnionType |
@@ -265,13 +265,13 @@ function resolveThunk<T>(thunk: Thunk<T>): T {
265265
* });
266266
*
267267
*/
268-
export class GraphQLScalarType {
268+
export class GraphQLScalarType<TInternal, TExternal> {
269269
name: string;
270270
description: ?string;
271271

272-
_scalarConfig: GraphQLScalarTypeConfig<*, *>;
272+
_scalarConfig: GraphQLScalarTypeConfig<TInternal, TExternal>;
273273

274-
constructor(config: GraphQLScalarTypeConfig<*, *>) {
274+
constructor(config: GraphQLScalarTypeConfig<TInternal, TExternal>) {
275275
invariant(config.name, 'Type must be named.');
276276
assertValidName(config.name);
277277
this.name = config.name;
@@ -294,19 +294,19 @@ export class GraphQLScalarType {
294294
}
295295

296296
// Serializes an internal value to include in a response.
297-
serialize(value: mixed): mixed {
297+
serialize(value: mixed): ?TExternal {
298298
const serializer = this._scalarConfig.serialize;
299299
return serializer(value);
300300
}
301301

302302
// Parses an externally provided value to use as an input.
303-
parseValue(value: mixed): mixed {
303+
parseValue(value: mixed): ?TInternal {
304304
const parser = this._scalarConfig.parseValue;
305305
return parser ? parser(value) : null;
306306
}
307307

308308
// Parses an externally provided literal value to use as an input.
309-
parseLiteral(valueNode: ValueNode): mixed {
309+
parseLiteral(valueNode: ValueNode): ?TInternal {
310310
const parser = this._scalarConfig.parseLiteral;
311311
return parser ? parser(valueNode) : null;
312312
}

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<*, *> {
226226
return new GraphQLScalarType({
227227
name: scalarIntrospection.name,
228228
description: scalarIntrospection.description,

src/utilities/schemaPrinter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function printType(type: GraphQLType): string {
152152
return printInputObject(type);
153153
}
154154

155-
function printScalar(type: GraphQLScalarType): string {
155+
function printScalar(type: GraphQLScalarType<*, *>): string {
156156
return printDescription(type) +
157157
`scalar ${type.name}`;
158158
}

0 commit comments

Comments
 (0)