-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.py
46 lines (33 loc) · 1.26 KB
/
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
39
40
41
42
43
44
45
46
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from models import Department as DepartmentModel, Employee as EmployeeModel, Inventory as InventoryModel
class Department(SQLAlchemyObjectType):
class Meta:
model = DepartmentModel
interfaces = (relay.Node, )
class DepartmentConnection(relay.Connection):
class Meta:
node = Department
class Employee(SQLAlchemyObjectType):
class Meta:
model = EmployeeModel
interfaces = (relay.Node, )
class EmployeConnection(relay.Connection):
class Meta:
node = Employee
class Inventory(SQLAlchemyObjectType):
class Meta:
model = InventoryModel
interfaces = (relay.Node, )
class InventoryConnection(relay.Connection):
class Meta:
node = Inventory
class Query(graphene.ObjectType):
node = relay.Node.Field()
# Allows sorting over multiple columns, by default over the primary key
all_products = SQLAlchemyConnectionField(InventoryConnection)
all_employees = SQLAlchemyConnectionField(EmployeConnection)
# Disable sorting over this field
all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None)
schema = graphene.Schema(query=Query)