-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL Mutation Result Deserialization Issues (When Using System.Text.Json.JsonSerializer) #1089
Comments
To deserialize automatically, try using the generic overload |
Referring to my original report (near the bottom), you will see that I originally tried the generic method you mentioned. It was the exception being thrown from this generic method which lead lead me to investigating the issue further. As mentioned, out of the box using the automatic deserialization fails with the exception I posted. |
Further to this, it appears that I am only having issues with |
Thanks for the detailed investigation so far @mike-a-stephens. I'm going to be working on the GraphService in the next day or so, especially picking up an old PR I never finished in #1051. I will be sure to get this fixed and add test cases for this deserialization issue. |
@nozzlegear The problem is caused by the schema generated file GraphQLSchema.generated.cs. // ...
[JsonDerivedType(typeof(ReturnLineItem), typeDiscriminator: "ReturnLineItem")]
[JsonDerivedType(typeof(ReturnLineItem), typeDiscriminator: "ReturnLineItem")]
// ...
public interface INode : IGraphQLObject
// ... The I've been unable to upgrade beyond 6.17.0 due to this issue meaning we're stuck on 2024-04 for now. Is it possible to get a point upgrade with this minor change in it? |
Interesting, thanks for digging in and finding that @RobJDavey. I'm working on the GraphQL service right now and will be regenerating the schema file for 2024-10 as well. I'll double check for that issue and if it's still in there I'll just manually edit it out before releasing, then I'll have to dig in and find out why it's doing that. |
Good catch. |
Fixed by #1101 |
This should be fixed in the new pre-release nuget package and will be fixed in the next release nuget. |
When deserializing the response from a GraphQL mutation, System.Text.Json.JsonSerializer is throwing an exception, whereas NetwtonSoft can deserialize the response successfully.
For example, using the following code:
The NewtonSoft deserializer succeeds and returns the deserialized object, however System.Text.Json deserializer fails with the following exception:
System.InvalidOperationException
HResult=0x80131509
Message=The polymorphic type 'ShopifySharp.GraphQL.INode' has already specified derived type 'ShopifySharp.GraphQL.ReturnLineItem'.
Source=System.Text.Json
StackTrace:
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_DerivedTypeIsAlreadySpecified(Type baseType, Type derivedType)
at System.Text.Json.Serialization.Metadata.PolymorphicTypeResolver..ctor(JsonSerializerOptions options, JsonPolymorphismOptions polymorphismOptions, Type baseType, Boolean converterCanHaveMetadata)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable
1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable
1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable
1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable
1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable
1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable
1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
--- End of stack trace from previous location ---
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|172_0()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
: : : : : : : : : : : : : : : : : : : : : : : : : : : :
This appears to be causing the generic ShopifySharp SendAsync methods to fail when processing the response of a mutation.
For example, in my original attempt at implementing the productCreate call, I used code similar to the following:
but was getting the exception thrown above, which lead me to try deserializing manually with NewtonSoft.
Am I doing something wrong, or is there indeed an issue when using System.Text.Json.JsonSerializer.Deserialize<>() ?
The text was updated successfully, but these errors were encountered: