@@ -45,8 +45,6 @@ import type {
4545 ConstValueNode ,
4646} from '../language/ast' ;
4747
48- import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped' ;
49-
5048import type { GraphQLSchema } from './schema' ;
5149
5250// Predicates & Assertions
@@ -562,8 +560,9 @@ export class GraphQLScalarType {
562560 specifiedByURL : ?string ;
563561 serialize : GraphQLScalarSerializer < mixed > ;
564562 parseValue : GraphQLScalarValueParser < mixed > ;
565- parseLiteral : GraphQLScalarLiteralParser < mixed > ;
563+ parseLiteral : ? GraphQLScalarLiteralParser < mixed > ;
566564 valueToLiteral : ?GraphQLScalarValueToLiteral ;
565+ literalToValue : ?GraphQLScalarLiteralToValue ;
567566 extensions : ?ReadOnlyObjMap < mixed > ;
568567 astNode : ?ScalarTypeDefinitionNode ;
569568 extensionASTNodes : $ReadOnlyArray < ScalarTypeExtensionNode > ;
@@ -575,10 +574,9 @@ export class GraphQLScalarType {
575574 this . specifiedByURL = config . specifiedByURL ;
576575 this . serialize = config . serialize ?? identityFunc ;
577576 this . parseValue = parseValue ;
578- this . parseLiteral =
579- config . parseLiteral ??
580- ( ( node , variables ) => parseValue ( valueFromASTUntyped ( node , variables ) ) ) ;
577+ this . parseLiteral = config . parseLiteral ;
581578 this . valueToLiteral = config . valueToLiteral ;
579+ this . literalToValue = config . literalToValue ;
582580 this . extensions = config . extensions && toObjMap ( config . extensions ) ;
583581 this . astNode = config . astNode ;
584582 this . extensionASTNodes = config . extensionASTNodes ?? [ ] ;
@@ -615,6 +613,7 @@ export class GraphQLScalarType {
615613 parseValue: this.parseValue,
616614 parseLiteral: this.parseLiteral,
617615 valueToLiteral: this.valueToLiteral,
616+ literalToValue: this.literalToValue,
618617 extensions: this.extensions,
619618 astNode: this.astNode,
620619 extensionASTNodes: this.extensionASTNodes,
@@ -644,14 +643,15 @@ export type GraphQLScalarValueParser<TInternal> = (
644643) => ?TInternal;
645644
646645export type GraphQLScalarLiteralParser<TInternal> = (
647- valueNode: ValueNode,
648- variables: ?ObjMap<mixed>,
646+ valueNode: ConstValueNode,
649647) => ?TInternal;
650648
651649export type GraphQLScalarValueToLiteral = (
652650 inputValue: mixed,
653651) => ?ConstValueNode;
654652
653+ export type GraphQLScalarLiteralToValue = (valueNode: ConstValueNode) => mixed;
654+
655655export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
656656 name: string,
657657 description?: ?string,
@@ -661,9 +661,11 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
661661 // Parses an externally provided value to use as an input.
662662 parseValue?: GraphQLScalarValueParser<TInternal>,
663663 // Parses an externally provided literal value to use as an input.
664- parseLiteral?: GraphQLScalarLiteralParser<TInternal>,
665- // Translates an external input value to an external literal (AST).
664+ parseLiteral?: ? GraphQLScalarLiteralParser<TInternal>,
665+ // Translates an external input value to a literal (AST).
666666 valueToLiteral?: ?GraphQLScalarValueToLiteral,
667+ // Translates a literal (AST) to external input value.
668+ literalToValue?: ?GraphQLScalarLiteralToValue,
667669 extensions?: ?ReadOnlyObjMapLike<mixed>,
668670 astNode?: ?ScalarTypeDefinitionNode,
669671 extensionASTNodes?: ?$ReadOnlyArray<ScalarTypeExtensionNode>,
@@ -673,7 +675,6 @@ type GraphQLScalarTypeNormalizedConfig = {|
673675 ...GraphQLScalarTypeConfig<mixed, mixed>,
674676 serialize: GraphQLScalarSerializer<mixed>,
675677 parseValue: GraphQLScalarValueParser<mixed>,
676- parseLiteral: GraphQLScalarLiteralParser<mixed>,
677678 extensions: ?ReadOnlyObjMap<mixed>,
678679 extensionASTNodes: $ReadOnlyArray<ScalarTypeExtensionNode>,
679680|};
@@ -1331,7 +1332,7 @@ export class GraphQLEnumType /* <T> */ {
13311332 return enumValue . value ;
13321333 }
13331334
1334- parseLiteral ( valueNode : ValueNode , _variables : ? ObjMap < mixed > ) : ?any /* T */ {
1335+ parseLiteral ( valueNode : ValueNode ) : ?any /* T */ {
13351336 // Note: variables will be resolved to a value before calling this function.
13361337 if ( valueNode . kind !== Kind . ENUM ) {
13371338 const valueStr = print ( valueNode ) ;
@@ -1364,6 +1365,12 @@ export class GraphQLEnumType /* <T> */ {
13641365 }
13651366 }
13661367
1368+ literalToValue ( valueNode : ConstValueNode ) : mixed {
1369+ if ( valueNode . kind === Kind . ENUM ) {
1370+ return valueNode . value ;
1371+ }
1372+ }
1373+
13671374 toConfig ( ) : GraphQLEnumTypeNormalizedConfig {
13681375 const values = keyValMap (
13691376 this . getValues ( ) ,
0 commit comments