|
7 | 7 |
|
8 | 8 |
|
9 | 9 | class Department(SQLAlchemyObjectType): |
10 | | - |
11 | 10 | class Meta: |
12 | 11 | model = DepartmentModel |
13 | 12 | interfaces = (relay.Node, ) |
14 | 13 |
|
15 | 14 |
|
16 | | -class Employee(SQLAlchemyObjectType): |
| 15 | +class DepartmentConnection(relay.Connection): |
| 16 | + class Meta: |
| 17 | + node = Department |
17 | 18 |
|
| 19 | + |
| 20 | +class Employee(SQLAlchemyObjectType): |
18 | 21 | class Meta: |
19 | 22 | model = EmployeeModel |
20 | 23 | interfaces = (relay.Node, ) |
21 | 24 |
|
22 | 25 |
|
23 | | -class Role(SQLAlchemyObjectType): |
| 26 | +class EmployeeConnection(relay.Connection): |
| 27 | + class Meta: |
| 28 | + node = Employee |
| 29 | + |
24 | 30 |
|
| 31 | +class Role(SQLAlchemyObjectType): |
25 | 32 | class Meta: |
26 | 33 | model = RoleModel |
27 | 34 | interfaces = (relay.Node, ) |
28 | 35 |
|
29 | 36 |
|
30 | | -SortEnumEmployee = utils.sort_enum_for_model( |
31 | | - EmployeeModel, 'SortEnumEmployee', |
| 37 | +class RoleConnection(relay.Connection): |
| 38 | + class Meta: |
| 39 | + node = Role |
| 40 | + |
| 41 | + |
| 42 | +SortEnumEmployee = utils.sort_enum_for_model(EmployeeModel, 'SortEnumEmployee', |
32 | 43 | lambda c, d: c.upper() + ('_ASC' if d else '_DESC')) |
33 | 44 |
|
34 | 45 |
|
35 | 46 | class Query(graphene.ObjectType): |
36 | 47 | node = relay.Node.Field() |
37 | 48 | # Allow only single column sorting |
38 | | - all_employees = SQLAlchemyConnectionField(Employee, sort=graphene.Argument(SortEnumEmployee, |
| 49 | + all_employees = SQLAlchemyConnectionField( |
| 50 | + EmployeeConnection, |
| 51 | + sort=graphene.Argument( |
| 52 | + SortEnumEmployee, |
39 | 53 | default_value=utils.EnumValue('id_asc', EmployeeModel.id.asc()))) |
40 | | - # Add sort over multiple columns, sorting by default over the primary key |
41 | | - all_roles = SQLAlchemyConnectionField(Role) |
| 54 | + # Allows sorting over multiple columns, by default over the primary key |
| 55 | + all_roles = SQLAlchemyConnectionField(RoleConnection) |
42 | 56 | # Disable sorting over this field |
43 | | - all_departments = SQLAlchemyConnectionField(Department, sort=None) |
| 57 | + all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None) |
44 | 58 |
|
45 | 59 |
|
46 | 60 | schema = graphene.Schema(query=Query, types=[Department, Employee, Role]) |
0 commit comments