@@ -451,10 +451,10 @@ describe('visitWithTypeInfo', () => {
451451 [ 'enter' , 'ObjectField' , null , '[String]' ] ,
452452 [ 'enter' , 'Name' , 'stringListField' , '[String]' ] ,
453453 [ 'leave' , 'Name' , 'stringListField' , '[String]' ] ,
454- [ 'enter' , 'ListValue' , null , 'String' ] ,
454+ [ 'enter' , 'ListValue' , null , 'String' /* the item type, not list type */ ] ,
455455 [ 'enter' , 'StringValue' , null , 'String' ] ,
456456 [ 'leave' , 'StringValue' , null , 'String' ] ,
457- [ 'leave' , 'ListValue' , null , 'String' ] ,
457+ [ 'leave' , 'ListValue' , null , 'String' /* the item type, not list type */ ] ,
458458 [ 'leave' , 'ObjectField' , null , '[String]' ] ,
459459 [ 'leave' , 'ObjectValue' , null , 'ComplexInput' ] ,
460460 ] ) ;
@@ -519,6 +519,106 @@ describe('visitWithTypeInfo', () => {
519519 ] ) ;
520520 } ) ;
521521
522+ it ( 'supports traversals of object literals of custom scalars' , ( ) => {
523+ const schema = buildSchema ( `
524+ scalar GeoPoint
525+ ` ) ;
526+ const ast = parseValue ( '{x: 4.0, y: 2.0}' ) ;
527+ const scalarType = schema . getType ( 'GeoPoint' ) ;
528+ invariant ( scalarType != null ) ;
529+
530+ const typeInfo = new TypeInfo ( schema , scalarType ) ;
531+
532+ const visited : Array < any > = [ ] ;
533+ visit (
534+ ast ,
535+ visitWithTypeInfo ( typeInfo , {
536+ enter ( node ) {
537+ const type = typeInfo . getInputType ( ) ;
538+ visited . push ( [
539+ 'enter' ,
540+ node . kind ,
541+ node . kind === 'Name' ? node . value : null ,
542+ String ( type ) ,
543+ ] ) ;
544+ } ,
545+ leave ( node ) {
546+ const type = typeInfo . getInputType ( ) ;
547+ visited . push ( [
548+ 'leave' ,
549+ node . kind ,
550+ node . kind === 'Name' ? node . value : null ,
551+ String ( type ) ,
552+ ] ) ;
553+ } ,
554+ } ) ,
555+ ) ;
556+
557+ expect ( visited ) . to . deep . equal ( [
558+ // Everything within ObjectValue should have type: undefined since the
559+ // contents of custom scalars aren't part of GraphQL schema definitions.
560+ [ 'enter' , 'ObjectValue' , null , 'GeoPoint' ] ,
561+ [ 'enter' , 'ObjectField' , null , 'undefined' ] ,
562+ [ 'enter' , 'Name' , 'x' , 'undefined' ] ,
563+ [ 'leave' , 'Name' , 'x' , 'undefined' ] ,
564+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
565+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
566+ [ 'leave' , 'ObjectField' , null , 'undefined' ] ,
567+ [ 'enter' , 'ObjectField' , null , 'undefined' ] ,
568+ [ 'enter' , 'Name' , 'y' , 'undefined' ] ,
569+ [ 'leave' , 'Name' , 'y' , 'undefined' ] ,
570+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
571+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
572+ [ 'leave' , 'ObjectField' , null , 'undefined' ] ,
573+ [ 'leave' , 'ObjectValue' , null , 'GeoPoint' ] ,
574+ ] ) ;
575+ } ) ;
576+
577+ it ( 'supports traversals of list literals of custom scalars' , ( ) => {
578+ const schema = buildSchema ( `
579+ scalar GeoPoint
580+ ` ) ;
581+ const ast = parseValue ( '[4.0, 2.0]' ) ;
582+ const scalarType = schema . getType ( 'GeoPoint' ) ;
583+ invariant ( scalarType != null ) ;
584+
585+ const typeInfo = new TypeInfo ( schema , scalarType ) ;
586+
587+ const visited : Array < any > = [ ] ;
588+ visit (
589+ ast ,
590+ visitWithTypeInfo ( typeInfo , {
591+ enter ( node ) {
592+ const type = typeInfo . getInputType ( ) ;
593+ visited . push ( [
594+ 'enter' ,
595+ node . kind ,
596+ node . kind === 'Name' ? node . value : null ,
597+ String ( type ) ,
598+ ] ) ;
599+ } ,
600+ leave ( node ) {
601+ const type = typeInfo . getInputType ( ) ;
602+ visited . push ( [
603+ 'leave' ,
604+ node . kind ,
605+ node . kind === 'Name' ? node . value : null ,
606+ String ( type ) ,
607+ ] ) ;
608+ } ,
609+ } ) ,
610+ ) ;
611+
612+ expect ( visited ) . to . deep . equal ( [
613+ [ 'enter' , 'ListValue' , null , 'undefined' ] ,
614+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
615+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
616+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
617+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
618+ [ 'leave' , 'ListValue' , null , 'undefined' ] ,
619+ ] ) ;
620+ } ) ;
621+
522622 it ( 'supports traversals of fragment arguments' , ( ) => {
523623 const typeInfo = new TypeInfo ( testSchema ) ;
524624
0 commit comments