88 */
99
1010import invariant from '../jsutils/invariant' ;
11- import isNullish from '../jsutils/isNullish ' ;
11+ import isInvalid from '../jsutils/isInvalid ' ;
1212import type { ObjMap } from '../jsutils/ObjMap' ;
1313import * as Kind from '../language/kinds' ;
1414import { assertValidName } from '../utilities/assertValidName' ;
15- import { scalarValueFromAST } from '../utilities/scalarValueFromAST ' ;
15+ import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped ' ;
1616import type {
1717 ScalarTypeDefinitionNode ,
1818 ObjectTypeDefinitionNode ,
@@ -340,30 +340,30 @@ export class GraphQLScalarType {
340340 }
341341
342342 // Determines if an internal value is valid for this type.
343- // Equivalent to checking for if the parsedValue is nullish.
344343 isValidValue(value: mixed): boolean {
345- return ! isNullish ( this . parseValue ( value ) ) ;
344+ return ! isInvalid ( this . parseValue ( value ) ) ;
346345 }
347346
348347 // Parses an externally provided value to use as an input.
349348 parseValue(value: mixed): mixed {
350349 const parser = this . _scalarConfig . parseValue ;
351- if ( isNullish ( value ) ) {
350+ if ( isInvalid ( value ) ) {
352351 return undefined ;
353352 }
354353 return parser ? parser ( value ) : value ;
355354 }
356355
357356 // Determines if an internal value is valid for this type.
358- // Equivalent to checking for if the parsedLiteral is nullish.
359- isValidLiteral(valueNode: ValueNode): boolean {
360- return ! isNullish ( this . parseLiteral ( valueNode ) ) ;
357+ isValidLiteral(valueNode: ValueNode, variables: ?ObjMap< mixed > ): boolean {
358+ return ! isInvalid ( this . parseLiteral ( valueNode , variables ) ) ;
361359 }
362360
363361 // Parses an externally provided literal value to use as an input.
364- parseLiteral(valueNode: ValueNode): mixed {
362+ parseLiteral(valueNode: ValueNode, variables: ?ObjMap < mixed > ): mixed {
365363 const parser = this . _scalarConfig . parseLiteral ;
366- return ( parser || scalarValueFromAST ) ( valueNode ) ;
364+ return parser ?
365+ parser ( valueNode , variables ) :
366+ valueFromASTUntyped ( valueNode , variables ) ;
367367 }
368368
369369 toString(): string {
@@ -385,7 +385,10 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {
385385 astNode ?: ?ScalarTypeDefinitionNode ;
386386 serialize : ( value : mixed ) => ?TExternal ;
387387 parseValue ?: ( value : mixed ) => ?TInternal ;
388- parseLiteral ?: ( valueNode : ValueNode ) => ?TInternal ;
388+ parseLiteral ?: (
389+ valueNode : ValueNode ,
390+ variables : ?ObjMap < mixed > ,
391+ ) => ?TInternal ;
389392} ;
390393
391394
@@ -956,12 +959,14 @@ export class GraphQLEnumType/* <T> */ {
956959 }
957960 }
958961
959- isValidLiteral ( valueNode : ValueNode ) : boolean {
962+ isValidLiteral ( valueNode : ValueNode , _variables : ?ObjMap < mixed > ) : boolean {
963+ // Note: variables will be resolved to a value before calling this function.
960964 return valueNode . kind === Kind . ENUM &&
961965 this . _getNameLookup ( ) [ valueNode . value ] !== undefined ;
962966 }
963967
964- parseLiteral ( valueNode : ValueNode ) : ?any / * T * / {
968+ parseLiteral ( valueNode : ValueNode , _variables : ?ObjMap < mixed > ) : ?any /* T */ {
969+ // Note: variables will be resolved to a value before calling this function.
965970 if ( valueNode . kind === Kind . ENUM ) {
966971 const enumValue = this . _getNameLookup ( ) [ valueNode . value ] ;
967972 if ( enumValue ) {
0 commit comments