3
3
// import fs from 'fs';
4
4
import dox from 'dox' ;
5
5
import path from 'path' ;
6
- import { GraphQLJSON , TypeComposer } from 'graphql-compose' ;
6
+ import { GraphQLJSON , TypeComposer , EnumTypeComposer } from 'graphql-compose' ;
7
7
import {
8
8
GraphQLString ,
9
9
GraphQLFloat ,
@@ -303,14 +303,18 @@ describe('ElasticApiParser', () => {
303
303
it ( 'should convert to GraphQLEnumType' , ( ) => {
304
304
const type = parser . getEnumType ( 'f1' , [ 'AND' , 'OR' ] ) ;
305
305
expect ( type ) . toBeInstanceOf ( GraphQLEnumType ) ;
306
- expect ( type . _values [ 0 ] ) . toMatchObject ( { name : 'AND' , value : 'AND' } ) ;
307
- expect ( type . _values [ 1 ] ) . toMatchObject ( { name : 'OR' , value : 'OR' } ) ;
306
+
307
+ const etc = EnumTypeComposer . create ( type ) ;
308
+ expect ( etc . getField ( 'AND' ) ) . toMatchObject ( { name : 'AND' , value : 'AND' } ) ;
309
+ expect ( etc . getField ( 'OR' ) ) . toMatchObject ( { name : 'OR' , value : 'OR' } ) ;
308
310
} ) ;
309
311
310
312
it ( "should convert '' to empty_string" , ( ) => {
311
313
const type = parser . getEnumType ( 'f1' , [ '' ] ) ;
312
314
expect ( type ) . toBeInstanceOf ( GraphQLEnumType ) ;
313
- expect ( type . _values [ 0 ] ) . toMatchObject ( {
315
+
316
+ const etc = EnumTypeComposer . create ( type ) ;
317
+ expect ( etc . getField ( 'empty_string' ) ) . toMatchObject ( {
314
318
name : 'empty_string' ,
315
319
value : '' ,
316
320
} ) ;
@@ -322,19 +326,21 @@ describe('ElasticApiParser', () => {
322
326
// But we allow to use this values, just renaming it.
323
327
const type = parser . getEnumType ( 'f1' , [ 'true' , true , 'false' , false ] ) ;
324
328
expect ( type ) . toBeInstanceOf ( GraphQLEnumType ) ;
325
- expect ( type . _values [ 0 ] ) . toMatchObject ( {
329
+
330
+ const etc = EnumTypeComposer . create ( type ) ;
331
+ expect ( etc . getField ( 'true_string' ) ) . toMatchObject ( {
326
332
name : 'true_string' ,
327
333
value : 'true' ,
328
334
} ) ;
329
- expect ( type . _values [ 1 ] ) . toMatchObject ( {
335
+ expect ( etc . getField ( 'true_boolean' ) ) . toMatchObject ( {
330
336
name : 'true_boolean' ,
331
337
value : true ,
332
338
} ) ;
333
- expect ( type . _values [ 2 ] ) . toMatchObject ( {
339
+ expect ( etc . getField ( 'false_string' ) ) . toMatchObject ( {
334
340
name : 'false_string' ,
335
341
value : 'false' ,
336
342
} ) ;
337
- expect ( type . _values [ 3 ] ) . toMatchObject ( {
343
+ expect ( etc . getField ( 'false_boolean' ) ) . toMatchObject ( {
338
344
name : 'false_boolean' ,
339
345
value : false ,
340
346
} ) ;
@@ -343,7 +349,9 @@ describe('ElasticApiParser', () => {
343
349
it ( 'should convert 1 to number_1' , ( ) => {
344
350
const type = parser . getEnumType ( 'f1' , [ 1 ] ) ;
345
351
expect ( type ) . toBeInstanceOf ( GraphQLEnumType ) ;
346
- expect ( type . _values [ 0 ] ) . toMatchObject ( { name : 'number_1' , value : 1 } ) ;
352
+
353
+ const etc = EnumTypeComposer . create ( type ) ;
354
+ expect ( etc . getField ( 'number_1' ) ) . toMatchObject ( { name : 'number_1' , value : 1 } ) ;
347
355
} ) ;
348
356
349
357
it ( 'should provide name started with ElasticEnum' , ( ) => {
0 commit comments