From 91739f8b5c81ed6a37b4883fbd409b03d2619250 Mon Sep 17 00:00:00 2001 From: Pedro Guilherme Siqueira Moreira Date: Mon, 26 Aug 2019 18:08:25 -0300 Subject: [PATCH] Add GraphQL schema --- schema.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 schema.py diff --git a/schema.py b/schema.py new file mode 100644 index 0000000..22c507d --- /dev/null +++ b/schema.py @@ -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)