cli icon indicating copy to clipboard operation
cli copied to clipboard

Improve error message for Functions GraphQL typegen failures

Open nickwesselman opened this issue 9 months ago β€’ 3 comments

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:

  1. Adding a specific package version (@graphql-codegen/[email protected]) to the npm exec command and using the --no argument to prevent npm from downloading it
  2. Detecting when the error is related to missing dependencies
  3. Providing a more helpful error message that guides users to restore their workspace dependencies

image.png

How to test your changes?

  1. Create a function that uses JavaScript
  2. Delete node_modules in the function path
  3. Run shopify app function typegen
  4. 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

nickwesselman avatar Apr 30 '25 20:04 nickwesselman

This stack of pull requests is managed by Graphite. Learn more about stacking.

nickwesselman avatar Apr 30 '25 20:04 nickwesselman

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

github-actions[bot] avatar Apr 30 '25 20:04 github-actions[bot]

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.

nickwesselman avatar May 06 '25 16:05 nickwesselman

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.

github-actions[bot] avatar Jun 06 '25 03:06 github-actions[bot]

Waiting until we drop Node 18 support.

nickwesselman avatar Jun 06 '25 12:06 nickwesselman

we've dropped node 18 :)

isaacroldan avatar Jul 01 '25 09:07 isaacroldan

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.

nickwesselman avatar Jul 03 '25 19:07 nickwesselman

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.

github-actions[bot] avatar Aug 03 '25 04:08 github-actions[bot]

still relevant

illarionvk avatar Aug 03 '25 08:08 illarionvk

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.

github-actions[bot] avatar Sep 04 '25 03:09 github-actions[bot]