@@ -2,28 +2,28 @@ const printName = (name) => {
2
2
return ' ' + name ;
3
3
}
4
4
5
+ const handleNested = ( fieldsPath , fieldType ) => {
6
+ const fields = recursiveQuery ( fieldsPath ) ;
7
+ return fields
8
+ ? ` ${ fieldType } { ${ fields } }`
9
+ : '' ;
10
+ }
11
+
5
12
const _query = property => {
6
13
// Special cases (nested values)
7
14
if ( property . name === 'allOf' ) {
8
15
if ( property . type . ofType ) {
9
- const fields = recursiveQuery ( property . type . ofType . fields ) ;
10
- return fields
11
- ?' allOf { ' + fields + ' }'
12
- : '' ;
16
+ return handleNested ( property . type . ofType . fields , 'allOf' ) ;
13
17
}
14
- const fields = recursiveQuery ( property . type . fields ) ;
15
- return fields
16
- ? ' allOf { ' + fields + ' }'
17
- : ''
18
+
19
+ return handleNested ( property . type . fields , 'allOf' ) ;
18
20
}
19
21
20
22
if ( property . name === 'oneOf' ) {
21
23
if ( property . type . ofType ) {
22
- const fields = recursiveQuery ( property . type . ofType . fields ) ;
23
- return fields ? ' oneOf { ' + fields + ' }' : '' ;
24
+ return handleNested ( property . type . ofType . fields , 'oneOf' ) ;
24
25
}
25
- const fields = recursiveQuery ( property . type . fields ) ;
26
- return fields ? ' oneOf { ' + fields + ' }' : '' ;
26
+ return handleNested ( property . type . fields , 'oneOf' ) ;
27
27
}
28
28
29
29
// Base cases
@@ -46,7 +46,7 @@ const _query = property => {
46
46
if ( property . type && property . type . typeOf && property . type . typeOf . fields ) {
47
47
return `${ printName ( property . name ) } { ${ recursiveQuery ( property . type . typeOf . fields ) } }` ;
48
48
}
49
-
49
+
50
50
// If we reach this point, there's a problem.
51
51
throw new Error ( 'No cases matched.' ) ;
52
52
}
0 commit comments