Python flask_graphql.GraphQLView.as_view() Examples

The following are 7 code examples of flask_graphql.GraphQLView.as_view(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_graphql.GraphQLView , or try the search function .
Example #1
Source File: schema.py    From graphql-pynamodb with MIT License 6 votes vote down vote up
def graphql_token_view():
    view = GraphQLView.as_view('graphql', schema=schema, graphiql=bool(app.config.get("DEBUG", False)))
    view = jwt_required()(view)
    return view 
Example #2
Source File: __init__.py    From flask-unchained with MIT License 6 votes vote down vote up
def after_init_app(self, app: FlaskUnchained):
        if app.config.GRAPHENE_URL:
            app.add_url_rule(app.config.GRAPHENE_URL,
                             view_func=csrf.exempt(GraphQLView.as_view(
                                 'graphql',
                                 schema=self.root_schema,
                                 graphiql=app.config.GRAPHENE_ENABLE_GRAPHIQL,
                                 pretty=app.config.GRAPHENE_PRETTY_JSON,
                                 batch=False,
                             )),
                             methods=GraphQLView.methods,
                             strict_slashes=False)

        if app.config.GRAPHENE_BATCH_URL:
            app.add_url_rule(app.config.GRAPHENE_BATCH_URL,
                             view_func=csrf.exempt(GraphQLView.as_view(
                                 'graphql',
                                 schema=self.root_schema,
                                 graphiql=app.config.GRAPHENE_ENABLE_GRAPHIQL,
                                 pretty=app.config.GRAPHENE_PRETTY_JSON,
                                 batch=True,
                             )),
                             methods=GraphQLView.methods,
                             strict_slashes=False) 
Example #3
Source File: test_subscription_transport.py    From graphql-python-subscriptions with MIT License 6 votes vote down vote up
def create_app(sub_mgr, schema, options):
    app = Flask(__name__)
    sockets = Sockets(app)

    app.app_protocol = lambda environ_path_info: 'graphql-subscriptions'

    app.add_url_rule(
        '/graphql',
        view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))

    @app.route('/publish', methods=['POST'])
    def sub_mgr_publish():
        sub_mgr.publish(*request.get_json())
        return jsonify(request.get_json())

    @sockets.route('/socket')
    def socket_channel(websocket):
        subscription_server = SubscriptionServer(sub_mgr, websocket, **options)
        subscription_server.handle()
        return []

    return app 
Example #4
Source File: __init__.py    From Flask-GraphQL-Large-Application-Example with MIT License 6 votes vote down vote up
def __init__(self, app):
        schema = graphene.Schema(query=Query, mutation=Mutation)

        app.add_url_rule(
            '/graphql',
            view_func=GraphQLView.as_view('graphql',
                                          schema=schema,
                                          graphiql=app.config['GRAPHIQL'])
        )

        schema_json = schema.introspect()

        @app.route("/schema")
        def schema_view():
            return jsonify(schema_json)

        print('[INFO] GraphQLView was successfully added with GraphiQL:{0}'.format(app.config['GRAPHIQL'])) 
Example #5
Source File: __init__.py    From flask-graphql-neo4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_app():
    app = Flask(__name__)
    app.add_url_rule('/graphql', view_func=GraphQLView.as_view(
        'graphql', schema=schema, graphiql=True)
    )

    @app.errorhandler(404)
    def page_not_found(e):
        return jsonify({'message': 'The requested URL was not found on the server.'}), 404

    return app 
Example #6
Source File: app.py    From flask-graphql with MIT License 5 votes vote down vote up
def create_app(path='/graphql', **kwargs):
    # backend = GraphQLCachedBackend(GraphQLQuiverBackend({"async_framework": "PROMISE"}))
    backend = None
    app = Flask(__name__)
    app.debug = True
    app.add_url_rule(path, view_func=GraphQLView.as_view('graphql', schema=Schema, backend=backend, **kwargs))
    return app 
Example #7
Source File: __init__.py    From Flask-GraphQL-Graphene-MySQL-Docker-StarterKit with MIT License 4 votes vote down vote up
def create_app():
    app = Flask(__name__)
    app.config.from_object((set_environment_config()))

    jwt = JWTManager(app)

    @jwt.expired_token_loader
    def my_expired_token_callback():
        return jsonify({
            'status': 401,
            'sub_status': 42,
            'msg': 'The token has expired'
        }), 401

    db.init_app(app)

    from app.models.User import User
    from app.models.VerificationCode import VerificationCode

    @app.before_first_request
    def initialize_database():
        db.create_all()

    @app.route('/')
    def hello_world():
        return "Hello World"

    from app.schema import schema

    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()

    return app