-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable conditional acknowledgment of WS connections. (#3720)
Co-authored-by: Patrick Arminio <[email protected]>
- Loading branch information
1 parent
45f4e50
commit e105975
Showing
22 changed files
with
609 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"executed", | ||
"executes", | ||
"execution", | ||
"reject", | ||
"special", | ||
"primitive", | ||
"invalid", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Release type: minor | ||
|
||
This release adds a new `on_ws_connect` method to all HTTP view integrations. | ||
The method is called when a `graphql-transport-ws` or `graphql-ws` connection is | ||
established and can be used to customize the connection acknowledgment behavior. | ||
|
||
This is particularly useful for authentication, authorization, and sending a | ||
custom acknowledgment payload to clients when a connection is accepted. For | ||
example: | ||
|
||
```python | ||
class MyGraphQLView(GraphQLView): | ||
async def on_ws_connect(self, context: Dict[str, object]): | ||
connection_params = context["connection_params"] | ||
|
||
if not isinstance(connection_params, dict): | ||
# Reject without a custom graphql-ws error payload | ||
raise ConnectionRejectionError() | ||
|
||
if connection_params.get("password") != "secret: | ||
# Reject with a custom graphql-ws error payload | ||
raise ConnectionRejectionError({"reason": "Invalid password"}) | ||
|
||
if username := connection_params.get("username"): | ||
# Accept with a custom acknowledgement payload | ||
return {"message": f"Hello, {username}!"} | ||
|
||
# Accept without a acknowledgement payload | ||
return await super().on_ws_connect(context) | ||
``` | ||
|
||
Take a look at our documentation to learn more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.