Skip to content

Commit

Permalink
Add GraphQL schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Guilherme Siqueira Moreira committed Aug 26, 2019
1 parent aa8afb7 commit 91739f8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from models import (Department as DepartmentModel, Employee as EmployeeModel)


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 EmployeeConnection(relay.Connection):
class Meta:
node = Employee


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)

0 comments on commit 91739f8

Please sign in to comment.