3737use GraphQL \Type \Definition \NullableType ;
3838use GraphQL \Type \Definition \ScalarType ;
3939use GraphQL \Type \Definition \Type ;
40+ use GraphQL \Type \Schema ;
4041
4142/**
4243 * Various utilities dealing with AST.
@@ -307,7 +308,7 @@ public static function astFromValue($value, InputType $type): ?ValueNode
307308 *
308309 * @api
309310 */
310- public static function valueFromAST (?ValueNode $ valueNode , Type $ type , ?array $ variables = null )
311+ public static function valueFromAST (?ValueNode $ valueNode , Type $ type , ?array $ variables = null , ? Schema $ schema = null )
311312 {
312313 $ undefined = Utils::undefined ();
313314
@@ -323,7 +324,7 @@ public static function valueFromAST(?ValueNode $valueNode, Type $type, ?array $v
323324 return $ undefined ;
324325 }
325326
326- return self ::valueFromAST ($ valueNode , $ type ->getWrappedType (), $ variables );
327+ return self ::valueFromAST ($ valueNode , $ type ->getWrappedType (), $ variables, $ schema );
327328 }
328329
329330 if ($ valueNode instanceof NullValueNode) {
@@ -362,7 +363,7 @@ public static function valueFromAST(?ValueNode $valueNode, Type $type, ?array $v
362363
363364 $ coercedValues [] = null ;
364365 } else {
365- $ itemValue = self ::valueFromAST ($ itemNode , $ itemType , $ variables );
366+ $ itemValue = self ::valueFromAST ($ itemNode , $ itemType , $ variables, $ schema );
366367 if ($ undefined === $ itemValue ) {
367368 // Invalid: intentionally return no value.
368369 return $ undefined ;
@@ -375,7 +376,7 @@ public static function valueFromAST(?ValueNode $valueNode, Type $type, ?array $v
375376 return $ coercedValues ;
376377 }
377378
378- $ coercedValue = self ::valueFromAST ($ valueNode , $ itemType , $ variables );
379+ $ coercedValue = self ::valueFromAST ($ valueNode , $ itemType , $ variables, $ schema );
379380 if ($ undefined === $ coercedValue ) {
380381 // Invalid: intentionally return no value.
381382 return $ undefined ;
@@ -416,7 +417,8 @@ public static function valueFromAST(?ValueNode $valueNode, Type $type, ?array $v
416417 $ fieldValue = self ::valueFromAST (
417418 $ fieldNode ->value ,
418419 $ field ->getType (),
419- $ variables
420+ $ variables ,
421+ $ schema ,
420422 );
421423
422424 if ($ undefined === $ fieldValue ) {
@@ -439,6 +441,16 @@ public static function valueFromAST(?ValueNode $valueNode, Type $type, ?array $v
439441 }
440442
441443 assert ($ type instanceof ScalarType, 'only remaining option ' );
444+ $ typeName = $ type ->name ;
445+
446+ // Account for type loader returning a different scalar instance than
447+ // the built-in singleton used in field definitions. Resolve the actual
448+ // type from the schema to ensure the correct parseLiteral() is called.
449+ if ($ schema !== null && Type::isBuiltInScalarName ($ typeName )) {
450+ $ schemaType = $ schema ->getType ($ typeName );
451+ assert ($ schemaType instanceof ScalarType, "Schema must provide a ScalarType for built-in scalar \"{$ typeName }\". " );
452+ $ type = $ schemaType ;
453+ }
442454
443455 // Scalars fulfill parsing a literal value via parseLiteral().
444456 // Invalid values represent a failure to parse correctly, in which case
0 commit comments