graphql-dotnet / graphql-dotnet/graphql-client
Netwtonsoft `MissingMemberHandling.Error` is incompatible with receiving web socket messages
- Dominant language
- C#
- Stars
- 648
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
My goal is to be able to utilise the `MissingMemberHandling.Error` option of the `JsonSerializerSettings`, instead of the default `MissingMemberHandling.Ignore`.
Why? because its a very useful way to ensure that the classes I'm crafting as deserialization targets for my queries actually match the queries being sent. It makes it impossible to accidently query for something that will be ignored during serialization, as this will throw a `JsonSerializationException`
This works perfectly for regular queries and mutations. But not for subscriptions or `UseWebSocketForQueriesAndMutations = true`
Instead, I get this exception thrown deep from `ReceiveWebsocketMessagesAsync`
```
Newtonsoft.Json.JsonSerializationException: Could not find member 'payload' on object of type 'WebsocketMessageWrapper'. Path 'payload', line 1, position 65.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
at GraphQL.Client.Serializer.Newtonsoft.NewtonsoftJsonSerializer.DeserializeFromUtf8Stream[T](Stream stream) in /_/src/GraphQL.Client.Serializer.Newtonsoft/NewtonsoftJsonSerializer.cs:line 54
at GraphQL.Client.Serializer.Newtonsoft.NewtonsoftJsonSerializer.DeserializeToWebsocketResponseWrapperAsync(Stream stream) in /_/src/GraphQL.Client.Serializer.Newtonsoft/NewtonsoftJsonSerializer.cs:line 41
at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.ReceiveWebsocketMessagesAsync() in /_/src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs:line 524
```
I've captured the offending response from the server. And it does indeed have a `payload` property, (the value of which is all from my GraphQL api)
```
"{\"type\":\"data\",\"id\":\"80fdadc12c0b44bc84115ce7231cb096\",\"payload\":{\"data\":{\"data\":{\"comment\":{\"id\":\"1408af422d\"},\"id\":\"1408af422d\",\"type\":\"CREATED\"}}}}"
```
But poking around a little, this seems like an indented outcome seeing as `WebsocketMessageWrapper` does not need to store the `payload`
---
I was wondering if this was intentional, as it's preventing me from using this serializer setting for my entire SDK.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.