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
747 stars 309 forks source link

Support for Meta Objects? #1068

Open jpboskdnz opened 4 months ago

jpboskdnz commented 4 months ago

Hi,

Is there any way to use Shopify's Meta Objects from ShopifySharp? I would like to save some structured data into Meta Objects, but the only reference I see within ShopifySharp is in the generated GraphQL Schema.

Glad to hear, thanks!

Best regards, JP

tcorvin commented 4 months ago

Hey all,

I believe this is related so I’ll post here… I’m trying to access MetafieldService through ShopifySharp: (I.e., var existingMetafields = await metafieldService.ListAsync(product.Id, "product");) And am getting a 404…seems like I’m doing everything correctly, but also seems like this is going through (or trying to go through) GraphQL Admin interface vs. my other stuff (which is working AND is going thru restful admin API.)

Any thoughts appreciated!

Thanks, Tyson

jpboskdnz commented 4 months ago

@tcorvin I don't think your question has anything to do with mine. Metaobjects and Metafields are different things in Shopify. However, I can answer your question. You're missing a 's' in the resourceType. It should be "products".

@nozzlegear Do you have any thoughts on Metaobjects? I can use them using the GraphService, but it looks like a bit complex. If this the way to go at the moment?

nozzlegear commented 4 months ago

Oh yes, sorry, I meant to get back to your question when I added that label! Unfortunately it is indeed complex at the moment using the GraphService and the generated schema objects. I've been using Metaobjects recently for a client's app and it was a bit of a pain to work with, so I'm actively working on improving the whole GraphQL experience with ShopifySharp starting with deprecating a bunch of the unnecessary overloads in #1051.

After I get that merged in the next couple of days, my plan is to dive into #1072. I don't have a time estimate for that, but ultimately I want to have a dotnet tool that will let you write the graph queries you're going to use for your metaobjects, then this tool will create specialized ShopifySharp services with exactly the entities and methods needed to make those requests. So for contrived example, if you only need the id and displayName fields on a Metaobject, then this special Metaobject entity would only have those fields.

In the meantime, I'll try to find the example code I was using to create Metaobjects and definitions using the current GraphService.

clement911 commented 4 months ago

@jpboskdnz I assume you've checked the API docs: https://shopify.dev/docs/api/admin-graphql/2024-04/objects/Metaobject

Using the GraphService, you should be able to do anything that is possible to do with the GraphQL API. Using the GraphService is actually very simple once you've used it a couple of times.

What are you trying to do exactly?

clement911 commented 4 months ago

Taking a look at the following file might be helpful: https://github.com/nozzlegear/ShopifySharp/blob/8ee5ebd423650aaf7aaa59978c0bf710bc7f4900/ShopifySharp.Tests/Graph_SendTests.cs#L10

jpboskdnz commented 4 months ago

Thanks @nozzlegear and @clement911 for pointing me into the right direction. Because we have created a somewhat complex structure in the Metaobjects, including translations in multiple languages, it's quite a work to put the data into Shopify using the GraphQL APIs. But it is what it is for now :-)

mysteryx93 commented 2 weeks ago

Oh, so Metaobjects are not supported at all by this library?

It's like Ontraport Custom Objects, I implemented support here https://github.com/mysteryx93/OntraportApi.NET?tab=readme-ov-file#custom-objects

Perhaps you could take inspiration from my design.