|
1 | 1 | from typing import List, NamedTuple
|
2 | 2 |
|
3 |
| -from graphql import graphql_sync |
4 |
| -from graphql.type import ( |
| 3 | +from graphql import ( |
| 4 | + graphql_sync, |
| 5 | + print_schema, |
5 | 6 | GraphQLField,
|
6 | 7 | GraphQLInt,
|
7 | 8 | GraphQLObjectType,
|
|
17 | 18 | forward_connection_args,
|
18 | 19 | )
|
19 | 20 |
|
| 21 | +from ..utils import dedent |
| 22 | + |
20 | 23 |
|
21 | 24 | class User(NamedTuple):
|
22 | 25 | name: str
|
@@ -175,3 +178,72 @@ def works_with_backward_connection_args():
|
175 | 178 | },
|
176 | 179 | None,
|
177 | 180 | )
|
| 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