Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose parseGid and use it internally (#845)
* Expose parseGid and use it internally * Update packages/hydrogen-react/src/parse-gid.doc.ts Co-authored-by: Matt Seccafien <matt.seccafien@shopify.com> * Ensure hydrogen-react is built before cli * update docs * Update .changeset/nervous-bears-look.md Co-authored-by: Daniel Rios <daniel.riospavia@shopify.com> * Revert "Ensure hydrogen-react is built before cli" This reverts commit 20b7c1b. * have cli use its own implementation of parsegid for now * Fix docs errors --------- Co-authored-by: Matt Seccafien <matt.seccafien@shopify.com> Co-authored-by: Daniel Rios <daniel.riospavia@shopify.com>
- Loading branch information
1 parent
96dad7a
commit 0a009a3
Showing
10 changed files
with
132 additions
and
10 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,15 @@ | ||
--- | ||
'@shopify/hydrogen-react': patch | ||
'@shopify/hydrogen': patch | ||
--- | ||
|
||
Adds `parseGid()` which is a helper function that takes in a [Shopify GID](https://shopify.dev/docs/api/usage/gids) and returns the `resource` and `id` from it. For example: | ||
|
||
```js | ||
import {parseGid} from '@shopify/hydrogen-react'; | ||
|
||
const {id, resource} = parseGid('gid://shopify/Order/123'); | ||
|
||
console.log(id); // 123 | ||
console.log(resource); // Order | ||
``` |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; | ||
|
||
const data: ReferenceEntityTemplateSchema = { | ||
name: 'parseGid', | ||
category: 'utilities', | ||
isVisualComponent: false, | ||
related: [], | ||
description: ` | ||
Parses [Shopify Global ID (GID)](https://shopify.dev/api/usage/gids) and returns the resource type and ID. | ||
`, | ||
type: 'gear', | ||
defaultExample: { | ||
description: 'I am the default example', | ||
codeblock: { | ||
tabs: [ | ||
{ | ||
title: 'JavaScript', | ||
code: './parse-gid.example.js', | ||
language: 'js', | ||
}, | ||
], | ||
title: 'Example code', | ||
}, | ||
}, | ||
definitions: [ | ||
{ | ||
title: 'Props', | ||
type: 'ParseGidGeneratedType', | ||
description: '', | ||
}, | ||
], | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {parseGid} from '@shopify/hydrogen-react'; | ||
|
||
const {id, resource} = parseGid('gid://shopify/Order/123'); | ||
|
||
console.log(id); // 123 | ||
console.log(resource); // Order |
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