Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adds GraphQL support to your Flask application.

License

NotificationsYou must be signed in to change notification settings

graphql-python/flask-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adds GraphQL support to your Flask application.

travispypiAnaconda-Server Badgecoveralls

Usage

Just use theGraphQLView view fromflask_graphql

fromflaskimportFlaskfromflask_graphqlimportGraphQLViewfromschemaimportschemaapp=Flask(__name__)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',schema=schema,batch=True))if__name__=='__main__':app.run()

This will add/graphql endpoint to your app and enable the GraphiQL IDE.

Special Note for Graphene v3

If you are using theSchema type ofGraphene library, be sure to use thegraphql_schema attribute to pass as schema on theGraphQLView view. Otherwise, theGraphQLSchema fromgraphql-core is the way to go.

More info atGraphene v3 release notes andGraphQL-core 3 usage.

Supported options for GraphQLView

  • schema: TheGraphQLSchema object that you want the view to execute when it gets a valid request.
  • context: A value to pass as thecontext_value to graphqlexecute function. By default is set todict with request object at keyrequest.
  • root_value: Theroot_value you want to provide to graphqlexecute.
  • pretty: Whether or not you want the response to be pretty printed JSON.
  • graphiql: IfTrue, may presentGraphiQL when loaded directly from a browser (a useful tool for debugging and exploration).
  • graphiql_version: The graphiql version to load. Defaults to"1.0.3".
  • graphiql_template: Inject a Jinja template string to customize GraphiQL.
  • graphiql_html_title: The graphiql title to display. Defaults to"GraphiQL".
  • batch: Set the GraphQL view as batch (for using inApollo-Client orReactRelayNetworkLayer)
  • middleware: A list of graphqlmiddlewares.
  • encode: the encoder to use for responses (sensibly defaults tographql_server.json_encode).
  • format_error: the error formatter to use for responses (sensibly defaults tographql_server.default_format_error.
  • subscriptions: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
  • headers: An optional GraphQL string to use as the initial displayed request headers, if not provided, the stored headers will be used.
  • default_query: An optional GraphQL string to use when no query is provided and no stored query exists from a previous session. If not provided, GraphiQL will use its own default query.
  • header_editor_enabled: An optional boolean which enables the header editor when true. Defaults tofalse.
  • should_persist_headers: An optional boolean which enables to persist headers to storage when true. Defaults tofalse.

You can also subclassGraphQLView and overwriteget_root_value(self, request) to have a dynamic root valueper request.

classUserRootValue(GraphQLView):defget_root_value(self,request):returnrequest.user

Contributing

Since v3,flask-graphql code lives atgraphql-server repository to keep any breaking change on the base package on sync with all other integrations. In order to contribute, please take a look atCONTRIBUTING.md.

About

Adds GraphQL support to your Flask application.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors14


[8]ページ先頭

©2009-2025 Movatter.jp