def register_blueprints(app): for name in find_modules('blog.views'): mod = import_string(name) if hasattr(mod, 'bp'): app.register_blueprint(mod.bp) app.add_url_rule('/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True))
def get_test_app(): app = Flask(__name__) app.debug = True app.add_url_rule('/graphql', 'graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) app.add_url_rule('/', 'index', view_func=index_view,) return app
def create_app(): app = Flask(__name__) app.add_url_rule( '/sale_point', view_func=GraphQLView.as_view( 'sale_point', schema=sale_point_schema, graphiql=True ) ) return app
from flask import Flask from flask_sqlalchemy import SQLAlchemy import os, graphene from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField from flask_graphql import GraphQLView from schemas.schemas import our_schema from models.model import db, app basedir = os.path.abspath(os.path.dirname(__file__)) app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=our_schema, graphiql=True)) @app.route('/') def index(): return "GraphQL server is listening on /graphql" if __name__ == "__main__": app.run()
@app.route('/google-auth') def google_auth(): print('/google-auth') state = request.args.get('state') code = request.args.get('code') if code is not None and authorize_user_step2(state, code): return redirect('/calendar') return redirect('/auth-failed', code=307) @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def catch_all(path): if not SPA_PATH.joinpath(path).is_file(): return app.send_static_file('index.html') return app.send_static_file(path or 'index.html') app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) # Optional, for adding batch query support (used in Apollo-Client) app.add_url_rule('/graphql/batch', view_func=GraphQLView.as_view('graphql-batch', schema=schema, batch=True))
from flask import Flask from flask_graphql import GraphQLView from models import db_session from schema import schema #from waitress import serve app = Flask(__name__) app.debug = True app.add_url_rule( '/gql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # for having the GraphiQL interface )) @app.route("/hello") def test(): return 'Hello World' @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': app.run(host='127.0.0.1', port=80) # 0.0.0.0
from flask_graphql import GraphQLView from app import app, db from app.models import Game from .schema import schema import os app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=app.config['GRAPHIQL'] # for having the GraphiQL interface ) ) @app.teardown_appcontext def shutdown_session(exception=None): db.session.remove() if __name__ == '__main__': db.create_all() app.run()
from flask import Flask from database import db_session from flask_graphql import GraphQLView from schema import schema app = Flask(__name__) app.debug = True app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True, context={ 'session': db_session } ) ) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': app.run()
def create_graphql_route(app): app.add_url_rule('/graphql/', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))
def init_views(): from photogal.graphql import schema enable_graphiql = app.env == 'development' app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=enable_graphiql)) app.add_url_rule('/graphql/batch', view_func=GraphQLView.as_view('graphql-batch', schema=schema, batch=True))
def create_app(**kwargs): app = Flask(__name__) app.debug = True app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=Schema, **kwargs)) return app
class Mutation(graphene.ObjectType): save_post = CreatePost.Field() # noinspection PyTypeChecker schema_mutation = graphene.Schema(query=Query, mutation=Mutation) # Flask Rest & Graphql Routes @app.route('/') def hello_world(): return 'Hello From Graphql Tutorial!' # /graphql-query app.add_url_rule('/graphql-query', view_func=GraphQLView.as_view('graphql-query', schema=schema_query, graphiql=True)) # /graphql-mutation app.add_url_rule('/graphql-mutation', view_func=GraphQLView.as_view('graphql-mutation', schema=schema_mutation, graphiql=True)) if __name__ == '__main__': app.run()
from flask import Flask from flask_graphql import GraphQLView from cc.models import db_session from cc.schema import schema, Ouvrage app = Flask(__name__) app.debug = True app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # to have GraphiQL interface )) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': app.run()
tok = User.get_user_token(request.json) if "errors" in tok: return jsonify(tok), 401 return jsonify({"user": {"token": tok}}), 200 return jsonify({"errors": {"global": "Invalid user"}}), 401 def f(): if True: return return app.add_url_rule('/graphiql', view_func=requires_auth(GraphQLView.as_view('graphiql', schema=schema, graphiql=True))) app.add_url_rule('/graphql', view_func=token_auth.login_required(GraphQLView.as_view('graphql', schema=schema, graphiql=False))) @app.route("/about") def about(): return render_template('about.html') @app.route("/") def home(): return render_template('home.html') @app.errorhandler(404) def not_found(error):
class AuthorizationMiddleware(object): def resolve(self, next, root, info, **args): '''Middleware Authorization logic before execute every mutation/query''' info.context = {'request':request} if request.headers.get('Authorization'): decoded_user = jwt.decode(request.headers.get('Authorization'), JWT_SECRET, algorithms=['HS256'], options={'require_exp':False}) user = User.query.get(decoded_user['user']) info.context['user'] = user return next(root, info, **args) '''GraphQL Endpoint''' app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True, middleware=[AuthorizationMiddleware()], #Apply middleware for global authorization ) ) class CustomSubscriptionServer(GeventSubscriptionServer): '''Overriding the gevent subscription server class for custom context and middleware setting''' def on_start(self, connection_context, op_id, params): '''Handling errors returned by the execution result before we reach the returned observable''' try: execution_result = self.execute(connection_context.request_context, params) except Exception as e: self.send_error(connection_context, op_id, str(e)) if not isinstance(execution_result, Observable): self.send_error(connection_context, op_id, str(execution_result.errors[0]))
def init_service(service, schema): """ Add GraphQL support to the given Flask app """ # add default graphql endpoints GraphQL(service.app, schema=schema) # add the index query per service agreement service.app.add_url_rule('/', view_func=GraphQLView.as_view('index', schema=schema))
def graphql_view(): # print ("verify_password", auth.verify_password) view = GraphQLView.as_view('graphql', schema=schema, context={'session': db_session}, graphiql=bool(app.config.get("DEBUG", False))) view = jwt_required()(view) return view
from database.base import db_session from flask import Flask from flask_graphql import GraphQLView from schema import schema app = Flask(__name__) app.add_url_rule( '/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': app.run(threaded=True) # debug=True
"""Pattoo version routes.""" # Flask imports from flask import Blueprint # pattoo imports from flask_graphql import GraphQLView from pattoo.db.schemas import SCHEMA # Define the GRAPHQL global variable GRAPHQL = Blueprint('GRAPHQL', __name__) # Create the base GraphQL route GRAPHQL.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=SCHEMA, graphiql=False)) # Create the base iGraphQL route GRAPHQL.add_url_rule( '/igraphql', view_func=GraphQLView.as_view( 'igraphql', schema=SCHEMA, graphiql=True))
def graphql_view(): return GraphQLView.as_view('graphql', schema=schema, graphiql=True)
from flask_restx import Resource, Api, fields from flask_cors import CORS import config from api_v1 import blueprint as apiv1 from api_v1.graphql import graphql_schema from flask_graphql import GraphQLView app = Flask(__name__) main = Blueprint("main", __name__, url_prefix="/") @main.route("/") def hello(): return render_template("main.html") app.register_blueprint(apiv1) app.register_blueprint(main) app.add_url_rule("/v1/graphql", view_func=GraphQLView.as_view("graphql", schema=graphql_schema, graphiql=config.get_setting("dev-user", None))) CORS(app) @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') return response app.run(debug=True, port=config.get_setting("listen-port", 5251))
from flask import Flask from flask_graphql import GraphQLView from models import db_session from schema import schema app = Flask(__name__) app.add_url_rule( '/graphql', # setting the view function view_func=GraphQLView.as_view( 'graphql', # we set the schema that we generate schema=schema, # we say that we *do* want a graphiql interface graphiql=True)) #@app.route('/graphiql') #def view_func(): # GrapheQLView.as_view('graphql', schema = schema, graphiql = True) @app.teardown_appcontext def remove_session(exception=None): db_session.remove() if __name__ == '__main__':
def graphql_view(): view = GraphQLView.as_view('graphql', schema=schema, graphiql=True, context={"user": ""}) return jwt_required(view)
from flask import Flask from graphene import ObjectType, String, Schema from flask_graphql import GraphQLView class Query(ObjectType): hello = String(description="Hello") def resolve_hello(self, args, context, info): return "World" view_func = GraphQLView.as_view("graphql", schema=Schema(query=Query)) app = Flask(__name__) app.add_url_rule("/", view_func=view_func) if __name__ == "__main__": app.run()
@app.route("/login_resolve", methods=['POST']) def login_resolve(): try: username = request.json['Username'] password = request.json['Password'] print(username, password) print(login_resolve_process(username, password)) #print(login_resolve_process(username, password)) #return jsonify({'message':'ok'}) except Exception as e: # print("Aqui es el error") print(str(e)) return jsonify({ 'error': str(e) }) """ app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # Habilita la interfaz GraphiQL ))
print (exc) raise Exception('Unexpected error') return Transfer(ok=True) class Mutation(graphene.ObjectType): addUser = AddUser.Field() transfer = Transfer.Field() ################################## schema = graphene.Schema(query=Query, mutation=Mutation) ############################################################################# ################################ FLASK APP ################################## app.add_url_rule('/', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() ############################################################################# ################################## EXECUTION ################################## if os.environ.get('LAMBDA_LOCAL_DEVELOPMENT') == '1': if __name__ == '__main__': if os.environ.get('DATABASE_INIT') == '1': init_db() app.run() #############################################################################
app.app_protocol = lambda environ_path_info: 'graphql-ws' # routes @app.route('/') def index(): return '<p> Hello World</p>' @sockets.route('/subscriptions') def echo_socket(ws): subscription_server.handle(ws) return [] app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # for having the GraphiQL interface, allow_subscriptions=True)) if __name__ == '__main__': from gevent import pywsgi from geventwebsocket.handler import WebSocketHandler server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler) server.serve_forever()
from flask import Flask from schema import Query from flask_graphql import GraphQLView from graphene import Schema import os view_func = GraphQLView.as_view('graphql', schema=Schema(query=Query), graphiql=True) app = Flask(__name__) app.add_url_rule('/graphql', view_func=view_func) if __name__ == '__main__': app.run(host='0.0.0.0', port=os.environ.get('PORT', 5000))
db.session.commit() print(cabinet.id, cabinet.name) return CreateCabinet(cabinet=cabinet) class Mutation(graphene.ObjectType): create_cabinet = CreateCabinet.Field() schema = graphene.Schema( query=Query, mutation=Mutation, ) graphql_blueprint = Blueprint('graphql', __name__) graphql_blueprint.add_url_rule('/', 'graphql', view_func=GraphQLView.as_view('graphql', schema=schema)) graphiql_blueprint = Blueprint('graphiql', __name__, template_folder='templates/graphiql') @graphiql_blueprint.route('/') def index(): return render_template('graphiql.html')
app.config['SECURITY_USER_IDENTITY_ATTRIBUTES'] = 'username' app.config['BABEL_DEFAULT_LOCALE'] = 'he' app.config['OAUTH_CREDENTIALS'] = { 'facebook': { 'id': os.environ.get('FACEBOOK_KEY'), 'secret': os.environ.get('FACEBOOK_SECRET') }, 'google': { 'id': os.environ.get('GOOGLE_LOGIN_CLIENT_ID'), 'secret': os.environ.get('GOOGLE_LOGIN_CLIENT_SECRET') } } app.add_url_rule('/graphql', view_func=GraphQLView.as_view( 'graphql', schema=graphqlSchema, graphiql=True, get_context=lambda: {'session': db.session})) assets = Environment() assets.init_app(app) assets_env = AssetsEnvironment(os.path.join(utilities._PROJECT_ROOT, 'static'), '/static') jinja_environment = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader( os.path.join( os.path.dirname(__file__), "../templates")), extensions=[AssetsExtension]) jinja_environment.assets_environment = assets_env
def add_tag_wrapper(): view = GraphQLView.as_view("add_tag", schema=graphene.Schema(mutation=AddTagObjType)) return sensible_token(view)
parser.add_argument('--redis_url', type=str, required=False, help='Redis url string, e.g. redis://[:password]@localhost:6379/0') args = parser.parse_args() if args.subscriptions_enabled and not args.redis_url: parser.error("--subscriptions_enabled requires --redis_url") if args.port: port = args.port else: port = 8900 schema = create_schema(args) subscription_server = GeventSubscriptionServer(schema) app.app_protocol = lambda environ_path_info: "graphql-ws" app.add_url_rule( "/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=False, context={'ttl': args.subscription_ttl}) ) @app.route("/") def graphql_view(): return make_response(render_graphiql()) @sockets.route("/subscriptions") def echo_socket(ws): subscription_server.handle(ws) return [] print('Serving on port {}...'.format(port)) server = pywsgi.WSGIServer(("", port), app, handler_class=WebSocketHandler).serve_forever()
from database import db_session from flask import Flask from schema import schema from flask_graphql import GraphQLView app = Flask(__name__) app.debug = True app.add_url_rule("/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True)) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == "__main__": app.run()
def create_app(path='/graphql', **kwargs): app = Flask(__name__) app.debug = True app.add_url_rule(path, view_func=GraphQLView.as_view('graphql', schema=Schema, graphiql=True)) return app
from flask import Flask from flask_graphql import GraphQLView from model import session from schema import schema app = Flask(__name__) app.debug = True app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True, # For having the GraphiQL interface context={'session': session})) @app.teardown_appcontext def shutdown_session(exception=None): session.remove() print 'POTATO' if __name__ == '__main__': print 'Hello World' app.run()
from flask import Flask, send_from_directory from flask_cors import CORS from flask_graphql import GraphQLView from db.models import db_session from interfaces import discover, playlists app = Flask(__name__) app.debug = True CORS(app) app.add_url_rule( '/discover/graphql', view_func=GraphQLView.as_view('discover_graphql', schema=discover.schema, graphiql=True) ) app.add_url_rule( '/playlists/graphql', view_func=GraphQLView.as_view('playlists_graphql', schema=playlists.schema, graphiql=True) ) @app.route('/client/<path:filename>') def serve_static(filename): return send_from_directory("client/", filename) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove()
from flask import Flask from flask_graphql import GraphQLView from flask_cors import CORS from movie_base.schema import schema from movie_base.config import config app = Flask(__name__) app.debug = True cors = CORS(app, resources={'/graphql': {'origins': '*'}}) # def index(path=None): # return render_template('index.html', js_location=config['js_location']) app.add_url_rule('/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True, )) # app.add_url_rule( # '/', # view_func=index # ) # app.add_url_rule( # '/<path:path>', # view_func=index # )
# flask_sqlalchemy/app.py from flask import Flask from flask_graphql import GraphQLView from models import db_session from schema import schema, Department app = Flask(__name__) app.debug = True app.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # for having the GraphiQL interface ) ) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': app.run()
response.headers["Content-Disposition"] = "attachment; filename=result.tsv" return response # Function to add a JSON content type to the response, takes in the data that # is to be returned def make_json_response(data): response = make_response(data) response.headers['Content-Type'] = 'application/json' return response application.add_url_rule('/sum_schema', view_func=GraphQLView.as_view('sum_graphql', schema=sum_schema, graphiql=True)) application.add_url_rule('/ac_schema', view_func=GraphQLView.as_view('ac_graphql', schema=ac_schema, graphiql=True)) application.add_url_rule('/files_schema', view_func=GraphQLView.as_view('files_graphql', schema=files_schema, graphiql=True)) application.add_url_rule('/table_schema', view_func=GraphQLView.as_view('table_graphql', schema=table_schema,
default_query = ''' { allEmployees { edges { node { id, name, department { id, name }, role { id, name } } } } }'''.strip() app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) @app.teardown_appcontext def shutdown_session(exception=None): db_session.remove() if __name__ == '__main__': init_db() app.run()
def _add_url_rules(self): self.blueprint.add_url_rule('/', view_func=self.index_view) self.blueprint.add_url_rule('/<path:path>', view_func=self.index_view) self.blueprint.add_url_rule( '/graphql', view_func=GraphQLView.as_view( 'graphql', schema=self.schema))