ndimatteo / HULL

💀 Headless Shopify Starter – powered by Next.js + Sanity.io
https://hull.dev
MIT License
1.38k stars 173 forks source link

Encountered a field that is not defined in the schema. #104

Closed myeljoud closed 2 years ago

myeljoud commented 2 years ago

After cloning the studio locally and linking it with my Shopify store, the products won't show up correctly. I have tried to make it work but could not, it took me days. Now I need some help so I can proceed.

Screen Shot 2022-07-27 at 20 30 44 Screen Shot 2022-07-27 at 20 30 58 Screen Shot 2022-07-27 at 20 31 06

Apparently, it is a schema error.

Here is some information that might be useful or relevant:

Screen Shot 2022-07-27 at 20 36 10

Any help is appreciated, and thanks for the excellent template!

ndimatteo commented 2 years ago

Hey there @medyahyejoud! It looks like you're using the Sanity Connect app (created by Sanity) to sync data. This is incompatible with HULL, which uses its own sync solution using custom Next.js API endpoints with Shopify webhooks.

This is why the data isn't coming in properly for you when using HULL! Please try following steps #2 and #3 of the readme to properly set up Shopify for syncing.

myeljoud commented 2 years ago

Hello, @ndimatteo thanks for the quick answer, yes I installed Sanity Connect and it is what causes the problem. I'm doing it all together again, I wanted to set up a studio separate from my Next app because I'm doing the App with custom design and custom modules, and trying to link the studio with the Next app and a React Native app.

Is there a way to separate them while syncing the products and a standalone Studio? I want to understand where the syncing happens and is shown and what parts of the template are critical for the sync process.

And thanks again.

ndimatteo commented 2 years ago

No problem @medyahyejoud!

The main syncing (create/update) happens through this API route, which receives the Shopify webhook payload for the product.

You can still run your studio separately from the Next app. The API routes are only used for the Shopify webhooks to handle actually writing the data to your Sanity dataset (much like the Sanity Connect app).

You could always pull these API routes out and put them on their own instance if you truly want that part to be separate from your main Next.js application.

I hope that helps!

myeljoud commented 2 years ago

Good evening @ndimatteo, hope you had a wonderful day.

Thanks a lot, that worked well for me I separated the two applications. After syncing some products I noticed that the images are not synced, I noticed that the sync should be triggered by this route and this route is linked with action resolver in Sanity Studio, but the images are not syncing maybe I'm missing some queue or something

ndimatteo commented 2 years ago

Glad that worked @medyahyejoud!

Just to clarify: images are synced from Sanity -> Shopify (not the other way around). The Sanity Action that triggers this creates the URL to ping that API route you linked (/api/shopify/product-images) based on the domain set in the "General Settings" document. You can see that here: https://github.com/ndimatteo/HULL/blob/main/studio/parts/resolve-actions.js#L68-L75

Since you separated out your API routes from your storefront account, it's likely that it's trying to ping your storefront domain name with that API route, instead of your separate application. Can you confirm if that's the case?

If so, I'd suggest modifying the action to pull the domain from another field (perhaps you could add a field in the settings for this, something like: Shopify Sync Domain, and use that in the action to create the correct link.

Once you do that, it should take any cartPhotos associated with the product and push them to Shopify to correspond with their matched variant.

myeljoud commented 2 years ago

Hey @ndimatteo, I already have a lot of products in Shopify with their corresponding images and description, I just need a way to pull those images and their descriptions to Sanity, not the other way around. As for the images syncing from Sanity -> Shopify.

Thanks.

ndimatteo commented 2 years ago

Gotcha @medyahyejoud! Since HULL takes a different approach to handling presentation data, you'll need to adapt the sync function to meet your needs with photos.

The webhook payload that the sync function ingests includes an images array, that you could parse to upload the assets to Sanity and then patch the product with image references.

It's not a small task, but shouldn't be too difficult to do. Beyond the Sanity client docs for uploading assets, you can also see how Midway (another headless Shopify starter) handles uploading Shopify images and associating them with documents here: https://github.com/ctrl-alt-del-world/midway/blob/master/web/src/lambda/shopify-sync.ts#L98-L115

ndimatteo commented 2 years ago

I'm also going to mark this as closed, as the original issue is resolved, and this is a customization that goes beyond what HULL is responsible for at this time.

Good luck, and feel free to open a new issue if something specific comes up in relation to core HULL functionality! 🤘

myeljoud commented 2 years ago

Thanks a bunch, guys that were a lot of help, good luck!