1
- import { parse } from " graphql/language/parser" ;
2
- import Logger from " ./logger" ;
3
- import Model from " ./model" ;
4
- import { print } from " graphql/language/printer" ;
5
- import { Arguments , Data , Field } from " ./interfaces" ;
6
- import { downcaseFirstLetter , upcaseFirstLetter } from " ./utils" ;
7
- import gql from " graphql-tag" ;
1
+ import { parse } from ' graphql/language/parser' ;
2
+ import Logger from ' ./logger' ;
3
+ import Model from ' ./model' ;
4
+ import { print } from ' graphql/language/printer' ;
5
+ import { Arguments , Data , Field } from ' ./interfaces' ;
6
+ import { downcaseFirstLetter , upcaseFirstLetter } from ' ./utils' ;
7
+ import gql from ' graphql-tag' ;
8
8
9
9
const inflection = require ( 'inflection' ) ;
10
10
@@ -31,7 +31,6 @@ export default class QueryBuilder {
31
31
return print ( parse ( query ) ) ;
32
32
}
33
33
34
-
35
34
/**
36
35
* Generates the arguments string for a graphql query based on a given map.
37
36
*
@@ -51,7 +50,7 @@ export default class QueryBuilder {
51
50
* @param {boolean } allowIdFields If true, ID fields will be included in the arguments list
52
51
* @returns {String }
53
52
*/
54
- private buildArguments ( args ?: Arguments , signature : boolean = false , allowIdFields : boolean = true ) : string {
53
+ private buildArguments ( args ?: Arguments , signature : boolean = false , allowIdFields : boolean = true ) : string {
55
54
if ( args === null ) return '' ;
56
55
57
56
let returnValue : string = '' ;
@@ -92,8 +91,6 @@ export default class QueryBuilder {
92
91
return returnValue ;
93
92
}
94
93
95
-
96
-
97
94
/**
98
95
* Builds a field for the GraphQL query and a specific model
99
96
*
@@ -137,14 +134,13 @@ export default class QueryBuilder {
137
134
}
138
135
}
139
136
140
-
141
137
/**
142
138
*
143
139
* @param {Model } model
144
140
* @param {Model } rootModel
145
141
* @returns {Array<String> }
146
142
*/
147
- private buildRelationsQuery ( model : ( null | Model ) , rootModel ?: Model ) {
143
+ private buildRelationsQuery ( model : ( null | Model ) , rootModel ?: Model ) {
148
144
if ( model === null ) return '' ;
149
145
150
146
const relationQueries : Array < string > = [ ] ;
@@ -159,9 +155,7 @@ export default class QueryBuilder {
159
155
return relationQueries ;
160
156
}
161
157
162
-
163
-
164
- public buildQuery ( type : string , name ?: string , args ?: Arguments , model ?: ( Model | null | string ) , fields ?: string , addModelToArgs :boolean = false , multiple ?: boolean ) {
158
+ public buildQuery ( type : string , name ?: string , args ?: Arguments , model ?: ( Model | null | string ) , fields ?: string , addModelToArgs : boolean = false , multiple ?: boolean ) {
165
159
model = model ? this . getModel ( model ) : null ;
166
160
167
161
if ( ! args ) args = { } ;
@@ -172,16 +166,14 @@ export default class QueryBuilder {
172
166
if ( ! name && model ) name = ( multiple ? model . pluralName : model . singularName ) ;
173
167
if ( ! name ) throw new Error ( "Can't determine name for the query! Please provide either name or model" ) ;
174
168
175
-
176
- const query :string =
169
+ const query : string =
177
170
`${ type } ${ upcaseFirstLetter ( name ) } ${ this . buildArguments ( args , true ) } {\n` +
178
171
` ${ model ? this . buildField ( model , multiple , args , model , name , true ) : fields } \n` +
179
172
`}` ;
180
173
181
174
return gql ( query ) ;
182
175
}
183
176
184
-
185
177
/**
186
178
* Transforms outgoing data. Use for variables param.
187
179
*
0 commit comments