@@ -390,10 +390,10 @@ describe('visitWithTypeInfo', () => {
390390 [ 'enter' , 'ObjectField' , null , '[String]' ] ,
391391 [ 'enter' , 'Name' , 'stringListField' , '[String]' ] ,
392392 [ 'leave' , 'Name' , 'stringListField' , '[String]' ] ,
393- [ 'enter' , 'ListValue' , null , 'String' ] ,
393+ [ 'enter' , 'ListValue' , null , 'String' /* the item type, not list type */ ] ,
394394 [ 'enter' , 'StringValue' , null , 'String' ] ,
395395 [ 'leave' , 'StringValue' , null , 'String' ] ,
396- [ 'leave' , 'ListValue' , null , 'String' ] ,
396+ [ 'leave' , 'ListValue' , null , 'String' /* the item type, not list type */ ] ,
397397 [ 'leave' , 'ObjectField' , null , '[String]' ] ,
398398 [ 'leave' , 'ObjectValue' , null , 'ComplexInput' ] ,
399399 ] ) ;
@@ -457,4 +457,104 @@ describe('visitWithTypeInfo', () => {
457457 [ 'leave' , 'SelectionSet' , null , 'Human' , 'Human' ] ,
458458 ] ) ;
459459 } ) ;
460+
461+ it ( 'supports traversals of object literals of custom scalars' , ( ) => {
462+ const schema = buildSchema ( `
463+ scalar GeoPoint
464+ ` ) ;
465+ const ast = parseValue ( '{x: 4.0, y: 2.0}' ) ;
466+ const scalarType = schema . getType ( 'GeoPoint' ) ;
467+ invariant ( scalarType != null ) ;
468+
469+ const typeInfo = new TypeInfo ( schema , scalarType ) ;
470+
471+ const visited : Array < any > = [ ] ;
472+ visit (
473+ ast ,
474+ visitWithTypeInfo ( typeInfo , {
475+ enter ( node ) {
476+ const type = typeInfo . getInputType ( ) ;
477+ visited . push ( [
478+ 'enter' ,
479+ node . kind ,
480+ node . kind === 'Name' ? node . value : null ,
481+ String ( type ) ,
482+ ] ) ;
483+ } ,
484+ leave ( node ) {
485+ const type = typeInfo . getInputType ( ) ;
486+ visited . push ( [
487+ 'leave' ,
488+ node . kind ,
489+ node . kind === 'Name' ? node . value : null ,
490+ String ( type ) ,
491+ ] ) ;
492+ } ,
493+ } ) ,
494+ ) ;
495+
496+ expect ( visited ) . to . deep . equal ( [
497+ // Everything within ObjectValue should have type: undefined since the
498+ // contents of custom scalars aren't part of GraphQL schema definitions.
499+ [ 'enter' , 'ObjectValue' , null , 'GeoPoint' ] ,
500+ [ 'enter' , 'ObjectField' , null , 'undefined' ] ,
501+ [ 'enter' , 'Name' , 'x' , 'undefined' ] ,
502+ [ 'leave' , 'Name' , 'x' , 'undefined' ] ,
503+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
504+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
505+ [ 'leave' , 'ObjectField' , null , 'undefined' ] ,
506+ [ 'enter' , 'ObjectField' , null , 'undefined' ] ,
507+ [ 'enter' , 'Name' , 'y' , 'undefined' ] ,
508+ [ 'leave' , 'Name' , 'y' , 'undefined' ] ,
509+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
510+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
511+ [ 'leave' , 'ObjectField' , null , 'undefined' ] ,
512+ [ 'leave' , 'ObjectValue' , null , 'GeoPoint' ] ,
513+ ] ) ;
514+ } ) ;
515+
516+ it ( 'supports traversals of list literals of custom scalars' , ( ) => {
517+ const schema = buildSchema ( `
518+ scalar GeoPoint
519+ ` ) ;
520+ const ast = parseValue ( '[4.0, 2.0]' ) ;
521+ const scalarType = schema . getType ( 'GeoPoint' ) ;
522+ invariant ( scalarType != null ) ;
523+
524+ const typeInfo = new TypeInfo ( schema , scalarType ) ;
525+
526+ const visited : Array < any > = [ ] ;
527+ visit (
528+ ast ,
529+ visitWithTypeInfo ( typeInfo , {
530+ enter ( node ) {
531+ const type = typeInfo . getInputType ( ) ;
532+ visited . push ( [
533+ 'enter' ,
534+ node . kind ,
535+ node . kind === 'Name' ? node . value : null ,
536+ String ( type ) ,
537+ ] ) ;
538+ } ,
539+ leave ( node ) {
540+ const type = typeInfo . getInputType ( ) ;
541+ visited . push ( [
542+ 'leave' ,
543+ node . kind ,
544+ node . kind === 'Name' ? node . value : null ,
545+ String ( type ) ,
546+ ] ) ;
547+ } ,
548+ } ) ,
549+ ) ;
550+
551+ expect ( visited ) . to . deep . equal ( [
552+ [ 'enter' , 'ListValue' , null , 'undefined' ] ,
553+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
554+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
555+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
556+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
557+ [ 'leave' , 'ListValue' , null , 'undefined' ] ,
558+ ] ) ;
559+ } ) ;
460560} ) ;
0 commit comments