{"id":13705473,"url":"https://github.com/graphql-python/sanic-graphql","last_synced_at":"2025-04-09T21:13:35.408Z","repository":{"id":57463842,"uuid":"83938677","full_name":"graphql-python/sanic-graphql","owner":"graphql-python","description":"Adds GraphQL support to your Sanic app.","archived":false,"fork":false,"pushed_at":"2020-08-07T18:39:07.000Z","size":394,"stargazers_count":149,"open_issues_count":12,"forks_count":19,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T21:13:29.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graphql-python.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-05T02:20:19.000Z","updated_at":"2024-04-20T15:54:44.000Z","dependencies_parsed_at":"2022-09-05T06:01:25.100Z","dependency_job_id":null,"html_url":"https://github.com/graphql-python/sanic-graphql","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-python%2Fsanic-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-python%2Fsanic-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-python%2Fsanic-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-python%2Fsanic-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphql-python","download_url":"https://codeload.github.com/graphql-python/sanic-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T22:00:42.131Z","updated_at":"2025-04-09T21:13:35.385Z","avatar_url":"https://github.com/graphql-python.png","language":"Python","funding_links":[],"categories":["Extensions","Python"],"sub_categories":["API"],"readme":"[![Build Status](https://travis-ci.org/graphql-python/sanic-graphql.svg?branch=master)](https://travis-ci.org/graphql-python/sanic-graphql)\n[![Coverage Status](https://coveralls.io/repos/github/graphql-python/sanic-graphql/badge.svg?branch=master)](https://coveralls.io/github/graphql-python/sanic-graphql?branch=master)\n[![PyPI version](https://badge.fury.io/py/Sanic-GraphQL.svg)](https://badge.fury.io/py/Sanic-GraphQL)\n\nSanic-GraphQL\n=============\n\nAdds [GraphQL] support to your [Sanic] application.\n\nBased on [flask-graphql] by [Syrus Akbary].\n\nUsage\n-----\n\nUse the `GraphQLView` view from`sanic_graphql`\n\n```python\nfrom sanic_graphql import GraphQLView\nfrom sanic import Sanic\n\nfrom schema import schema\n\napp = Sanic(name=\"Sanic Graphql App\")\n\napp.add_route(\n    GraphQLView.as_view(schema=schema, graphiql=True),\n    '/graphql'\n)\n\n# Optional, for adding batch query support (used in Apollo-Client)\napp.add_route(\n    GraphQLView.as_view(schema=schema, batch=True),\n    '/graphql/batch'\n)\n\nif __name__ == '__main__':\n    app.run(host='0.0.0.0', port=8000)\n```\n\nThis will add `/graphql` endpoint to your app and enable the GraphiQL IDE.\n\n### Supported options for GraphQLView\n\n * `schema`: The `GraphQLSchema` object that you want the view to execute when it gets a valid request.\n * `context`: A value to pass as the `context_value` to graphql `execute` function. By default is set to `dict` with request object at key `request`.\n * `root_value`: The `root_value` you want to provide to graphql `execute`.\n * `pretty`: Whether or not you want the response to be pretty printed JSON.\n * `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).\n * `graphiql_version`: The graphiql version to load. Defaults to **\"1.0.3\"**.\n * `graphiql_template`: Inject a Jinja template string to customize GraphiQL.\n * `graphiql_html_title`: The graphiql title to display. Defaults to **\"GraphiQL\"**.\n * `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses \n`Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer.\n * `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))\n * `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).\n * `max_age`: Sets the response header Access-Control-Max-Age for preflight requests.\n * `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).\n * `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.\n * `enable_async`: whether `async` mode will be enabled.\n * `subscriptions`: The GraphiQL socket endpoint for using subscriptions in graphql-ws.\n * `headers`: An optional GraphQL string to use as the initial displayed request headers, if not provided, the stored headers will be used.\n * `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.\n* `header_editor_enabled`: An optional boolean which enables the header editor when true. Defaults to **false**.\n* `should_persist_headers`:  An optional boolean which enables to persist headers to storage when true. Defaults to **false**.\n\n\nYou can also subclass `GraphQLView` and overwrite `get_root_value(self, request)` to have a dynamic root value per request.\n\n```python\nclass UserRootValue(GraphQLView):\n    def get_root_value(self, request):\n        return request.user\n```\n\n\n## Contributing\nSince v3, `sanic-graphql` code lives at [graphql-server](https://github.com/graphql-python/graphql-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 at [CONTRIBUTING.md](https://github.com/graphql-python/graphql-server/blob/master/CONTRIBUTING.md).\n\n\n## License\n\nCopyright for portions of project [sanic-graphql] are held by [Syrus Akbary] as part of project [flask-graphql]. All other copyright \nfor project [sanic-graphql] are held by [Sergey Porivaev].\n\nThis project is licensed under MIT License.\n\n  [GraphQL]: http://graphql.org/\n  [Sanic]: https://github.com/channelcat/sanic\n  [flask-graphql]: https://github.com/graphql-python/flask-graphql\n  [Syrus Akbary]: https://github.com/syrusakbary\n  [GraphiQL]: https://github.com/graphql/graphiql\n  [Apollo-Client]: http://dev.apollodata.com/core/network.html#query-batching\n  [ReactRelayNetworkLayer]: https://github.com/nodkz/react-relay-network-layer\n  [Sergey Porivaev]: https://github.com/grazor\n  [sanic-graphql]: https://github.com/grazor/sanic-graphql\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-python%2Fsanic-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphql-python%2Fsanic-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-python%2Fsanic-graphql/lists"}