Fix bugs with transport-ws-protocol#111
Fix bugs with transport-ws-protocol#111syrusakbary merged 1 commit intographql-python:v3from ayys:v3-bugfixes-transport-ws-protocol
Conversation
I am guessing this branch was only used with GraphQLWSHandler, and not with GraphQLTransportWSHandler. That's probably why there were a bunch of bugs. This PR fixes those.
| return await self._get_context(request=self._ws) | ||
| return await self._get_context(self._ws) | ||
|
|
||
| async def get_root_value(self) -> Any: | ||
| return await self._get_root_value(request=self._ws) | ||
| return await self._get_root_value(self._ws) |
There was a problem hiding this comment.
Removed this because channels/graphql_ws.py doesn't specify the argument name either.
There was a problem hiding this comment.
Side note: graphql_ws.py and graphql_transport_ws.py have alot of duplicate code that could be merged. I will not do that in this PR though.
| await self._ws.accept( | ||
| subprotocol=BaseGraphQLTransportWSHandler.GRAPHQL_TRANSPORT_WS_PROTOCOL | ||
| ) | ||
| await self._ws.accept(subprotocol=BaseGraphQLTransportWSHandler.PROTOCOL) |
There was a problem hiding this comment.
wrong variable name was being used :/
| async def send_message(self, data: Message) -> None: | ||
| data = data.asdict() | ||
| assert ( | ||
| data.get("type") is not None | ||
| ), "expected dict with `type` field. Got {} instead".format(data) | ||
| await self.send_json(data) |
There was a problem hiding this comment.
Use dataclasses instead of TypedDicts. TypeDict is just a dict at runtime, and is only used for typehinting. That means data.type would not have worked.
sidenote: we should do the same for graphql_ws.py too.
|
|
||
| from .contstants import ( | ||
| GQL_CONNECTION_INIT, | ||
| GQL_CONNECTION_ACK, |
There was a problem hiding this comment.
These constants should probably be an enum, but fixing that shouldn't be part of this PR
I am guessing the
v3branch was only used withGraphQLWSHandler, and not withGraphQLTransportWSHandler. That's probably why there were a bunch of bugs. This PR fixes the errors I got when trying to use subscriptions with thegraphql-transport-wsprotocol.The first error I got was
I implemented this function and the error went away.
Second error was with message types - they were
TypedDicts, but typeddicts are essentially dicts.This means additional fields specified are not properly used. I fixed it by converting them to
dataclassesand adding ato_dictfield to it.