ShopifySharp icon indicating copy to clipboard operation
ShopifySharp copied to clipboard

Support for Meta Objects?

Open jpboskdnz opened this issue 1 year ago • 7 comments

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

jpboskdnz avatar May 15 '24 11:05 jpboskdnz

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

tcorvin avatar May 21 '24 18:05 tcorvin

@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?

jpboskdnz avatar May 23 '24 08:05 jpboskdnz

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.

nozzlegear avatar May 23 '24 16:05 nozzlegear

@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 avatar May 25 '24 01:05 clement911

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

clement911 avatar May 25 '24 02:05 clement911

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 :-)

jpboskdnz avatar May 28 '24 11:05 jpboskdnz

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.

mysteryx93 avatar Sep 18 '24 01:09 mysteryx93