Shopify / shopify-api-js

Shopify Admin API Library for Node. Accelerate development with support for authentication, graphql proxy, webhooks
MIT License
944 stars 390 forks source link

Rest resource `Shop.all()` returns the complete response #1300

Closed nullndr closed 7 months ago

nullndr commented 7 months ago

The call to admin.rest.resources.Shop.all({ session }) returns the whole response, and not just the data[0] object:

https://github.com/Shopify/shopify-api-js/blob/eae4573cbe6991c4bda8044c1668dde9980bc9a3/packages/shopify-api/rest/admin/2024-01/shop.ts#L44

Like the Customer resurce, it should returns the following:

return response.data ? response.data[0] : null;
nullndr commented 7 months ago

May I open a PR for this?

paulomarg commented 7 months ago

Hi, thanks for raising this! This method is a bit of an odd one out because that API behaves a little different to the others.

Instead of changing the all method (which would be a breaking change), I wonder if it would be better to create a brand new method (Shop.current()?) that returns the first instance in data, similar to Customer.find().

I'll add this to our tracking, but to be transparent there are other things that would be done before this, so it might be a while before we can get to it. If you can open a PR, we'll be happy to review / merge it!

nullndr commented 7 months ago

Hi @paulomarg, I do think that the use of Shop.all() is a bit confusioning to retrieve the store info, so I agree with the Shop.current() method.

I'll open a PR.