Skip to content

Commit e171f47

Browse files
authored
Update v16 interceptor docs for removed IOperationMessagePayload.As<T> (#9731)
1 parent 0401891 commit e171f47

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

website-next/content/docs/hotchocolate/migrating/migrate-from-15-to-16.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,36 @@ We removed the following methods from the `IExecutionDiagnosticEventListener` si
11081108

11091109
Some other methods also had a change in their signature - simply override them again to fix any compilation issues.
11101110

1111+
## IOperationMessagePayload exposes raw JSON
1112+
1113+
The `IOperationMessagePayload` interface, used by `ISocketSessionInterceptor` hooks (`OnConnectAsync`, `OnPingAsync`, `OnPongAsync`), no longer exposes the `As<T>()` deserialization helper. It now provides direct access to the raw `JsonElement?` through a `Payload` property:
1114+
1115+
```diff
1116+
-public interface IOperationMessagePayload
1117+
-{
1118+
- T? As<T>() where T : class;
1119+
-}
1120+
+public interface IOperationMessagePayload
1121+
+{
1122+
+ JsonElement? Payload { get; }
1123+
+}
1124+
```
1125+
1126+
If you were calling `.As<T>()` to deserialize the payload, switch to `Payload?.Deserialize<T>()`:
1127+
1128+
```diff
1129+
public override ValueTask<ConnectionStatus> OnConnectAsync(
1130+
ISocketSession session,
1131+
IOperationMessagePayload connectionInitMessage,
1132+
CancellationToken cancellationToken = default)
1133+
{
1134+
- var payload = connectionInitMessage.As<MyConnectPayload>();
1135+
+ var payload = connectionInitMessage.Payload?.Deserialize<MyConnectPayload>();
1136+
1137+
// ...
1138+
}
1139+
```
1140+
11111141
## Experimental @semanticNonNull support removed
11121142

11131143
Hot Chocolate v15 included experimental support for the `@semanticNonNull` directive, which let you mark fields as semantically non-null while still returning `null` (rather than propagating to the parent) when a resolver errored. We've removed this feature in v16 in favor of the [`onError` proposal](https://github.com/graphql/graphql-spec/pull/1163).

website/src/docs/hotchocolate/v16/server/interceptors.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ public override ValueTask<ConnectionStatus> OnConnectAsync(
176176
ISocketSession session, IOperationMessagePayload connectionInitMessage,
177177
CancellationToken cancellationToken)
178178
{
179-
if (connectionInitMessage.As<Dictionary<string, object?>>()
180-
?.TryGetValue("authToken", out var token) == true)
179+
if (connectionInitMessage.Payload is { ValueKind: JsonValueKind.Object } payload
180+
&& payload.TryGetProperty("authToken", out var token)
181+
&& token.ValueKind == JsonValueKind.String)
181182
{
183+
var authToken = token.GetString();
182184
// Validate token ...
183185
}
184186

0 commit comments

Comments
 (0)