cli icon indicating copy to clipboard operation
cli copied to clipboard

Functions 'schema' and 'replay' commands - fix dependence on `.env`

Open mssalemi opened this issue 1 year ago β€’ 3 comments

WHY are these changes introduced?

Fixes: https://github.com/Shopify/shopify-functions/issues/411

WHAT is this pull request doing?

Summary of Changes

This PR addresses an issue where the absence of a .env file (and consequently an API key) triggers a prompt for the user to select an app every time a command is executed. This behavior is due to the condition checked in the following code segment: https://github.com/Shopify/cli/blob/037598517bc4cc282ac57dd841fcdbe71034e346/packages/app/src/cli/services/generate-schema.ts#L40.

Proposed Solution

To resolve this, the solution I have currently, uses the already fetched API key (using an existing call with fetchOrCreateOrganizationApp), and we cache that data using setCachedAppInfo (from here)

With this change, once the API key is cached, subsequent command executions will not prompt the user to select an organization, thereby streamlining the workflow.

How to Test Your Changes

  1. Ensure that there is no .env file in your app directory.

  2. Execute the schema command:

    SHOPIFY_CLI_ENABLE_APP_LOG_POLLING=1 NODE_TLS_REJECT_UNAUTHORIZED=0 SPIN=1 SPIN_INSTANCE=XXX pnpm run shopify app function schema --path=./app-name
    
  3. Execute the replay command:

    SHOPIFY_CLI_ENABLE_APP_LOG_POLLING=1 NODE_TLS_REJECT_UNAUTHORIZED=0 SPIN=1 SPIN_INSTANCE=XXX pnpm run shopify app function replay --path=./app-name
    

During a new cli replay or schema command run, you will encounter the app selection prompt. However, for subsequent runs, the cli should use the cached API key, bypassing the need for manual selection.

TODO: current just setting the apikey as the appId

Notes:

  • better way to get and store api key, do we create an .env for them?
  • currently i just set it on the appId

Post-release steps

Measuring impact

How do we know this change was effective? Please choose one:

  • [ ] 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

  • [ ] I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • [ ] I've considered possible documentation changes

mssalemi avatar Oct 03 '24 19:10 mssalemi

Thanks for your contribution!

Depending on what you are working on, you may want to request a review from a Shopify team:

  • Themes: @shopify/advanced-edits
  • UI extensions: @shopify/ui-extensions-cli
    • Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
  • Hydrogen: @shopify/hydrogen
  • Other: @shopify/app-inner-loop

github-actions[bot] avatar Oct 03 '24 19:10 github-actions[bot]

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟑 Statements
72.6% (-0.05% πŸ”»)
8523/11739
🟑 Branches
69.53% (-0.11% πŸ”»)
4178/6009
🟑 Functions
71.61% (-0.06% πŸ”»)
2205/3079
🟑 Lines
72.92% (-0.06% πŸ”»)
8065/11060
Show files with reduced coverage πŸ”»
St.:grey_question:
File Statements Branches Functions Lines
πŸ”΄
... / dev.ts
9.65% (-10.35% πŸ”»)
1.56% (-13.36% πŸ”»)
15.79% (-8.6% πŸ”»)
9.52% (-11.35% πŸ”»)
🟒
... / ConcurrentOutput.tsx
98.39% (-1.61% πŸ”»)
90.91% (-4.55% πŸ”»)
100%
98.33% (-1.67% πŸ”»)

Test suite run success

1940 tests passing in 873 suites.

Report generated by πŸ§ͺjest coverage report action from ad69102bca86ea068368b8fae87b3c02e867e192

github-actions[bot] avatar Oct 03 '24 19:10 github-actions[bot]

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

github-actions[bot] avatar Oct 04 '24 14:10 github-actions[bot]