good-idea / sane-shopify

MIT License
212 stars 15 forks source link

Update docs for "Roll your own" server #132

Closed nrgnrg closed 3 years ago

nrgnrg commented 3 years ago

I've been implementing the server using Google Cloud Functions and couldn't get the "Roll your own" webhooks to work as it shows in the docs.

After a lot of debugging and looking at the source code I found the function that syncDocument returns needs to be passed a WebhookData object containing id and updated_at rather than simply id as a string.

As it stands this is the example in the docs:

app.post('/api/onProductCreate', async (req, res) => {
  const id = req.body.id
  await webhooks.onProductCreate(id)
  res.status(200).send('success')
})

whereas this is what is required to get it to work

app.post('/api/onProductCreate', async (req, res) => {
  const { id, updated_at } = req.body;
  await webhooks.onProductCreate({ id, updated_at } as WebhookData)
  res.status(200).send('success')
})

I'm happy to create a pull request to update this in the docs?

I'd also be more than happy to make a pull request with a server package for Cloud Functions like there is for Lambda.

I think WebhookData should also be updated to make additional keys optional, that way we wouldn't need to cast it when the function is being called.

One last thing, I think it should explicitly state somewhere in the docs the API version to use when setting up Shopify webhooks and Storefront API to avoid potential errors in the future.

good-idea commented 3 years ago

@all-contributors please add @nrgnrg for documentation

allcontributors[bot] commented 3 years ago

@good-idea

I've put up a pull request to add @nrgnrg! :tada: