Improve error message for Functions GraphQL typegen failures
WHY are these changes introduced?
When Functions GraphQL typegen fails due to missing dependencies, the error message is not very helpful for users to understand what went wrong.
For example, if a developer attempts an npm install on a repo using pnpm workspaces, the extension dependencies won't be installed. With how we run the code generator (npm exec -- graphql-code-generator --config package.json), if itβs not present in node_modules, npm attempts to download a package that provides it, which defaults to the old graphql-code-generator package and not @graphql-codegen/cli. Then that old graphql-code-generator bombs with an unhelpful error message:
Cannot convert undefined or null to object
See related issues: #3111, #2031
WHAT is this pull request doing?
Improves error handling when generating GraphQL types for Functions by:
- Adding a specific package version (
@graphql-codegen/[email protected]) to thenpm execcommand and using the--noargument to prevent npm from downloading it - Detecting when the error is related to missing dependencies
- Providing a more helpful error message that guides users to restore their workspace dependencies

How to test your changes?
- Create a function that uses JavaScript
- Delete node_modules in the function path
- Run
shopify app function typegen - Verify that the error message is clear and suggests restoring dependencies
Measuring impact
How do we know this change was effective? Please choose one:
- [x] n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
- [ ] Existing analytics will cater for this addition
- [ ] PR includes analytics changes to measure impact
Checklist
- [x] I've considered possible cross-platform impacts (Mac, Linux, Windows)
- [x] I've considered possible documentation changes
-
#5732
π (View in Graphite)
-
main
This stack of pull requests is managed by Graphite. Learn more about stacking.
Coverage report
St.:grey_question: |
Category | Percentage | Covered / Total |
|---|---|---|---|
| π‘ | Statements | 78.37% (+0.03% πΌ) |
12579/16050 |
| π‘ | Branches | 72.53% (+0.07% πΌ) |
6127/8447 |
| π‘ | Functions | 78.49% | 3280/4179 |
| π‘ | Lines | 78.81% (+0.03% πΌ) |
11904/15104 |
Test suite run success
2918 tests passing in 1262 suites.
Report generated by π§ͺjest coverage report action from c12999cffbf70069fa5b3693079bbfa6be65142a
This is failing currently on Node 18 when generating a new function. The codegen CLI either isn't being installed, or isn't being installed somewhere that npm exec can find it.
I'm not sure if this PR created the issue or just made an existing one more apparent. I'll need to wait until I have more time to debug, OR await dropping Node 18 support to merge this.
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. β If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.
Waiting until we drop Node 18 support.
we've dropped node 18 :)
hmm Node 18 must not have been the issue, the acceptance tests are still failing, but only on MacOS and Linux. Will need to dig in more.
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. β If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.
still relevant
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. β If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.