nozzlegear / ShopifySharp

ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores.
https://nozzlegear.com/shopify-development-handbook
MIT License
742 stars 308 forks source link

(GraphService) Deserialization Exception When Querying Products with Media in ShopifySharp 6.13.0 #1027

Closed AnandPrabha closed 6 months ago

AnandPrabha commented 6 months ago

Hello,

I've encountered an issue with ShopifySharp version 6.13.0 when trying to query products along with their media information. Specifically, the problem arises when I execute a GraphQL query to fetch products and their associated media. Here is the query I am using: { products(first: 1) { nodes { id title media(first: 1) { nodes { alt id mediaContentType preview { image { id url } } } } } } } Upon executing this query, I receive the following exception: One or more errors occurred. (Deserialization of interface types is not supported. Type 'ShopifySharp.GraphQL.IMedia'. Path: $.nodes[0].media.nodes[0] | LineNumber: 0 | BytePositionInLine: 36.) seems that the library struggles to handle the deserialization of interface types correctly, particularly when fetching media nodes associated with products. I would appreciate any guidance on how to resolve this issue or if there are any workarounds available

nozzlegear commented 6 months ago

Thanks for the report @AnandPrabha! Could you show me the code you're using to send the Graph query?

clement911 commented 6 months ago

This is expected, although we should document it. Because Media is an interface, you must include the typename field so that the serializer knows which type to deserialize to. Note that the typename field must be the FIRST field in the object.

The query below should work.

{ products(first: 1) { nodes { id title media(first: 1) { nodes { alt id mediaContentType preview { image { __typename id url } } } } } } }

AnandPrabha commented 6 months ago

The suggested code didn't work initially. However, after trying to add typename to the media nodes, the issue was resolved. Here's the updated and working structure: {
products(first: 1) { nodes { id title media(first: 1) { nodes { **
typename** alt id mediaContentType preview { image { id url } } } } } } }

clement911 commented 6 months ago

Ah yes, I had it at the wrong place.