-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from Shopify/v3_webhook_context
Future flags and webhook admin context update
- Loading branch information
Showing
27 changed files
with
1,314 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
'@shopify/shopify-app-remix': minor | ||
--- | ||
|
||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.changeset/pre.json | ||
coverage | ||
|
||
packages/shopify-app-remix/docs/* | ||
packages/shopify-app-remix/docs/**/*.json | ||
packages/shopify-app-remix/**/*.example.tsx? |
827 changes: 777 additions & 50 deletions
827
packages/shopify-app-remix/docs/generated/generated_docs_data.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/shopify-app-remix/docs/staticPages/examples/guides/future-flags/config.example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {shopifyApp} from '@shopify/shopify-app-remix/server'; | ||
|
||
export const shopify = shopifyApp({ | ||
// ... | ||
future: { | ||
unstable_newFeature: true, | ||
}, | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/shopify-app-remix/docs/staticPages/examples/guides/future-flags/unstable.example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type {LoaderFunctionArgs} from '@remix-run/node'; | ||
|
||
import {shopify} from '~/shopify.server'; | ||
|
||
export const loader = async ({request}: LoaderFunctionArgs) => { | ||
const result = shopify.newFeature(params); | ||
|
||
return null; | ||
}; |
78 changes: 78 additions & 0 deletions
78
packages/shopify-app-remix/docs/staticPages/future-flags.doc.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {LandingTemplateSchema} from '@shopify/generate-docs'; | ||
|
||
const data: LandingTemplateSchema = { | ||
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 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', | ||
anchorLink: 'configuration', | ||
title: 'Setting future flags', | ||
sectionContent: | ||
'To opt in to a feature, simply enable the appropriate flag in the `future` option of the `shopifyApp` function.' + | ||
'\n\nOnce a flag is set, the returned `shopify` object will start using the new APIs, including using any new types. That allows apps to rely on TypeScript to use a feature regardless of a flag being enabled or not.', | ||
codeblock: { | ||
title: '/app/shopify.server.ts', | ||
tabs: [ | ||
{ | ||
title: '/app/shopify.server.ts', | ||
language: 'ts', | ||
code: './examples/guides/future-flags/config.example.ts', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
type: 'Generic', | ||
anchorLink: 'unstable-apis', | ||
title: 'Unstable APIs', | ||
sectionContent: | ||
'When introducing new features to the package for which we want to gather feedback, we will add them behind a future flag, starting with the `unstable_` prefix.' + | ||
'\n\nThat allows early adopters to try them out individually, without having to install a release candidate package.' + | ||
'\n\nWhen the feature is ready for release, the future flag will be removed and it will be available by default.' + | ||
'\n\nIn this example, `shopify` has a new function called `newFeature`. If the future flag is disabled, TypeScript will be unaware of the new function, and the app will fail to compile if it tries to use it.', | ||
codeblock: { | ||
title: '/app/routes/*.tsx', | ||
tabs: [ | ||
{ | ||
title: '/app/routes/*.tsx', | ||
language: 'ts', | ||
code: './examples/guides/future-flags/unstable.example.ts', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
type: 'Generic', | ||
anchorLink: 'breaking-changes', | ||
title: 'Breaking changes', | ||
sectionContent: | ||
'Similarly to unstable APIs, breaking changes will be introduced behind a future flag, but the prefix will be the next major version (e.g. `v3_`).' + | ||
'\n\nThis allows apps to prepare for the next major version ahead of time, and to gradually adopt the new APIs.' + | ||
'\n\nWhen the next major version is released, the future flag will be removed, and the old code it changes will be removed. Apps that adopted the flag before then will continue to work the same way with no new changes.', | ||
}, | ||
{ | ||
type: 'GenericList', | ||
anchorLink: 'flags', | ||
title: 'Supported flags', | ||
sectionContent: | ||
'These are the future flags supported in the current version.', | ||
listItems: [ | ||
{ | ||
name: 'v3_webhookAdminContext', | ||
value: '', | ||
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, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
export default data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.