graphene/examples/flask_sqlalchemy/schema.py

41 lines
880 B
Python
Raw Normal View History

2016-01-23 08:44:41 +03:00
import graphene
from graphene import relay
from graphene.contrib.sqlalchemy import (SQLAlchemyConnectionField,
SQLAlchemyNode)
from models import Department as DepartmentModel
from models import Employee as EmployeeModel
2016-04-13 15:16:01 +03:00
from models import Role as RoleModel
2016-01-23 08:44:41 +03:00
schema = graphene.Schema()
2016-01-23 08:44:41 +03:00
@schema.register
class Department(SQLAlchemyNode):
2016-01-23 08:44:41 +03:00
class Meta:
model = DepartmentModel
@schema.register
class Employee(SQLAlchemyNode):
2016-01-23 08:44:41 +03:00
class Meta:
model = EmployeeModel
2016-04-13 15:16:01 +03:00
@schema.register
class Role(SQLAlchemyNode):
class Meta:
model = RoleModel
identifier = 'role_id'
2016-01-23 08:44:41 +03:00
class Query(graphene.ObjectType):
2016-04-13 15:16:01 +03:00
node = relay.NodeField(Employee)
2016-01-24 00:12:01 +03:00
all_employees = SQLAlchemyConnectionField(Employee)
2016-04-13 15:16:01 +03:00
all_roles = SQLAlchemyConnectionField(Role)
role = relay.NodeField(Role)
2016-01-23 08:44:41 +03:00
schema.query = Query