Skip to content

RFC: Add type params to Scalars. #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 14 additions & 14 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { GraphQLSchema } from './schema';
* These are all of the possible kinds of types.
*/
export type GraphQLType =
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLObjectType |
GraphQLInterfaceType |
GraphQLUnionType |
Expand Down Expand Up @@ -61,12 +61,12 @@ export function assertType(type: mixed): GraphQLType {
* These types may be used as input types for arguments and directives.
*/
export type GraphQLInputType =
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLEnumType |
GraphQLInputObjectType |
GraphQLList<GraphQLInputType> |
GraphQLNonNull<
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLEnumType |
GraphQLInputObjectType |
GraphQLList<GraphQLInputType>
Expand All @@ -93,14 +93,14 @@ export function assertInputType(type: ?GraphQLType): GraphQLInputType {
* These types may be used as output types as the result of fields.
*/
export type GraphQLOutputType =
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLObjectType |
GraphQLInterfaceType |
GraphQLUnionType |
GraphQLEnumType |
GraphQLList<GraphQLOutputType> |
GraphQLNonNull<
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLObjectType |
GraphQLInterfaceType |
GraphQLUnionType |
Expand Down Expand Up @@ -131,7 +131,7 @@ export function assertOutputType(type: ?GraphQLType): GraphQLOutputType {
* These types may describe types which may be leaf values.
*/
export type GraphQLLeafType =
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLEnumType;

export function isLeafType(type: ?GraphQLType): boolean {
Expand Down Expand Up @@ -200,7 +200,7 @@ export function assertAbstractType(type: ?GraphQLType): GraphQLAbstractType {
* These types can all accept null as a value.
*/
export type GraphQLNullableType =
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLObjectType |
GraphQLInterfaceType |
GraphQLUnionType |
Expand All @@ -218,7 +218,7 @@ export function getNullableType<T: GraphQLType>(
* These named types do not include modifiers like List or NonNull.
*/
export type GraphQLNamedType =
GraphQLScalarType |
GraphQLScalarType<*, *> |
GraphQLObjectType |
GraphQLInterfaceType |
GraphQLUnionType |
Expand Down Expand Up @@ -265,13 +265,13 @@ function resolveThunk<T>(thunk: Thunk<T>): T {
* });
*
*/
export class GraphQLScalarType {
export class GraphQLScalarType<TInternal, TExternal> {
name: string;
description: ?string;

_scalarConfig: GraphQLScalarTypeConfig<*, *>;
_scalarConfig: GraphQLScalarTypeConfig<TInternal, TExternal>;

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

// Serializes an internal value to include in a response.
serialize(value: mixed): mixed {
serialize(value: mixed): ?TExternal {
const serializer = this._scalarConfig.serialize;
return serializer(value);
}

// Parses an externally provided value to use as an input.
parseValue(value: mixed): mixed {
parseValue(value: mixed): ?TInternal {
const parser = this._scalarConfig.parseValue;
return parser ? parser(value) : null;
}

// Parses an externally provided literal value to use as an input.
parseLiteral(valueNode: ValueNode): mixed {
parseLiteral(valueNode: ValueNode): ?TInternal {
const parser = this._scalarConfig.parseLiteral;
return parser ? parser(valueNode) : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function buildClientSchema(

function buildScalarDef(
scalarIntrospection: IntrospectionScalarType
): GraphQLScalarType {
): GraphQLScalarType<*, *> {
return new GraphQLScalarType({
name: scalarIntrospection.name,
description: scalarIntrospection.description,
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/schemaPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function printType(type: GraphQLType): string {
return printInputObject(type);
}

function printScalar(type: GraphQLScalarType): string {
function printScalar(type: GraphQLScalarType<*, *>): string {
return printDescription(type) +
`scalar ${type.name}`;
}
Expand Down