Skip to content

Commit 5468c8f

Browse files
connection: allow nodeType to any named type with or without non-null (#331)
1 parent 02a5a27 commit 5468c8f

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/connection/__tests__/connection-test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33
import {
44
GraphQLInt,
5+
GraphQLNonNull,
56
GraphQLObjectType,
67
GraphQLSchema,
78
GraphQLString,
@@ -54,7 +55,7 @@ const userType = new GraphQLObjectType({
5455

5556
const { connectionType: friendConnection } = connectionDefinitions({
5657
name: 'Friend',
57-
nodeType: userType,
58+
nodeType: new GraphQLNonNull(userType),
5859
resolveNode: (edge) => allUsers[edge.node],
5960
edgeFields: () => ({
6061
friendshipTime: {
@@ -71,7 +72,7 @@ const { connectionType: friendConnection } = connectionDefinitions({
7172
});
7273

7374
const { connectionType: userConnection } = connectionDefinitions({
74-
nodeType: userType,
75+
nodeType: new GraphQLNonNull(userType),
7576
resolveNode: (edge) => allUsers[edge.node],
7677
});
7778

@@ -246,7 +247,7 @@ describe('connectionDefinition()', () => {
246247
"""An edge in a connection."""
247248
type FriendEdge {
248249
"""The item at the end of the edge"""
249-
node: User
250+
node: User!
250251
251252
"""A cursor for use in pagination"""
252253
cursor: String!
@@ -265,7 +266,7 @@ describe('connectionDefinition()', () => {
265266
"""An edge in a connection."""
266267
type UserEdge {
267268
"""The item at the end of the edge"""
268-
node: User
269+
node: User!
269270
270271
"""A cursor for use in pagination"""
271272
cursor: String!

src/connection/connection.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type {
2+
GraphQLNonNull,
3+
GraphQLNamedType,
4+
GraphQLScalarType,
5+
GraphQLObjectType,
26
GraphQLFieldConfigArgumentMap,
37
GraphQLFieldConfigMap,
48
GraphQLFieldResolver,
5-
GraphQLObjectType,
6-
GraphQLScalarType,
79
Thunk,
810
} from 'graphql';
911

@@ -58,7 +60,7 @@ export interface ConnectionArguments {
5860

5961
export interface ConnectionConfig {
6062
name?: string;
61-
nodeType: GraphQLObjectType;
63+
nodeType: GraphQLNamedType | GraphQLNonNull<GraphQLNamedType>;
6264
resolveNode?: GraphQLFieldResolver<any, any>;
6365
resolveCursor?: GraphQLFieldResolver<any, any>;
6466
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>>;

src/connection/connection.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {
2-
GraphQLBoolean,
3-
GraphQLInt,
4-
GraphQLNonNull,
52
GraphQLList,
3+
GraphQLNonNull,
64
GraphQLObjectType,
5+
GraphQLInt,
76
GraphQLString,
7+
GraphQLBoolean,
8+
getNamedType,
89
} from 'graphql';
910

1011
import type {
12+
GraphQLNamedType,
1113
GraphQLFieldConfigArgumentMap,
1214
GraphQLFieldConfigMap,
1315
GraphQLFieldResolver,
@@ -73,7 +75,7 @@ export type ConnectionArguments = {
7375

7476
type ConnectionConfig = {|
7577
name?: string,
76-
nodeType: GraphQLObjectType,
78+
nodeType: GraphQLNamedType | GraphQLNonNull<GraphQLNamedType>,
7779
resolveNode?: GraphQLFieldResolver<any, any>,
7880
resolveCursor?: GraphQLFieldResolver<any, any>,
7981
edgeFields?: Thunk<GraphQLFieldConfigMap<any, any>>,
@@ -100,7 +102,7 @@ export function connectionDefinitions(
100102
config: ConnectionConfig,
101103
): GraphQLConnectionDefinitions {
102104
const { nodeType } = config;
103-
const name = config.name ?? nodeType.name;
105+
const name = config.name ?? getNamedType(nodeType).name;
104106
const edgeFields = config.edgeFields ?? {};
105107
const connectionFields = config.connectionFields ?? {};
106108
const resolveNode = config.resolveNode;

0 commit comments

Comments
 (0)