Skip to content

Commit 3b0cbd0

Browse files
connection-test: add that checks generated types (#329)
1 parent a2662a0 commit 3b0cbd0

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/connection/__tests__/connection-test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
GraphQLSchema,
77
GraphQLString,
88
graphqlSync,
9+
printSchema,
910
} from 'graphql';
1011

12+
import { dedent } from '../../__testUtils__/dedent';
13+
1114
import { connectionFromArray } from '../arrayConnection';
1215

1316
import {
@@ -176,4 +179,73 @@ describe('connectionDefinition()', () => {
176179
},
177180
});
178181
});
182+
183+
it('generates correct types', () => {
184+
// FIXME remove trimEnd after we update to `[email protected]`
185+
expect(printSchema(schema).trimEnd()).to.deep.equal(dedent`
186+
type Query {
187+
user: User
188+
}
189+
190+
type User {
191+
name: String
192+
friends(after: String, first: Int, before: String, last: Int): FriendConnection
193+
friendsForward(after: String, first: Int): UserConnection
194+
friendsBackward(before: String, last: Int): UserConnection
195+
}
196+
197+
"""A connection to a list of items."""
198+
type FriendConnection {
199+
"""Information to aid in pagination."""
200+
pageInfo: PageInfo!
201+
202+
"""A list of edges."""
203+
edges: [FriendEdge]
204+
totalCount: Int
205+
}
206+
207+
"""Information about pagination in a connection."""
208+
type PageInfo {
209+
"""When paginating forwards, are there more items?"""
210+
hasNextPage: Boolean!
211+
212+
"""When paginating backwards, are there more items?"""
213+
hasPreviousPage: Boolean!
214+
215+
"""When paginating backwards, the cursor to continue."""
216+
startCursor: String
217+
218+
"""When paginating forwards, the cursor to continue."""
219+
endCursor: String
220+
}
221+
222+
"""An edge in a connection."""
223+
type FriendEdge {
224+
"""The item at the end of the edge"""
225+
node: User
226+
227+
"""A cursor for use in pagination"""
228+
cursor: String!
229+
friendshipTime: String
230+
}
231+
232+
"""A connection to a list of items."""
233+
type UserConnection {
234+
"""Information to aid in pagination."""
235+
pageInfo: PageInfo!
236+
237+
"""A list of edges."""
238+
edges: [UserEdge]
239+
}
240+
241+
"""An edge in a connection."""
242+
type UserEdge {
243+
"""The item at the end of the edge"""
244+
node: User
245+
246+
"""A cursor for use in pagination"""
247+
cursor: String!
248+
}
249+
`);
250+
});
179251
});

0 commit comments

Comments
 (0)