Skip to content

Commit

Permalink
Improving webhook update docs per review
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Oct 10, 2023
1 parent db6f91c commit 14fdd21
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
60 changes: 60 additions & 0 deletions .changeset/serious-nails-own.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,63 @@
Added support for `future` flags in the `shopifyApp` function, with a `v3_webhookContext` flag to have `authenticate.webhook` return a standard `admin` context, instead of a different type.

Apps can opt in to the new future at any time, so this is not a breaking change (yet).

<details>
<summary>See an example</summary>

Without the `v3_webhookContext` flag, `graphql` provides a `query` function that takes the query string as the `data` param.
When using variables, `data` needs to be an object containing `query` and `variables`.

```ts
import {json, ActionFunctionArgs} from '@remix-run/node';
import {authenticate} from '../shopify.server';

export async function action({request}: ActionFunctionArgs) {
const {admin} = await authenticate.webhook(request);

const response = await admin?.graphql.query<any>({
data: {
query: `#graphql
mutation populateProduct($input: ProductInput!) {
productCreate(input: $input) {
product {
id
}
}
}`,
variables: {input: {title: 'Product Name'}},
},
});

const productData = response?.body.data;
return json({data: productData.data});
}
```

With the `v3_webhookContext` flag enabled, `graphql` _is_ a function that takes in the query string and an optional settings object, including `variables`.

```ts
import {ActionFunctionArgs} from '@remix-run/node';
import {authenticate} from '../shopify.server';

export async function action({request}: ActionFunctionArgs) {
const {admin} = await authenticate.webhook(request);

const response = await admin?.graphql(
`#graphql
mutation populateProduct($input: ProductInput!) {
productCreate(input: $input) {
product {
id
}
}
}`,
{variables: {input: {title: 'Product Name'}}},
);

const productData = await response.json();
return json({data: productData.data});
}
```

</details>
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
{
"id": "guide-future-flags",
"title": "Future flags",
"description": "Similarly to how [Remix approaches breaking changes](https://remix.run/docs/en/main/start/future-flags), the `@shopify/shopify-app-remix` package also uses future flags.\n\nBigger features are breaking changes are initially added behind a future flag. This means that they're disabled by default, and must be manually enabled by setting the appropriate flag in the `future` option of the `shopifyApp` function.\n\nThis allows apps to gradually adopt new features, and prepare for breaking changes and major releases ahead of time.",
"description": "Similarly to how [Remix approaches breaking changes](https://remix.run/docs/en/main/start/future-flags), the `@shopify/shopify-app-remix` package also uses future flags.\n\nBigger features and breaking changes are initially added behind a future flag. This means that they're disabled by default, and must be manually enabled by setting the appropriate flag in the `future` option of the `shopifyApp` function.\n\nThis allows apps to gradually adopt new features, and prepare for breaking changes and major releases ahead of time.",
"sections": [
{
"type": "Generic",
Expand Down Expand Up @@ -154,7 +154,7 @@
{
"name": "v3_webhookAdminContext",
"value": "",
"description": "Returns the same `admin` context (`AdminApiContext`) from `authenticate.webhook` that is returned from `authenticate.admin`.",
"description": "Returns the same `admin` context (`AdminApiContext`) from `authenticate.webhook` that is returned from `authenticate.admin`.\n\nSee [authenticate.webhook](/docs/api/shopify-app-remix/authenticate/webhook#example-admin) for more details.",
"isOptional": true
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const data: LandingTemplateSchema = {
title: 'Future flags',
description:
'Similarly to how [Remix approaches breaking changes](https://remix.run/docs/en/main/start/future-flags), the `@shopify/shopify-app-remix` package also uses future flags.' +
"\n\nBigger features are breaking changes are initially added behind a future flag. This means that they're disabled by default, and must be manually enabled by setting the appropriate flag in the `future` option of the `shopifyApp` function." +
"\n\nBigger features and breaking changes are initially added behind a future flag. This means that they're disabled by default, and must be manually enabled by setting the appropriate flag in the `future` option of the `shopifyApp` function." +
'\n\nThis allows apps to gradually adopt new features, and prepare for breaking changes and major releases ahead of time.',
sections: [
{
Expand Down Expand Up @@ -66,7 +66,8 @@ const data: LandingTemplateSchema = {
name: 'v3_webhookAdminContext',
value: '',
description:
'Returns the same `admin` context (`AdminApiContext`) from `authenticate.webhook` that is returned from `authenticate.admin`.',
'Returns the same `admin` context (`AdminApiContext`) from `authenticate.webhook` that is returned from `authenticate.admin`.' +
'\n\nSee [authenticate.webhook](/docs/api/shopify-app-remix/authenticate/webhook#example-admin) for more details.',
isOptional: true,
},
],
Expand Down

0 comments on commit 14fdd21

Please sign in to comment.