Skip to content
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

Use a random port for GraphiQL when the default one is not available #3579

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

gonzaloriestra
Copy link
Contributor

@gonzaloriestra gonzaloriestra commented Mar 20, 2024

WHY are these changes introduced?

Fixes #3578

Since GraphiQL was added, you can't run dev multiple times simultaneously without specifying a different GraphiQL port, as we always use the same default value (3457). When you try to run dev a second time, it raises an error:

20-55-wdzm7-m9r05

WHAT is this pull request doing?

If the default port is in use, find an available one instead of raising an error. In that case, a warning is shown:

image

How to test your changes?

Run p shopify app dev in two tabs and ensure that GraphiQL works in both places

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
  • I've made sure that any changes to dev or deploy have been reflected in the internal flowchart.

Copy link
Contributor

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/cli-foundations

Copy link
Contributor

github-actions bot commented Mar 20, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.28% (+0.08% 🔼)
6624/9164
🟡 Branches
69.36% (+0.04% 🔼)
3223/4647
🟡 Functions
71.01% (+0.15% 🔼)
1766/2487
🟡 Lines
73.48% (+0.11% 🔼)
6250/8506
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / trigger.ts
0%
0% (-100% 🔻)
0% 0%
🟢
... / app.test-data.ts
93.79% (-0.04% 🔻)
93.94% (-1.52% 🔻)
85.29% (-0.21% 🔻)
93.33% (-0.04% 🔻)
🟢
... / specification.ts
100%
93.33% (-0.42% 🔻)
100% 100%
🟢
... / app_config_privacy_compliance_webhooks.ts
100%
93.75% (-2.55% 🔻)
100% 100%
🟢
... / context.ts
92.58% (-0.1% 🔻)
86.81% (+0.14% 🔼)
87.88%
93.4% (-0.09% 🔻)
🔴
... / dev.ts
9.8% (-0.2% 🔻)
0% 17.65%
9.57% (-0.21% 🔻)
🟡
... / fetch-app-from-config-or-select.ts
75%
60% (-11.43% 🔻)
100% 75%
🟢
... / use.ts
96.43% (-3.57% 🔻)
94.74% (-5.26% 🔻)
100%
96.43% (-3.57% 🔻)
🟢
... / fetch.ts
80% (-3.87% 🔻)
71.43%
75% (-12.5% 🔻)
84% (-0.31% 🔻)
🟢
... / select-app.ts
92.86% (-0.89% 🔻)
75% 100% 100%
🟢
... / urls.ts
82.08% (-0.49% 🔻)
78.31% (-0.51% 🔻)
75%
84% (-0.47% 🔻)
🔴
... / partners-client.ts
21.95% (-1.58% 🔻)
50%
16.67% (+0.39% 🔼)
20.99% (-1.63% 🔻)
🟢
... / object.ts
90% (-1.67% 🔻)
100%
87.5% (-2.5% 🔻)
90% (-0.91% 🔻)
🟢
... / spin.ts
96.67% (-0.83% 🔻)
60% (-5.38% 🔻)
100%
96.55% (-0.88% 🔻)

Test suite run success

1593 tests passing in 741 suites.

Report generated by 🧪jest coverage report action from 01fbd0e

@gonzaloriestra gonzaloriestra marked this pull request as ready for review March 20, 2024 10:36
@amcaplan
Copy link
Contributor

I'm not sure this is a good idea. Certain features of GraphiQL (query history, session recovery) break if you switch ports, so I'm thinking users should have to do this manually.

@gonzaloriestra
Copy link
Contributor Author

I know, but even without history, GrahpiQL keeps working and it's not the main purpose of the dev command. It must be annoying for people having the default port already in use, or when they want to dev two different apps at the same time...

What if we show a warning when the port is random? Something like:

The default port for GraphiQL (3457) is not available, so a random one has been chosen (5754).

If you want to keep your GrahpiQL session, you can manually select a port by passing `--graphiql-port`.

@nickwesselman
Copy link
Contributor

What is the use case for running dev multiple times? Might that have other side effects?

@gonzaloriestra
Copy link
Contributor Author

@nickwesselman I guess the main use case would be to work on two different projects, being able to switch without stopping the dev command. I think there are no other side effects, I've done it many times until we added GrahpiQL.

@gonzaloriestra
Copy link
Contributor Author

Another alternative would be asking to kill the other process, as we do with the authentication:

21-28-vltar-bs9t3

Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/tcp.d.ts
@@ -1,10 +1,11 @@
 /**
  * Returns an available port in the current environment.
  *
+ * @param preferredPort - Number of the preferred port to be used if available.
  * @returns A promise that resolves with an availabe port.
  * @example
  */
-export declare function getAvailableTCPPort(): Promise<number>;
+export declare function getAvailableTCPPort(preferredPort?: number): Promise<number>;
 /**
  * Checks if a port is available.
  *

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: CLI dev command fails with no port available for GraphiQL regardless of port chosen (MacOS)
4 participants