Skip to content
Snippets Groups Projects
Verified Commit 880dd9c9 authored by Mark's avatar Mark
Browse files

Add basic graphql schema

parent 2fd721d3
No related branches found
No related tags found
No related merge requests found
app.py 0 → 100644
from flask import Flask
from flask_security import Security, login_required, \
SQLAlchemySessionUserDatastore
from flask_graphql import GraphQLView
from os import environ
from database.database import db_session, init_db
from database.schema import schema
from database.models import User, Role
app = Flask(__name__)
app.debug = True if "DEBUG" in environ and environ["DEBUG"] else False
app.add_url_rule(
'/graphql',
view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True # for having the GraphiQL interface
)
)
user_datastore = SQLAlchemySessionUserDatastore(db_session,
User, Role)
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
@app.before_first_request
def initialize_database():
init_db()
if __name__ == '__main__':
app.run()
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from database.models import User as UserModel, Application as ApplicationModel, Role as RoleModel
from database.database import scoped_session
class User(SQLAlchemyObjectType):
class Meta:
model = UserModel
interfaces = (relay.Node, )
class UserConnections(relay.Connection):
class Meta:
node = User
class Application(SQLAlchemyObjectType):
class Meta:
model = ApplicationModel
interfaces = (relay.Node, )
class ApplicationConnections(relay.Connection):
class Meta:
node = Application
class Role(SQLAlchemyObjectType):
class Meta:
model = RoleModel
interfaces = (relay.Node, )
class RoleConnections(relay.Connection):
class Meta:
node = Role
class Query(graphene.ObjectType):
node = relay.Node.Field()
all_users = SQLAlchemyConnectionField(UserConnections)
all_application = SQLAlchemyConnectionField(ApplicationConnections)
all_roles = SQLAlchemyConnectionField(RoleConnections)
schema = graphene.Schema(query=Query)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment