-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.py
38 lines (26 loc) · 1006 Bytes
/
schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from models import Department, Employee
class DepartmentNode(SQLAlchemyObjectType):
class Meta:
model = Department
interfaces = (relay.Node,)
class DepartmentConnection(relay.Connection):
class Meta:
node = DepartmentNode
class EmployeeNode(SQLAlchemyObjectType):
class Meta:
model = Employee
interfaces = (relay.Node,)
class EmployeeConnection(relay.Connection):
class Meta:
node = EmployeeNode
class Query(graphene.ObjectType):
node = relay.Node.Field()
# Allows sorting over multiple columns, by default over the primary key
all_employees = SQLAlchemyConnectionField(EmployeeConnection)
# Disable sorting over this field
all_departments = SQLAlchemyConnectionField(DepartmentConnection,
sort=None)
schema = graphene.Schema(query=Query)