Skip to content

Commit d197e81

Browse files
committed
test_connection: add test that checks generated types
1 parent 36c0b15 commit d197e81

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

tests/connection/test_connection.py

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import List, NamedTuple
22

3-
from graphql import graphql_sync
4-
from graphql.type import (
3+
from graphql import (
4+
graphql_sync,
5+
print_schema,
56
GraphQLField,
67
GraphQLInt,
78
GraphQLObjectType,
@@ -17,6 +18,8 @@
1718
forward_connection_args,
1819
)
1920

21+
from ..utils import dedent
22+
2023

2124
class User(NamedTuple):
2225
name: str
@@ -175,3 +178,72 @@ def works_with_backward_connection_args():
175178
},
176179
None,
177180
)
181+
182+
def generates_correct_types():
183+
assert print_schema(schema).rstrip() == dedent(
184+
'''
185+
type Query {
186+
user: User
187+
}
188+
189+
type User {
190+
name: String
191+
friends(after: String, first: Int, before: String, last: Int): FriendConnection
192+
friendsForward(after: String, first: Int): UserConnection
193+
friendsBackward(before: String, last: Int): UserConnection
194+
}
195+
196+
"""A connection to a list of items."""
197+
type FriendConnection {
198+
"""Information to aid in pagination."""
199+
pageInfo: PageInfo!
200+
201+
"""A list of edges."""
202+
edges: [FriendEdge]
203+
totalCount: Int
204+
}
205+
206+
"""Information about pagination in a connection."""
207+
type PageInfo {
208+
"""When paginating forwards, are there more items?"""
209+
hasNextPage: Boolean!
210+
211+
"""When paginating backwards, are there more items?"""
212+
hasPreviousPage: Boolean!
213+
214+
"""When paginating backwards, the cursor to continue."""
215+
startCursor: String
216+
217+
"""When paginating forwards, the cursor to continue."""
218+
endCursor: String
219+
}
220+
221+
"""An edge in a connection."""
222+
type FriendEdge {
223+
"""The item at the end of the edge"""
224+
node: User
225+
226+
"""A cursor for use in pagination"""
227+
cursor: String!
228+
friendshipTime: String
229+
}
230+
231+
"""A connection to a list of items."""
232+
type UserConnection {
233+
"""Information to aid in pagination."""
234+
pageInfo: PageInfo!
235+
236+
"""A list of edges."""
237+
edges: [UserEdge]
238+
}
239+
240+
"""An edge in a connection."""
241+
type UserEdge {
242+
"""The item at the end of the edge"""
243+
node: User
244+
245+
"""A cursor for use in pagination"""
246+
cursor: String!
247+
}
248+
''' # noqa: E501
249+
)

0 commit comments

Comments
 (0)