4
4
import dox from 'dox' ;
5
5
import fs from 'fs' ;
6
6
import path from 'path' ;
7
- import { GraphQLJSON , upperFirst , TypeComposer , type ComposeFieldConfigMap } from 'graphql-compose' ;
8
7
import {
9
- GraphQLString ,
10
- GraphQLFloat ,
11
- GraphQLBoolean ,
12
- GraphQLObjectType ,
13
- GraphQLEnumType ,
14
- GraphQLNonNull ,
15
- } from 'graphql-compose/lib/graphql' ;
16
- import type {
17
- GraphQLArgumentConfig ,
18
- GraphQLFieldConfigMap ,
19
- GraphQLFieldConfigArgumentMap ,
20
- GraphQLInputType ,
21
- } from 'graphql-compose/lib/graphql' ;
8
+ upperFirst ,
9
+ TypeComposer ,
10
+ EnumTypeComposer ,
11
+ type ComposeFieldConfigMap ,
12
+ type ComposeFieldConfigArgumentMap ,
13
+ type ComposeArgumentConfig ,
14
+ type ComposeArgumentConfigAsObject ,
15
+ } from 'graphql-compose' ;
22
16
import { reorderKeys } from './utils' ;
23
17
24
18
export type ElasticParamConfigT = {
@@ -67,7 +61,7 @@ export type ElasticApiParserOptsT = {
67
61
68
62
export default class ElasticApiParser {
69
63
cachedEnums : {
70
- [ fieldName : string ] : { [ valsStringified : string ] : GraphQLEnumType } ,
64
+ [ fieldName : string ] : { [ valsStringified : string ] : EnumTypeComposer } ,
71
65
} ;
72
66
73
67
apiVersion: string ;
@@ -258,7 +252,7 @@ export default class ElasticApiParser {
258
252
return result ;
259
253
}
260
254
261
- generateFieldMap ( ) : GraphQLFieldConfigMap < * , * > {
255
+ generateFieldMap ( ) : ComposeFieldConfigMap < any , any > {
262
256
const result = { } ;
263
257
Object . keys ( this . parsedSource ) . forEach ( methodName => {
264
258
result [ methodName ] = this . generateFieldConfig ( methodName ) ;
@@ -293,7 +287,7 @@ export default class ElasticApiParser {
293
287
const argMap = this . settingsToArgMap ( argsSettings , argsDescriptions ) ;
294
288
295
289
return {
296
- type : GraphQLJSON ,
290
+ type : 'JSON' ,
297
291
description ,
298
292
args : argMap ,
299
293
// eslint-disable-next-line no-unused-vars
@@ -322,10 +316,11 @@ export default class ElasticApiParser {
322
316
paramCfg : ElasticParamConfigT ,
323
317
fieldName : string ,
324
318
description ?: ?string
325
- ) : GraphQLArgumentConfig {
326
- const result : GraphQLArgumentConfig = {
319
+ ) : ComposeArgumentConfig {
320
+ const result : { ... ComposeArgumentConfigAsObject } = {
327
321
type : this . paramTypeToGraphQL ( paramCfg , fieldName ) ,
328
322
} ;
323
+
329
324
if ( paramCfg . default ) {
330
325
result . defaultValue = paramCfg . default ;
331
326
} else if ( fieldName === 'format' ) {
@@ -336,40 +331,40 @@ export default class ElasticApiParser {
336
331
result . description = description ;
337
332
}
338
333
339
- return result ;
334
+ return ( result : any ) ;
340
335
}
341
336
342
- paramTypeToGraphQL ( paramCfg : ElasticParamConfigT , fieldName : string ) : GraphQLInputType {
337
+ paramTypeToGraphQL ( paramCfg : ElasticParamConfigT , fieldName : string ) : EnumTypeComposer | string {
343
338
switch ( paramCfg . type ) {
344
339
case 'string' :
345
- return GraphQLString ;
340
+ return 'String' ;
346
341
case 'boolean' :
347
- return GraphQLBoolean ;
342
+ return 'Boolean' ;
348
343
case 'number' :
349
- return GraphQLFloat ;
344
+ return 'Float' ;
350
345
case 'time' :
351
- return GraphQLString ;
346
+ return 'String' ;
352
347
case 'list' :
353
- return GraphQLJSON ;
348
+ return 'JSON' ;
354
349
case 'enum' :
355
350
if ( Array . isArray ( paramCfg . options ) ) {
356
351
return this . getEnumType ( fieldName , paramCfg . options ) ;
357
352
}
358
- return GraphQLString ;
353
+ return 'String' ;
359
354
case undefined :
360
355
// some fields may not have type definition in API file,
361
356
// eg '@param {anything} params.operationThreading - ?'
362
- return GraphQLJSON ;
357
+ return 'JSON' ;
363
358
default :
364
359
// console.log(
365
360
// // eslint-disable-line
366
361
// `New type '${paramCfg.type}' in elastic params setting for field ${fieldName}.`
367
362
// );
368
- return GraphQLJSON ;
363
+ return 'JSON' ;
369
364
}
370
365
}
371
366
372
- getEnumType ( fieldName : string , vals : mixed [ ] ) : GraphQLEnumType {
367
+ getEnumType ( fieldName : string , vals : mixed [ ] ) : EnumTypeComposer {
373
368
const key = fieldName ;
374
369
const subKey = JSON . stringify ( vals ) ;
375
370
@@ -403,7 +398,7 @@ export default class ElasticApiParser {
403
398
if ( postfix === 0 ) postfix = '' ;
404
399
else postfix = `_${ postfix } ` ;
405
400
406
- this . cachedEnums [ key ] [ subKey ] = new GraphQLEnumType ( {
401
+ this . cachedEnums [ key ] [ subKey ] = EnumTypeComposer . create ( {
407
402
name : `${ this . prefix } Enum_${ upperFirst ( fieldName ) } ${ postfix } ` ,
408
403
values,
409
404
} ) ;
@@ -415,13 +410,13 @@ export default class ElasticApiParser {
415
410
settingsToArgMap (
416
411
settings : ?ElasticCaSettingsT ,
417
412
descriptions : ElasticParsedArgsDescriptionsT = { }
418
- ) : GraphQLFieldConfigArgumentMap {
413
+ ) : ComposeFieldConfigArgumentMap {
419
414
const result = { } ;
420
415
const { params, urls, url, method, needBody } = settings || { } ;
421
416
422
417
if ( method === 'POST' || method === 'PUT' ) {
423
418
result . body = {
424
- type : needBody ? new GraphQLNonNull ( GraphQLJSON ) : GraphQLJSON ,
419
+ type : needBody ? 'JSON!' : 'JSON' ,
425
420
} ;
426
421
}
427
422
@@ -452,7 +447,7 @@ export default class ElasticApiParser {
452
447
return result ;
453
448
}
454
449
455
- reassembleNestedFields ( fields : ComposeFieldConfigMap < any , any > ) : GraphQLFieldConfigMap < * , * > {
450
+ reassembleNestedFields ( fields : ComposeFieldConfigMap < any , any > ) : ComposeFieldConfigMap < any , any > {
456
451
const result = { } ;
457
452
Object . keys ( fields ) . forEach ( k => {
458
453
const names = k . split ( '.' ) ;
@@ -461,7 +456,7 @@ export default class ElasticApiParser {
461
456
} else {
462
457
if ( ! result [ names [ 0 ] ] ) {
463
458
result [ names [ 0 ] ] = {
464
- type : new GraphQLObjectType ( {
459
+ type : TypeComposer . create ( {
465
460
name : `${ this . prefix } _${ upperFirst ( names [ 0 ] ) } ` ,
466
461
fields : ( ( ) => { } : any ) ,
467
462
} ) ,
@@ -470,7 +465,7 @@ export default class ElasticApiParser {
470
465
} ,
471
466
} ;
472
467
}
473
- TypeComposer . create ( result [ names [ 0 ] ] . type ) . setField ( names [ 1 ] , fields [ k ] ) ;
468
+ result [ names [ 0 ] ] . type . setField ( names [ 1 ] , fields [ k ] ) ;
474
469
}
475
470
} ) ;
476
471
0 commit comments