1
+ /* @flow */
1
2
3
+ import { parse } from 'graphql/language' ;
2
4
import {
3
5
GraphQLScalarType ,
4
6
GraphQLInt ,
@@ -8,60 +10,88 @@ import {
8
10
GraphQLID ,
9
11
GraphQLList ,
10
12
GraphQLNonNull ,
13
+ __Schema ,
14
+ __Directive ,
15
+ __DirectiveLocation ,
16
+ __Type ,
17
+ __Field ,
18
+ __InputValue ,
19
+ __EnumValue ,
20
+ __TypeKind ,
11
21
} from 'graphql/type' ;
12
- import { parse } from 'graphql/language' ;
13
- import produceType , { getNamedTypeAST , buildWrappedType } from '../produceType' ;
22
+ import produceType , { getNamedTypeNode , buildWrappedType } from '../produceType' ;
14
23
15
- const [ { type : innerTypeAST } , { type : wrappedTypeAST } ] = parse ( `
24
+ const [ { type : wrappedTypeNode } , { type : wrapperTypeNode } ] = ( parse ( `
16
25
type Ints {
17
26
int: Int
18
27
nonNullListOfNonNullInt: [Int!]!
19
28
}
20
- ` , { noLocation : true } ) . definitions [ 0 ] . fields ;
29
+ ` , { noLocation : true } ) . definitions [ 0 ] : any ) . fields ;
21
30
const wrappedType = new GraphQLNonNull ( new GraphQLList ( new GraphQLNonNull ( GraphQLInt ) ) ) ;
22
31
23
- describe ( 'getNamedTypeAST ()' , ( ) => {
24
- it ( 'should work ', ( ) => {
25
- expect ( getNamedTypeAST ( wrappedTypeAST ) ) . toEqual ( innerTypeAST ) ;
32
+ describe ( 'getNamedTypeNode ()' , ( ) => {
33
+ test ( 'gets wrapped type nodes ', ( ) => {
34
+ expect ( getNamedTypeNode ( wrapperTypeNode ) ) . toEqual ( wrappedTypeNode ) ;
26
35
} ) ;
27
36
} ) ;
28
37
29
38
describe ( 'buildWrappedType()' , ( ) => {
30
- it ( 'should work ', ( ) => {
31
- expect ( buildWrappedType ( GraphQLInt , wrappedTypeAST ) ) . toEqual ( wrappedType ) ;
39
+ test ( 'wraps types ', ( ) => {
40
+ expect ( buildWrappedType ( GraphQLInt , wrapperTypeNode ) ) . toEqual ( wrappedType ) ;
32
41
} ) ;
33
42
} ) ;
34
43
35
44
describe ( 'produceType()' , ( ) => {
36
- const customTypeAST = parse ( `
45
+ const customTypeNode : any = parse ( `
37
46
scalar UUID
38
47
` ) . definitions [ 0 ] ;
39
48
const UUID = new GraphQLScalarType ( { name : 'UUID' , serialize : String } ) ;
40
49
41
- it ( 'should produce GraphQL scalars ', ( ) => {
42
- const typeAST = parse ( `
43
- type Scalars {
50
+ test ( 'produces GraphQL inner types ', ( ) => {
51
+ const typeNode : any = parse ( `
52
+ type InnerTypes {
44
53
int: Int
45
54
float: Float
46
55
string: String
47
56
boolean: Boolean
48
57
id: ID
58
+ schema: __Schema,
59
+ directive: __Directive,
60
+ directiveLocation: __DirectiveLocation,
61
+ type: __Type,
62
+ field: __Field,
63
+ inputValue: __InputValue,
64
+ enumValue: __EnumValue,
65
+ typeKind: __TypeKind,
49
66
}
50
67
` ) . definitions [ 0 ] ;
51
- expect ( typeAST . fields . map ( ( { type } ) => type ) . map ( produceType ) )
52
- . toEqual ( [ GraphQLInt , GraphQLFloat , GraphQLString , GraphQLBoolean , GraphQLID ] ) ;
68
+ expect ( typeNode . fields . map ( ( { type } ) => type ) . map ( produceType ) ) . toEqual ( [
69
+ GraphQLInt ,
70
+ GraphQLFloat ,
71
+ GraphQLString ,
72
+ GraphQLBoolean ,
73
+ GraphQLID ,
74
+ __Schema ,
75
+ __Directive ,
76
+ __DirectiveLocation ,
77
+ __Type ,
78
+ __Field ,
79
+ __InputValue ,
80
+ __EnumValue ,
81
+ __TypeKind ,
82
+ ] ) ;
53
83
} ) ;
54
84
55
- it ( 'should produce GraphQL type wrappers', ( ) => {
56
- expect ( produceType ( wrappedTypeAST , [ ] ) ) . toEqual ( wrappedType ) ;
85
+ test ( 'produces GraphQL type wrappers', ( ) => {
86
+ expect ( produceType ( wrapperTypeNode , [ ] ) ) . toEqual ( wrappedType ) ;
57
87
} ) ;
58
88
59
- it ( 'should produce custom types', ( ) => {
60
- expect ( produceType ( customTypeAST , [ UUID ] ) ) . toEqual ( UUID ) ;
89
+ test ( 'produces custom types', ( ) => {
90
+ expect ( produceType ( customTypeNode , [ UUID ] ) ) . toEqual ( UUID ) ;
61
91
} ) ;
62
92
63
- it ( 'should throw if it can\'t produce the type', ( ) => {
64
- expect ( ( ) => produceType ( customTypeAST , [ ] ) )
93
+ test ( 'throws if it can\'t produce the type', ( ) => {
94
+ expect ( ( ) => produceType ( customTypeNode , [ ] ) )
65
95
. toThrowError ( 'Type "UUID" not found.' ) ;
66
96
} ) ;
67
97
} ) ;
0 commit comments