@@ -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 ] ) ;
@@ -735,4 +735,104 @@ describe('visitWithTypeInfo', () => {
735735 [ 'leave' , 'Document' , null , 'undefined' , 'undefined' ] ,
736736 ] ) ;
737737 } ) ;
738+
739+ it ( 'supports traversals of object literals of custom scalars' , ( ) => {
740+ const schema = buildSchema ( `
741+ scalar GeoPoint
742+ ` ) ;
743+ const ast = parseValue ( '{x: 4.0, y: 2.0}' ) ;
744+ const scalarType = schema . getType ( 'GeoPoint' ) ;
745+ invariant ( scalarType != null ) ;
746+
747+ const typeInfo = new TypeInfo ( schema , scalarType ) ;
748+
749+ const visited : Array < any > = [ ] ;
750+ visit (
751+ ast ,
752+ visitWithTypeInfo ( typeInfo , {
753+ enter ( node ) {
754+ const type = typeInfo . getInputType ( ) ;
755+ visited . push ( [
756+ 'enter' ,
757+ node . kind ,
758+ node . kind === 'Name' ? node . value : null ,
759+ String ( type ) ,
760+ ] ) ;
761+ } ,
762+ leave ( node ) {
763+ const type = typeInfo . getInputType ( ) ;
764+ visited . push ( [
765+ 'leave' ,
766+ node . kind ,
767+ node . kind === 'Name' ? node . value : null ,
768+ String ( type ) ,
769+ ] ) ;
770+ } ,
771+ } ) ,
772+ ) ;
773+
774+ expect ( visited ) . to . deep . equal ( [
775+ // Everything within ObjectValue should have type: undefined since the
776+ // contents of custom scalars aren't part of GraphQL schema definitions.
777+ [ 'enter' , 'ObjectValue' , null , 'GeoPoint' ] ,
778+ [ 'enter' , 'ObjectField' , null , 'undefined' ] ,
779+ [ 'enter' , 'Name' , 'x' , 'undefined' ] ,
780+ [ 'leave' , 'Name' , 'x' , 'undefined' ] ,
781+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
782+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
783+ [ 'leave' , 'ObjectField' , null , 'undefined' ] ,
784+ [ 'enter' , 'ObjectField' , null , 'undefined' ] ,
785+ [ 'enter' , 'Name' , 'y' , 'undefined' ] ,
786+ [ 'leave' , 'Name' , 'y' , 'undefined' ] ,
787+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
788+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
789+ [ 'leave' , 'ObjectField' , null , 'undefined' ] ,
790+ [ 'leave' , 'ObjectValue' , null , 'GeoPoint' ] ,
791+ ] ) ;
792+ } ) ;
793+
794+ it ( 'supports traversals of list literals of custom scalars' , ( ) => {
795+ const schema = buildSchema ( `
796+ scalar GeoPoint
797+ ` ) ;
798+ const ast = parseValue ( '[4.0, 2.0]' ) ;
799+ const scalarType = schema . getType ( 'GeoPoint' ) ;
800+ invariant ( scalarType != null ) ;
801+
802+ const typeInfo = new TypeInfo ( schema , scalarType ) ;
803+
804+ const visited : Array < any > = [ ] ;
805+ visit (
806+ ast ,
807+ visitWithTypeInfo ( typeInfo , {
808+ enter ( node ) {
809+ const type = typeInfo . getInputType ( ) ;
810+ visited . push ( [
811+ 'enter' ,
812+ node . kind ,
813+ node . kind === 'Name' ? node . value : null ,
814+ String ( type ) ,
815+ ] ) ;
816+ } ,
817+ leave ( node ) {
818+ const type = typeInfo . getInputType ( ) ;
819+ visited . push ( [
820+ 'leave' ,
821+ node . kind ,
822+ node . kind === 'Name' ? node . value : null ,
823+ String ( type ) ,
824+ ] ) ;
825+ } ,
826+ } ) ,
827+ ) ;
828+
829+ expect ( visited ) . to . deep . equal ( [
830+ [ 'enter' , 'ListValue' , null , 'undefined' ] ,
831+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
832+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
833+ [ 'enter' , 'FloatValue' , null , 'undefined' ] ,
834+ [ 'leave' , 'FloatValue' , null , 'undefined' ] ,
835+ [ 'leave' , 'ListValue' , null , 'undefined' ] ,
836+ ] ) ;
837+ } ) ;
738838} ) ;
0 commit comments