Shopify / shopify-app-js

MIT License
275 stars 109 forks source link

Theme Rest Resource doesn't have `fromData` applied automatically #1086

Open david-w-shopify opened 3 months ago

david-w-shopify commented 3 months ago

Issue summary

Before opening this issue, I have:

Theme rest resource no longer has fromData applied to it. I suspect this is happening with other rest resources too, but it's only impacted me with themes.

Using this snippet

const { admin, session } =  await authenticate.admin(request);
const theme = new admin.rest.resources.Theme({
  session,
  fromData: {
    name: 'Test',
    src: 'test',
    role: 'unpublished'
  }
});

console.log({ theme })

Expected behavior

Using the above snippet I'd expect this to be logged:

{
    theme: Theme {
    name: 'Test',
    src: 'test',
    role: 'unpublished',
    created_at: undefined,
    id: undefined,
    previewable: undefined,
    processing: undefined,
    theme_store_id: undefined,
    updated_at: undefined
  }
}

Actual behavior

I get this

{
    theme: Theme {
    name: undefined,
    src: undefined,
    role: undefined,
    created_at: undefined,
    id: undefined,
    previewable: undefined,
    processing: undefined,
    theme_store_id: undefined,
    updated_at: undefined
  }
}

Steps to reproduce the problem

I've created this repo to reproduce the issue: https://github.com/david-w-shopify/shopify-rest-resource-issue.

  1. Clone the above repo and install dependencies (if you'd rather set it up yourself, just create a new remix app via the cli) and copy from app/routes/app.tsx the reproduction repo
  2. Run pnpm dev and install the app on a test store
  3. Visit the app in your store
  4. Check the console to see the theme variable being logged
matthew-charles-chan commented 3 months ago

I have found the same behaviour with Orders.

Using this snippet:

  const { admin, session } = await authenticate.admin(request);

  const orderData = {
    email: "foo@example.com",
    fulfillment_status: "fulfilled",
    fulfillments: [
      {
        location_id: 24826418,
      },
    ],
    line_items: [
      {
        variant_id: 447654529,
        quantity: 1,
      },
    ],
  };

  const order = new admin.rest.resources.Order({
    session,
    fromData: orderData,
  });

  await order.save({ update: true });

Expected Behaviour

A new order will be created without error.

Actual Behaviour

A 400 error is thrown:

errors: { order: 'Required parameter missing or invalid' }
matteodepalo commented 3 months ago

Thank you for reporting this @david-w-shopify, we'll take a look.

github-actions[bot] commented 1 month ago

We're labeling this issue as stale because there hasn't been any activity on it for 60 days. While the issue will stay open and we hope to resolve it, this helps us prioritize community requests.

You can add a comment to remove the label if it's still relevant, and we can re-evaluate it.

NirvanaNrv commented 1 month ago

I got the same thing with Webhook. Logging in the constructor of Base showed me a correctly updated 'this' from 'fromData' right before exiting. Commenting the field block at the end of webhook.mjs made it work properly. And that is the length of my analysis on this. Note fromData was working for me a few months ago.