Skip to content

Commit

Permalink
Merge pull request #47 from tartiflette/ISSUE-46
Browse files Browse the repository at this point in the history
ISSUE-46 - Properly injects the "executor_context" into the "aiohttp" subscription handler
  • Loading branch information
Maximilien-R authored Sep 5, 2019
2 parents e2c48e0 + 2c5e6d1 commit 85d349d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Released]

- [0.8.x]
- [0.8.5](./changelogs/0.8.5.md) - 2019-09-04
- [0.8.4](./changelogs/0.8.4.md) - 2019-08-13
- [0.8.3](./changelogs/0.8.3.md) - 2019-08-13
- [0.8.2](./changelogs/0.8.2.md) - 2019-07-03
Expand Down
5 changes: 5 additions & 0 deletions changelogs/0.8.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [0.8.5] -- 2019-09-04

## Fixed

- Properly injects the `executor_context` into the `aiohttp` subscription handler [#25](https://github.com/tartiflette/tartiflette-aiohttp/issues/46) thrown by @jonypawks
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"isort==4.3.21",
]

_VERSION = "0.8.4"
_VERSION = "0.8.5"

_PACKAGES = find_packages(exclude=["tests*"])

Expand Down
16 changes: 11 additions & 5 deletions tartiflette_aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ def validate_and_compute_graphiql_option(


def _set_subscription_ws_handler(
app: "Application", subscription_ws_endpoint: Optional[str]
app: "Application",
subscription_ws_endpoint: Optional[str],
context: Dict[str, Any],
) -> None:
if not subscription_ws_endpoint:
return

app.router.add_route(
"GET", subscription_ws_endpoint, AIOHTTPSubscriptionHandler(app)
"GET",
subscription_ws_endpoint,
AIOHTTPSubscriptionHandler(app, context),
)


Expand Down Expand Up @@ -102,7 +106,7 @@ def register_graphql_handlers(
app: "Application",
engine_sdl: str = None,
engine_schema_name: str = "default",
executor_context: dict = None,
executor_context: Optional[Dict[str, Any]] = None,
executor_http_endpoint: str = "/graphql",
executor_http_methods: List[str] = None,
engine: Engine = None,
Expand All @@ -121,7 +125,7 @@ def register_graphql_handlers(
app {aiohttp.web.Application} -- The application to register to.
engine_sdl {str} -- The SDL defining your API (default: {None})
engine_schema_name {str} -- The name of your sdl (default: {"default"})
executor_context {dict} -- Context dict that will be passed to the resolvers (default: {None})
executor_context {Optional[Dict[str, Any]]} -- Context dict that will be passed to the resolvers (default: {None})
executor_http_endpoint {str} -- Path part of the URL the graphql endpoint will listen on (default: {"/graphql"})
executor_http_methods {list[str]} -- List of HTTP methods allowed on the endpoint (only GET and POST are supported) (default: {None})
engine {Engine} -- An uncooked engine, or a create_engine coroutines (default: {None})
Expand Down Expand Up @@ -176,7 +180,9 @@ def register_graphql_handlers(
except AttributeError:
raise Exception("Unsupported < %s > http method" % method)

_set_subscription_ws_handler(app, subscription_ws_endpoint)
_set_subscription_ws_handler(
app, subscription_ws_endpoint, executor_context
)

_set_graphiql_handler(
app,
Expand Down
11 changes: 7 additions & 4 deletions tartiflette_aiohttp/_subscription_ws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
_ALLOWED_ERROR_TYPES = [GQL_CONNECTION_ERROR, GQL_ERROR]


def _get_graphql_params(payload: Dict[str, Any]) -> Dict[str, Any]:
def _get_graphql_params(
payload: Dict[str, Any], context: Dict[str, Any]
) -> Dict[str, Any]:
return {
"query": payload.get("query"),
"variables": payload.get("variables"),
"operation_name": payload.get("operationName"),
"context": payload.get("context"),
"context": context,
}


Expand Down Expand Up @@ -77,8 +79,9 @@ async def close(self, code: int) -> None:


class AIOHTTPSubscriptionHandler:
def __init__(self, app: "Application") -> None:
def __init__(self, app: "Application", context: Dict[str, Any]) -> None:
self._app: "Application" = app
self._context = context

async def _send_message(
self,
Expand Down Expand Up @@ -143,7 +146,7 @@ async def _on_start(
operation_id: str,
payload: Dict[str, Any],
) -> None:
params = _get_graphql_params(payload)
params = _get_graphql_params(payload, self._context)
if not isinstance(params, dict):
return await self._send_error(
connection_context,
Expand Down

0 comments on commit 85d349d

Please sign in to comment.