@@ -45,8 +45,6 @@ import type {
45
45
ConstValueNode ,
46
46
} from '../language/ast' ;
47
47
48
- import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped' ;
49
-
50
48
import type { GraphQLSchema } from './schema' ;
51
49
52
50
// Predicates & Assertions
@@ -562,8 +560,9 @@ export class GraphQLScalarType {
562
560
specifiedByURL : ?string ;
563
561
serialize : GraphQLScalarSerializer < mixed > ;
564
562
parseValue : GraphQLScalarValueParser < mixed > ;
565
- parseLiteral : GraphQLScalarLiteralParser < mixed > ;
563
+ parseLiteral : ? GraphQLScalarLiteralParser < mixed > ;
566
564
valueToLiteral : ?GraphQLScalarValueToLiteral ;
565
+ literalToValue : ?GraphQLScalarLiteralToValue ;
567
566
extensions : ?ReadOnlyObjMap < mixed > ;
568
567
astNode : ?ScalarTypeDefinitionNode ;
569
568
extensionASTNodes : $ReadOnlyArray < ScalarTypeExtensionNode > ;
@@ -575,10 +574,9 @@ export class GraphQLScalarType {
575
574
this . specifiedByURL = config . specifiedByURL ;
576
575
this . serialize = config . serialize ?? identityFunc ;
577
576
this . parseValue = parseValue ;
578
- this . parseLiteral =
579
- config . parseLiteral ??
580
- ( ( node , variables ) => parseValue ( valueFromASTUntyped ( node , variables ) ) ) ;
577
+ this . parseLiteral = config . parseLiteral ;
581
578
this . valueToLiteral = config . valueToLiteral ;
579
+ this . literalToValue = config . literalToValue ;
582
580
this . extensions = config . extensions && toObjMap ( config . extensions ) ;
583
581
this . astNode = config . astNode ;
584
582
this . extensionASTNodes = config . extensionASTNodes ?? [ ] ;
@@ -615,6 +613,7 @@ export class GraphQLScalarType {
615
613
parseValue: this.parseValue,
616
614
parseLiteral: this.parseLiteral,
617
615
valueToLiteral: this.valueToLiteral,
616
+ literalToValue: this.literalToValue,
618
617
extensions: this.extensions,
619
618
astNode: this.astNode,
620
619
extensionASTNodes: this.extensionASTNodes,
@@ -644,14 +643,15 @@ export type GraphQLScalarValueParser<TInternal> = (
644
643
) => ?TInternal;
645
644
646
645
export type GraphQLScalarLiteralParser<TInternal> = (
647
- valueNode: ValueNode,
648
- variables: ?ObjMap<mixed>,
646
+ valueNode: ConstValueNode,
649
647
) => ?TInternal;
650
648
651
649
export type GraphQLScalarValueToLiteral = (
652
650
inputValue: mixed,
653
651
) => ?ConstValueNode;
654
652
653
+ export type GraphQLScalarLiteralToValue = (valueNode: ConstValueNode) => mixed;
654
+
655
655
export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
656
656
name: string,
657
657
description?: ?string,
@@ -661,9 +661,11 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
661
661
// Parses an externally provided value to use as an input.
662
662
parseValue?: GraphQLScalarValueParser<TInternal>,
663
663
// 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).
666
666
valueToLiteral?: ?GraphQLScalarValueToLiteral,
667
+ // Translates a literal (AST) to external input value.
668
+ literalToValue?: ?GraphQLScalarLiteralToValue,
667
669
extensions?: ?ReadOnlyObjMapLike<mixed>,
668
670
astNode?: ?ScalarTypeDefinitionNode,
669
671
extensionASTNodes?: ?$ReadOnlyArray<ScalarTypeExtensionNode>,
@@ -673,7 +675,6 @@ type GraphQLScalarTypeNormalizedConfig = {|
673
675
...GraphQLScalarTypeConfig<mixed, mixed>,
674
676
serialize: GraphQLScalarSerializer<mixed>,
675
677
parseValue: GraphQLScalarValueParser<mixed>,
676
- parseLiteral: GraphQLScalarLiteralParser<mixed>,
677
678
extensions: ?ReadOnlyObjMap<mixed>,
678
679
extensionASTNodes: $ReadOnlyArray<ScalarTypeExtensionNode>,
679
680
|};
@@ -1331,7 +1332,7 @@ export class GraphQLEnumType /* <T> */ {
1331
1332
return enumValue . value ;
1332
1333
}
1333
1334
1334
- parseLiteral ( valueNode : ValueNode , _variables : ? ObjMap < mixed > ) : ?any /* T */ {
1335
+ parseLiteral ( valueNode : ValueNode ) : ?any /* T */ {
1335
1336
// Note: variables will be resolved to a value before calling this function.
1336
1337
if ( valueNode . kind !== Kind . ENUM ) {
1337
1338
const valueStr = print ( valueNode ) ;
@@ -1364,6 +1365,12 @@ export class GraphQLEnumType /* <T> */ {
1364
1365
}
1365
1366
}
1366
1367
1368
+ literalToValue ( valueNode : ConstValueNode ) : mixed {
1369
+ if ( valueNode . kind === Kind . ENUM ) {
1370
+ return valueNode . value ;
1371
+ }
1372
+ }
1373
+
1367
1374
toConfig ( ) : GraphQLEnumTypeNormalizedConfig {
1368
1375
const values = keyValMap (
1369
1376
this . getValues ( ) ,
0 commit comments