本文整理汇总了Python中flask_graphql.GraphQLView.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python GraphQLView.as_view方法的具体用法?Python GraphQLView.as_view怎么用?Python GraphQLView.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_graphql.GraphQLView
的用法示例。
在下文中一共展示了GraphQLView.as_view方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: after_init_app
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
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)
示例2: create_app
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
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
示例3: __init__
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
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']))
示例4: graphql_token_view
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
def graphql_token_view():
view = GraphQLView.as_view('graphql', schema=schema, graphiql=bool(app.config.get("DEBUG", False)))
view = jwt_required()(view)
return view
示例5: create_app
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
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
示例6: create_app
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
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
示例7: create_app
# 需要导入模块: from flask_graphql import GraphQLView [as 别名]
# 或者: from flask_graphql.GraphQLView import as_view [as 别名]
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