Skip to content

Commit 3965565

Browse files
committed
Add ofType property to Connection and Edge types.
Connection type is some kind of wrapper under GraphQLNamedType. This behavior needed for `graphql-compose` module in `projection` helper, otherwise it incorrectly construct projectionMapper for tricky fields.
1 parent 02bac85 commit 3965565

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/types/__tests__/connectionType-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

src/types/connectionType.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import PageInfoType from './pageInfoType';
1818
export 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

3840
export 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
}

0 commit comments

Comments
 (0)