File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,28 @@ function isFragment(info, ast) {
2626 return hasFragments ( info ) && info . fragments [ ast . name . value ] && ast . kind !== 'FragmentDefinition' ;
2727}
2828
29+ function simplifyObjectValue ( objectValue ) {
30+ return objectValue . fields . reduce ( ( memo , field ) => {
31+ memo [ field . name . value ] =
32+ field . value . kind === 'IntValue' ? parseInt ( field . value . value , 10 ) :
33+ field . value . kind === 'FloatValue' ? parseFloat ( field . value . value ) :
34+ field . value . kind === 'ObjectValue' ? simplifyObjectValue ( field . value ) :
35+ field . value . value ;
36+
37+ return memo ;
38+ } , { } ) ;
39+ }
40+
2941function simplifyValue ( value , info ) {
3042 if ( value . values ) {
3143 return value . values . map ( value => simplifyValue ( value , info ) ) ;
3244 }
3345 if ( 'value' in value ) {
3446 return value . value ;
3547 }
48+ if ( value . kind === 'ObjectValue' ) {
49+ return simplifyObjectValue ( value ) ;
50+ }
3651 if ( value . name ) {
3752 return info . variableValues [ value . name . value ] ;
3853 }
Original file line number Diff line number Diff line change @@ -96,6 +96,32 @@ describe('simplifyAST', function () {
9696 } )
9797 } ) ;
9898
99+ it ( 'should simplify a basic structure with object args' , function ( ) {
100+ expect ( simplifyAST ( parse ( `
101+ {
102+ luke: human(contact: { phone: "91264646" }) {
103+ name
104+ }
105+ }
106+ ` ) ) ) . to . deep . equal ( {
107+ args : { } ,
108+ fields : {
109+ luke : {
110+ key : "human" ,
111+ args : {
112+ contact : { phone : "91264646" }
113+ } ,
114+ fields : {
115+ name : {
116+ args : { } ,
117+ fields : { }
118+ }
119+ }
120+ }
121+ }
122+ } )
123+ } ) ;
124+
99125 it ( 'should simplify a basic structure with nested array args' , function ( ) {
100126 expect ( simplifyAST ( parse ( `
101127 {
You can’t perform that action at this time.
0 commit comments