-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Codegen dependencies to templates #1962
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5de88a2
Move codegen dependencies to templates
frandiox b164da9
Remove flat schema
frandiox 7e78035
Dedup package-lock.json
frandiox fde9ca4
Do not throw when missing caapi schema
frandiox baff520
Changesets
frandiox af7bc4b
Move codegen dependencies to templates
frandiox e3496df
Remove codegen from hello-world
frandiox 0e2f50c
Update readme
frandiox 0001c93
Remove dependency of dependency from direct list
frandiox 78bbb5e
Changesets
frandiox 2defdfd
Merge branch 'main' into fd-defer-codegen
frandiox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 @@ | ||
--- | ||
'@shopify/cli-hydrogen': patch | ||
--- | ||
|
||
Avoid throwing error in `h2 dev --codegen` when the Customer Account schema is not found. |
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,5 @@ | ||
--- | ||
'@shopify/hydrogen-codegen': minor | ||
--- | ||
|
||
Remove deprecated `schema` export. Use `getSchema('storefront')` instead. |
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,19 @@ | ||
--- | ||
'skeleton': patch | ||
--- | ||
|
||
Codegen dependencies must be now listed directly in `package.json`: | ||
|
||
```diff | ||
{ | ||
"devDependencies": { | ||
+ "@graphql-codegen/cli": "5.0.2", | ||
"@remix-run/dev": "^2.8.0", | ||
"@remix-run/eslint-config": "^2.8.0", | ||
+ "@shopify/hydrogen-codegen": "^0.3.0", | ||
"@shopify/mini-oxygen": "^2.2.5", | ||
"@shopify/oxygen-workers-types": "^4.0.0", | ||
... | ||
} | ||
} | ||
``` |
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
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 |
---|---|---|
@@ -1,35 +1,34 @@ | ||
// This comment is used during ESM build: | ||
//! import {createRequire} from 'module'; const require = createRequire(import.meta.url); | ||
|
||
type Api = 'storefront' | 'customer-account'; | ||
type Options<T extends boolean> = {throwIfMissing?: T}; | ||
|
||
/** | ||
* Resolves a schema path for the provided API type. Only the API types currently | ||
* bundled in Hydrogen are allowed: "storefront" and "customer". | ||
* @param api | ||
* @returns | ||
*/ | ||
export const getSchema = ( | ||
api = 'storefront' as 'storefront' | 'customer-account', | ||
) => { | ||
export function getSchema(api: Api, options?: Options<true>): string; | ||
export function getSchema( | ||
api: Api, | ||
options: Options<false>, | ||
): string | undefined; | ||
export function getSchema(api: Api, options?: Options<boolean>) { | ||
if (api !== 'storefront' && api !== 'customer-account') { | ||
throw new Error( | ||
`The provided API type "${api}" is unknown. Please use "storefront" or "customer-account".`, | ||
); | ||
} | ||
|
||
return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`); | ||
}; | ||
|
||
let staticSFAPISchema = ''; | ||
|
||
try { | ||
staticSFAPISchema = getSchema('storefront'); | ||
} catch (error) { | ||
// This can happen at build time or when '@shopify/hydrogen-react' is not found. | ||
// Generally this shouldn't be an issue in real apps so let's ignore the error. | ||
// Also, this package could be used in non-Hydrogen apps. | ||
try { | ||
return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`); | ||
} catch { | ||
if (options?.throwIfMissing !== false) { | ||
throw new Error( | ||
`Could not find a schema for "${api}".\nPlease make sure a recent version of \`@shopify/hydrogen\` is installed.`, | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The resolved schema path for the Storefront API. | ||
*/ | ||
export const schema = staticSFAPISchema; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was it removed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this caught my attention too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in
hello-world
template. This template is not yet even updated to Vite, and it does not have generated types for queries. Instead of adding the codegen dependencies in this template, I'm just removing the--codegen
flag to keep it minimal 🤔