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

Restore --variant flag #981

Open
xzyfer opened this issue Feb 2, 2022 · 0 comments
Open

Restore --variant flag #981

xzyfer opened this issue Feb 2, 2022 · 0 comments
Labels
feature 🎉 new commands, flags, functionality, and improved error messages triage issues and PRs that need to be triaged

Comments

@xzyfer
Copy link

xzyfer commented Feb 2, 2022

Description

The --variant flag was removed in #101 in favour of graph@variant positional argument. Formatted positional arguments are problematic in environments without substitution or templating capabilities i.e. npm/yarn scripts.

Consider the following package.json.

{
  "scripts": {
    "schema:check": "rover graph check mygraph@production --schema=./schema.gql"
  }
}

There isn't a viable way for the script caller to select the variant. This either requires wrapping the rover call in another script in order to template the variant or introduce variant specific script entries i.e. schema:check:staging, schema:check:production, etc... The latter quickly gets unwieldy as we add script entries for other rover operations like publish.

{
  "scripts": {
    "schema:check:staging": "rover graph check mygraph@staging --schema=./schema.gql",
    "schema:check:production": "rover graph check mygraph@production --schema=./schema.gql",
    "schema:publish:staging": "rover graph publish mygraph@staging --schema=./schema.gql",
    "schema:publish:production": "rover graph publish mygraph@production --schema=./schema.gql",
    // ...etc
  }
}

Re-introducing the --variant flag resolves this issue by allowing the caller to select the variant.

{
  "scripts": {
    "schema:check": "rover graph check mygraph --schema=./schema.gql",
    "schema:publish": "rover graph publish mygraph --schema=./schema.gql"
  }
}
npm run schema:check --variant=staging

What about npm_config_*

It's true that npm offers naive templating for scripts that would allow the following

{
  "scripts": {
    "schema:check": "rover graph check mygraph@$npm_config_variant --schema=./schema.gql"
  }
}
npm run schema:check --variant=staging

However this is not consistently supported across node package managers, most notably yarn has a 4yr outstanding PR for a comparable feature.

What about passing in the positional argument

The following is (mostly) possible today

{
  "scripts": {
    "schema:check": "rover graph check --schema=./schema.gql"
  }
}
npm run schema:check mygraph@variant

This works for a single package but it requires all callers to know to graph ID (something that is largely static) which is owned by n external service i.e. Apollo Studio).

However even this approach breaks down once you enter a monorepo environment. Consider a lerna based monorepo, we would want to do the following

lerna run schema:check

This would execute yarn run schema:check in all monorepo packages. Unless all packages depend on the single graph were no longer able to use positional arguments. The --variant flag solves this since flags are passed on by lerna (and other monorepo tools) and node package managers.

lerna run schema:check --variant=staging
@xzyfer xzyfer added feature 🎉 new commands, flags, functionality, and improved error messages triage issues and PRs that need to be triaged labels Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🎉 new commands, flags, functionality, and improved error messages triage issues and PRs that need to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant