mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 04:07:16 +03:00
Improved Flask SQLAlchemy example
This commit is contained in:
parent
553982c3fc
commit
5697ef98e9
|
@ -18,10 +18,16 @@ def init_db():
|
|||
Base.metadata.drop_all(bind=engine)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
department = Department(name='Informatics')
|
||||
db_session.add(department)
|
||||
# Create the fixtures
|
||||
engineering = Department(name='Engineering')
|
||||
db_session.add(engineering)
|
||||
hr = Department(name='Human Resources')
|
||||
db_session.add(hr)
|
||||
|
||||
db_session.add(department)
|
||||
employee = Employee(name='Peter', department=department)
|
||||
db_session.add(employee)
|
||||
peter = Employee(name='Peter', department=engineering)
|
||||
db_session.add(peter)
|
||||
roy = Employee(name='Roy', department=engineering)
|
||||
db_session.add(roy)
|
||||
tracy = Employee(name='Tracy', department=hr)
|
||||
db_session.add(tracy)
|
||||
db_session.commit()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
graphene[sqlalchemy]
|
||||
graphql_flask==1.0.0
|
||||
graphql_flask==1.1.0
|
||||
SQLAlchemy==1.0.11
|
||||
Flask==0.10.1
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import graphene
|
||||
from graphene import relay
|
||||
from graphene.contrib.sqlalchemy import SQLAlchemyNode
|
||||
from graphene.contrib.sqlalchemy import SQLAlchemyNode, SQLAlchemyConnectionField
|
||||
from models import Department as DepartmentModel, Employee as EmployeeModel
|
||||
|
||||
from database import db_session
|
||||
|
@ -22,5 +22,6 @@ class Employee(SQLAlchemyNode):
|
|||
|
||||
class Query(graphene.ObjectType):
|
||||
node = relay.NodeField(Department, Employee)
|
||||
all_employees = SQLAlchemyConnectionField(Employee)
|
||||
|
||||
schema.query = Query
|
||||
|
|
Loading…
Reference in New Issue
Block a user