Skip to content

Commit 9204d32

Browse files
committed
Don't fall back to Apollo when not in subprotocols
If the server doesn't return Sec-WebSocket-Protocol, we can't default to graphql-ws (ie Apollo) if the transport was configured without it as a subprotocol. In that situation, default to graphql-transport-ws (GRAPHQLWS).
1 parent b57afa6 commit 9204d32

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

gql/transport/websockets_protocol.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,15 @@ async def _after_connect(self):
479479
# Find the backend subprotocol returned in the response headers
480480
try:
481481
self.subprotocol = self.response_headers["Sec-WebSocket-Protocol"]
482+
log.debug(f"backend subprotocol returned: {self.subprotocol!r}")
482483
except KeyError:
483-
# If the server does not send the subprotocol header, using
484-
# the apollo subprotocol by default
485-
self.subprotocol = self.APOLLO_SUBPROTOCOL
486-
487-
log.debug(f"backend subprotocol returned: {self.subprotocol!r}")
484+
# If the server does not send the subprotocol header, use
485+
# the apollo subprotocol by default unless we didn't ask for it
486+
if self.APOLLO_SUBPROTOCOL in self.adapter.subprotocols:
487+
self.subprotocol = self.APOLLO_SUBPROTOCOL
488+
else:
489+
self.subprotocol = self.GRAPHQLWS_SUBPROTOCOL
490+
log.debug(f"backend returned no subprotocol, using: {self.subprotocol!r}")
488491

489492
async def _after_initialize(self):
490493

0 commit comments

Comments
 (0)