File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 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', () => {
3636 const cursor = getNamedType ( tc . getFieldType ( 'cursor' ) ) ;
3737 expect ( cursor ) . equal ( GraphQLConnectionCursor ) ;
3838 } ) ;
39+
40+ it ( 'should have `ofType` property (like GraphQLList, GraphQLNonNull)' , ( ) => {
41+ const edgeType = prepareEdgeType ( userTypeComposer ) ;
42+ expect ( edgeType ) . property ( 'ofType' ) . equals ( userTypeComposer . getType ( ) ) ;
43+ } ) ;
3944 } ) ;
4045
4146 describe ( 'prepareConnectionType()' , ( ) => {
@@ -69,5 +74,12 @@ describe('types/connectionType.js', () => {
6974 const edges = getNamedType ( tc . getFieldType ( 'edges' ) ) ;
7075 expect ( edges ) . property ( 'name' ) . equals ( 'UserEdge' ) ;
7176 } ) ;
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+ } ) ;
7284 } ) ;
7385} ) ;
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import PageInfoType from './pageInfoType';
1818export function prepareEdgeType ( typeComposer : TypeComposer ) : GraphQLObjectType {
1919 const name = `${ typeComposer . getTypeName ( ) } Edge` ;
2020
21- return new GraphQLObjectType ( {
21+ const edgeType = new GraphQLObjectType ( {
2222 name,
2323 description : 'An edge in a connection.' ,
2424 fields : ( ) => ( {
@@ -32,13 +32,15 @@ export function prepareEdgeType(typeComposer: TypeComposer): GraphQLObjectType {
3232 } ,
3333 } ) ,
3434 } ) ;
35+ edgeType . ofType = typeComposer . getType ( ) ;
36+ return edgeType ;
3537}
3638
3739
3840export function prepareConnectionType ( typeComposer : TypeComposer ) : GraphQLObjectType {
3941 const name = `${ typeComposer . getTypeName ( ) } Connection` ;
4042
41- return new GraphQLObjectType ( {
43+ const connectionType = new GraphQLObjectType ( {
4244 name,
4345 description : 'A connection to a list of items.' ,
4446 fields : ( ) => ( {
@@ -56,4 +58,6 @@ export function prepareConnectionType(typeComposer: TypeComposer): GraphQLObject
5658 } ,
5759 } ) ,
5860 } ) ;
61+ connectionType . ofType = typeComposer . getType ( ) ;
62+ return connectionType ;
5963}
You can’t perform that action at this time.
0 commit comments