1
- const printName = ( name ) => {
2
- return ' ' + name ;
3
- }
1
+ const printName = name => {
2
+ return " " + name ;
3
+ } ;
4
4
5
5
const handleNested = ( fieldsPath , fieldType ) => {
6
6
const fields = recursiveQuery ( fieldsPath ) ;
7
- return fields
8
- ? ` ${ fieldType } { ${ fields } }`
9
- : '' ;
10
- }
7
+ return fields ? ` ${ fieldType } { ${ fields } }` : "" ;
8
+ } ;
11
9
12
10
const _query = property => {
13
11
// Special cases (nested values)
14
- if ( property . name === ' allOf' ) {
12
+ if ( property . name === " allOf" ) {
15
13
if ( property . type . ofType ) {
16
- return handleNested ( property . type . ofType . fields , ' allOf' ) ;
14
+ return handleNested ( property . type . ofType . fields , " allOf" ) ;
17
15
}
18
16
19
- return handleNested ( property . type . fields , ' allOf' ) ;
17
+ return handleNested ( property . type . fields , " allOf" ) ;
20
18
}
21
19
22
- if ( property . name === ' oneOf' ) {
20
+ if ( property . name === " oneOf" ) {
23
21
if ( property . type . ofType ) {
24
- return handleNested ( property . type . ofType . fields , ' oneOf' ) ;
22
+ return handleNested ( property . type . ofType . fields , " oneOf" ) ;
25
23
}
26
- return handleNested ( property . type . fields , ' oneOf' ) ;
24
+ return handleNested ( property . type . fields , " oneOf" ) ;
27
25
}
28
26
29
27
// Base cases
30
-
31
28
if ( ! property . type ) {
32
29
return printName ( property . name ) ;
33
30
}
@@ -38,22 +35,27 @@ const _query = property => {
38
35
}
39
36
40
37
// Normal recursion
41
-
42
38
if ( property . type && property . type . fields ) {
43
- return `${ printName ( property . name ) } { ${ recursiveQuery ( property . type . fields ) } }` ;
39
+ return `${ printName ( property . name ) } { ${ recursiveQuery (
40
+ property . type . fields
41
+ ) } }`;
44
42
}
45
43
46
44
if ( property . type && property . type . typeOf && property . type . typeOf . fields ) {
47
- return `${ printName ( property . name ) } { ${ recursiveQuery ( property . type . typeOf . fields ) } }` ;
45
+ return `${ printName ( property . name ) } { ${ recursiveQuery (
46
+ property . type . typeOf . fields
47
+ ) } }`;
48
48
}
49
49
50
50
// If we reach this point, there's a problem.
51
- throw new Error ( ' No cases matched.' ) ;
52
- }
51
+ throw new Error ( " No cases matched." ) ;
52
+ } ;
53
53
54
54
const recursiveQuery = properties => {
55
- if ( properties === null ) { return ; }
55
+ if ( properties === null ) {
56
+ return ;
57
+ }
56
58
return properties . map ( property => _query ( property ) ) ;
57
- }
59
+ } ;
58
60
59
- module . exports = { rawQuery , recursiveQuery } ;
61
+ module . exports = { recursiveQuery } ;
0 commit comments