@@ -18,6 +18,10 @@ var graphql = require('graphql'),
18
18
* @param dict dictionary of arguments
19
19
*/
20
20
getArgsToVarsStr = ( dict ) => {
21
+ if ( typeof dict !== 'object' ) {
22
+ return '' ;
23
+ }
24
+
21
25
return Object . entries ( dict )
22
26
. map ( ( [ varName , arg ] ) => { return `${ arg . name } : $${ varName } ` ; } )
23
27
. join ( ', ' ) ;
@@ -102,6 +106,10 @@ var graphql = require('graphql'),
102
106
* @param dict dictionary of arguments
103
107
*/
104
108
getVarsToTypesStr = ( dict ) => {
109
+ if ( typeof dict !== 'object' ) {
110
+ return '' ;
111
+ }
112
+
105
113
return Object . entries ( dict )
106
114
. map ( ( [ varName , arg ] ) => {
107
115
return `$${ varName } : ${ arg . type } ` ;
@@ -151,7 +159,7 @@ function resolveVariableType (type, gqlSchema, stack = 0, stackLimit = 4) {
151
159
152
160
if ( graphql . isInputObjectType ( argType ) ) {
153
161
fields = argType . getFields ( ) ;
154
- Object . keys ( fields ) . forEach ( ( field ) => {
162
+ typeof fields === 'object' && Object . keys ( fields ) . forEach ( ( field ) => {
155
163
if ( fields [ field ] . type === type ) {
156
164
fieldObj [ field ] = '<Same as ' + type + '>' ;
157
165
}
@@ -241,7 +249,7 @@ module.exports = {
241
249
}
242
250
crossReferenceKeyList [ crossReferenceKey ] = true ;
243
251
244
- let childKeys = Object . keys ( curType . getFields ( ) ) ;
252
+ let childKeys = Object . keys ( curType . getFields ( ) || { } ) ;
245
253
childQuery = childKeys
246
254
. filter ( ( fieldName ) => {
247
255
/* Exclude deprecated fields */
@@ -282,7 +290,7 @@ module.exports = {
282
290
for ( let i = 0 , len = types . length ; i < len ; i ++ ) {
283
291
const valueTypeName = types [ i ] ,
284
292
valueType = gqlSchema . getType ( valueTypeName ) ,
285
- unionChildQuery = Object . keys ( valueType . getFields ( ) )
293
+ unionChildQuery = Object . keys ( valueType . getFields ( ) || { } )
286
294
. map ( ( cur ) => {
287
295
// Don't genrate query fields that have self referencing
288
296
if ( cur === curName ) {
@@ -330,7 +338,7 @@ module.exports = {
330
338
console . log ( '[gqlg warning]:' , 'description is required' ) ;
331
339
}
332
340
333
- Object . keys ( obj ) . forEach ( ( type ) => {
341
+ typeof obj === 'object' && Object . keys ( obj ) . forEach ( ( type ) => {
334
342
335
343
let field ,
336
344
newDescription ;
@@ -358,9 +366,12 @@ module.exports = {
358
366
359
367
/* Generate variables Object from argumentDict */
360
368
var variables = { } ;
361
- Object . entries ( queryResult . argumentsDict ) . map ( ( [ varName , arg ] ) => {
362
- variables [ varName ] = resolveVariableType ( arg . type , gqlSchema , 0 , stackLimit ) ;
363
- } ) ;
369
+
370
+ if ( typeof queryResult . argumentsDict === 'object' ) {
371
+ Object . entries ( queryResult . argumentsDict ) . map ( ( [ varName , arg ] ) => {
372
+ variables [ varName ] = resolveVariableType ( arg . type , gqlSchema , 0 , stackLimit ) ;
373
+ } ) ;
374
+ }
364
375
365
376
let query = queryResult . queryStr ;
366
377
// here the `description` is used to construct the actual queries
0 commit comments