1+ /* @flow */
12
3+ import { parse } from 'graphql/language' ;
24import {
35 GraphQLScalarType ,
46 GraphQLInt ,
@@ -8,60 +10,88 @@ import {
810 GraphQLID ,
911 GraphQLList ,
1012 GraphQLNonNull ,
13+ __Schema ,
14+ __Directive ,
15+ __DirectiveLocation ,
16+ __Type ,
17+ __Field ,
18+ __InputValue ,
19+ __EnumValue ,
20+ __TypeKind ,
1121} from 'graphql/type' ;
12- import { parse } from 'graphql/language' ;
13- import produceType , { getNamedTypeAST , buildWrappedType } from '../produceType' ;
22+ import produceType , { getNamedTypeNode , buildWrappedType } from '../produceType' ;
1423
15- const [ { type : innerTypeAST } , { type : wrappedTypeAST } ] = parse ( `
24+ const [ { type : wrappedTypeNode } , { type : wrapperTypeNode } ] = ( parse ( `
1625 type Ints {
1726 int: Int
1827 nonNullListOfNonNullInt: [Int!]!
1928 }
20- ` , { noLocation : true } ) . definitions [ 0 ] . fields ;
29+ ` , { noLocation : true } ) . definitions [ 0 ] : Object ) . fields ;
2130const wrappedType = new GraphQLNonNull ( new GraphQLList ( new GraphQLNonNull ( GraphQLInt ) ) ) ;
2231
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 ) ;
2635 } ) ;
2736} ) ;
2837
2938describe ( 'buildWrappedType()' , ( ) => {
30- it ( 'should work ', ( ) => {
31- expect ( buildWrappedType ( GraphQLInt , wrappedTypeAST ) ) . toEqual ( wrappedType ) ;
39+ test ( 'wraps types ', ( ) => {
40+ expect ( buildWrappedType ( GraphQLInt , wrapperTypeNode ) ) . toEqual ( wrappedType ) ;
3241 } ) ;
3342} ) ;
3443
3544describe ( 'produceType()' , ( ) => {
36- const customTypeAST = parse ( `
45+ const customTypeNode : Object = parse ( `
3746 scalar UUID
3847 ` ) . definitions [ 0 ] ;
3948 const UUID = new GraphQLScalarType ( { name : 'UUID' , serialize : String } ) ;
4049
41- it ( 'should produce GraphQL scalars ', ( ) => {
42- const typeAST = parse ( `
43- type Scalars {
50+ test ( 'produces GraphQL inner types ', ( ) => {
51+ const typeNode : Object = parse ( `
52+ type InnerTypes {
4453 int: Int
4554 float: Float
4655 string: String
4756 boolean: Boolean
4857 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,
4966 }
5067 ` ) . 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+ ] ) ;
5383 } ) ;
5484
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 ) ;
5787 } ) ;
5888
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 ) ;
6191 } ) ;
6292
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 , [ ] ) )
6595 . toThrowError ( 'Type "UUID" not found.' ) ;
6696 } ) ;
6797} ) ;
0 commit comments