Skip to content
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 orderCancel throws exception #1109

Open
MusicMonkey5555 opened this issue Nov 19, 2024 · 2 comments
Open

GraphQL orderCancel throws exception #1109

MusicMonkey5555 opened this issue Nov 19, 2024 · 2 comments

Comments

@MusicMonkey5555
Copy link

MusicMonkey5555 commented Nov 19, 2024

When making the request:

var orderRequest = new GraphRequest()
{
				query =
				@"mutation orderCancel($notifyCustomer:Boolean!, $orderId: ID!, $reason: OrderCancelReason!, $refund: Boolean!, $restock: Boolean!, $staffNote: String!) {
        orderCancel(notifyCustomer: $notifyCustomer, orderId: $orderId, reason: $reason, refund: $refund, restock: $restock, staffNote: $staffNote) {
            job {
                done,
                id
            }
            orderCancelUserErrors {
                code,
                field,
                message
            }
        }
    }",
				variables = new
				{
								notifyCustomer = false,
								orderId = "gid://shopify/Order/11239781433711",
								reason = "CUSTOMER",
								refund = true,
								restock = true,
								staffNote = "Test Order for free item",
				}
};

//Make the API call
var orderResponse = new ShopifySharp.GraphQL.OrderCancelPayload();
try
{
				orderResponse = _graphService.SendAsync<ShopifySharp.GraphQL.OrderCancelPayload>(orderRequest).Result;
}
catch (Exception ex)
{

}

The exception:

{
  "ClassName": "System.AggregateException",
  "Message": "One or more errors occurred.",
  "Data": {
    
  },
  "InnerException": {
    "ClassName": "System.InvalidOperationException",
    "Message": "The polymorphic type 'ShopifySharp.GraphQL.INode' has already specified derived type 'ShopifySharp.GraphQL.ReturnLineItem'.",
    "Data": null,
    "InnerException": null,
    "HelpURL": null,
    "StackTraceString": "   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_DerivedTypeIsAlreadySpecified(Type baseType, Type derivedType)\r\n   at System.Text.Json.Serialization.Metadata.PolymorphicTypeResolver..ctor(JsonSerializerOptions options, JsonPolymorphismOptions polymorphismOptions, Type baseType, Boolean converterCanHaveMetadata)\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)\r\n   at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)\r\n   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)\r\n   at ShopifySharp.GraphQL.Serializer.Deserialize[T](String json)\r\n   at ShopifySharp.GraphService.SendAsync[TResult](GraphRequest request, Nullable`1 graphqlQueryCost, CancellationToken cancellationToken)",
    "RemoteStackTraceString": null,
    "RemoteStackIndex": 0,
    "ExceptionMethod": null,
    "HResult": -2146233079,
    "Source": "System.Text.Json",
    "WatsonBuckets": null
  },
  "HelpURL": null,
  "StackTraceString": "   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)\r\n   at sf_ERP_Shopify_Sync_GraphQL.Orders.Push() in C:\\Repos\\sf_Shopify_ERP_Sync\\sf_ERP_Shopify_Sync_GraphQL\\Orders.cs:line 585",
  "RemoteStackTraceString": null,
  "RemoteStackIndex": 0,
  "ExceptionMethod": null,
  "HResult": -2146233088,
  "Source": "System.Private.CoreLib",
  "WatsonBuckets": null,
  "InnerExceptions": [
    {
      "ClassName": "System.InvalidOperationException",
      "Message": "The polymorphic type 'ShopifySharp.GraphQL.INode' has already specified derived type 'ShopifySharp.GraphQL.ReturnLineItem'.",
      "Data": null,
      "InnerException": null,
      "HelpURL": null,
      "StackTraceString": "   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_DerivedTypeIsAlreadySpecified(Type baseType, Type derivedType)\r\n   at System.Text.Json.Serialization.Metadata.PolymorphicTypeResolver..ctor(JsonSerializerOptions options, JsonPolymorphismOptions polymorphismOptions, Type baseType, Boolean converterCanHaveMetadata)\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()\r\n   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType)\r\n   at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)\r\n   at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)\r\n   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)\r\n   at ShopifySharp.GraphQL.Serializer.Deserialize[T](String json)\r\n   at ShopifySharp.GraphService.SendAsync[TResult](GraphRequest request, Nullable`1 graphqlQueryCost, CancellationToken cancellationToken)",
      "RemoteStackTraceString": null,
      "RemoteStackIndex": 0,
      "ExceptionMethod": null,
      "HResult": -2146233079,
      "Source": "System.Text.Json",
      "WatsonBuckets": null
    }
  ]
}

It does actually cancel the order on the store, but just has an issue returning the response it looks like.
Let me know if you need any more info.

@MusicMonkey5555
Copy link
Author

I guess I will also add I'm running it as a .net 8 console application and tried it on system.text.json 8.0.5 as well as upgraded to 9.0.0 and ShopifySharp 6.18.0 as well as 6.19.0. The output above is from everything being upgraded in case it was fixed.

@nozzlegear
Copy link
Owner

Thanks for the report! Could you try the latest pre-release version of ShopifySharp (version 6.19.0-b215) on Nuget and see if you get this same exception when using it?

dotnet add package ShopifySharp --version 6.19.0-b215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants