File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ describe('types/connectionType.js', () => {
36
36
const cursor = getNamedType ( tc . getFieldType ( 'cursor' ) ) ;
37
37
expect ( cursor ) . equal ( GraphQLConnectionCursor ) ;
38
38
} ) ;
39
+
40
+ it ( 'should have `ofType` property (like GraphQLList, GraphQLNonNull)' , ( ) => {
41
+ const edgeType = prepareEdgeType ( userTypeComposer ) ;
42
+ expect ( edgeType ) . property ( 'ofType' ) . equals ( userTypeComposer . getType ( ) ) ;
43
+ } ) ;
39
44
} ) ;
40
45
41
46
describe ( 'prepareConnectionType()' , ( ) => {
@@ -69,5 +74,12 @@ describe('types/connectionType.js', () => {
69
74
const edges = getNamedType ( tc . getFieldType ( 'edges' ) ) ;
70
75
expect ( edges ) . property ( 'name' ) . equals ( 'UserEdge' ) ;
71
76
} ) ;
77
+
78
+ it ( 'should have `ofType` property (like GraphQLList, GraphQLNonNull)' , ( ) => {
79
+ // this behavior needed for `graphql-compose` module in `projection` helper
80
+ // otherwise it incorrectly construct projectionMapper for tricky fields
81
+ const connectionType = prepareConnectionType ( userTypeComposer ) ;
82
+ expect ( connectionType ) . property ( 'ofType' ) . equals ( userTypeComposer . getType ( ) ) ;
83
+ } ) ;
72
84
} ) ;
73
85
} ) ;
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import PageInfoType from './pageInfoType';
18
18
export function prepareEdgeType ( typeComposer : TypeComposer ) : GraphQLObjectType {
19
19
const name = `${ typeComposer . getTypeName ( ) } Edge` ;
20
20
21
- return new GraphQLObjectType ( {
21
+ const edgeType = new GraphQLObjectType ( {
22
22
name,
23
23
description : 'An edge in a connection.' ,
24
24
fields : ( ) => ( {
@@ -32,13 +32,15 @@ export function prepareEdgeType(typeComposer: TypeComposer): GraphQLObjectType {
32
32
} ,
33
33
} ) ,
34
34
} ) ;
35
+ edgeType . ofType = typeComposer . getType ( ) ;
36
+ return edgeType ;
35
37
}
36
38
37
39
38
40
export function prepareConnectionType ( typeComposer : TypeComposer ) : GraphQLObjectType {
39
41
const name = `${ typeComposer . getTypeName ( ) } Connection` ;
40
42
41
- return new GraphQLObjectType ( {
43
+ const connectionType = new GraphQLObjectType ( {
42
44
name,
43
45
description : 'A connection to a list of items.' ,
44
46
fields : ( ) => ( {
@@ -56,4 +58,6 @@ export function prepareConnectionType(typeComposer: TypeComposer): GraphQLObject
56
58
} ,
57
59
} ) ,
58
60
} ) ;
61
+ connectionType . ofType = typeComposer . getType ( ) ;
62
+ return connectionType ;
59
63
}
You can’t perform that action at this time.
0 commit comments