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

RFC: Exposing the generate-schema and generate-output actions from cli-utils as Node.js API's #134

Closed
matthewvolk opened this issue Mar 13, 2024 · 1 comment · Fixed by #135 or #207
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@matthewvolk
Copy link
Contributor

Summary

We maintain a CLI to help users bootstrap a new project on our platform (e.g., npm create ...), and as part of that process we would like to:

  1. Run through our normal bootstrap process
  2. Generate a GraphQL schema
  3. Output the introspection file for gql.tada to use

While we could achieve this by using child_process.exec to call the gql.tada CLI from within our CLI, we have concerns around:

  • Type safety: We prefer strongly typed method calls over string-based CLI commands
  • Performance: Using exec spawns a new shell which adds overhead, but a direct API call can be executed within the same process space as our CLI
  • Error handling: Parsing stdout and stderr from exec to determine success/failure can become complicated

Proposed Solution

  1. Determine a reasonable API interface for the methods to be exposed (e.g., making cwd an optional parameter on the method)
  2. Abstracting generate-schema and generate-output logic into two individual methods that live outside of the CLI action handler callbacks.
  3. Exporting those methods as named exports from the @gql.tada/cli-utils package (we think importing these methods from @gql.tada/cli-utils makes the most sense so we don't have to install the entire gql.tada package in our CLI)

Requirements

N/A

Relevant Links

@matthewvolk matthewvolk added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Mar 13, 2024
@kitten
Copy link
Member

kitten commented Apr 12, 2024

@JoviDeCroock @matthewvolk: We're currently nearing the “beta/v1.0.0” release of the CLI, and I think we may have to revisit this.

The functions we expose currently may not match what the CLI is doing exactly and put some cosnstraints on us that make it more likely that we'll break them in the future, if we're not careful.

We could instead replace them with @gql.tada/internal however.

This does require us to move some substantial parts of @gql.tada/cli-utils` over, but may help with separating the two a little into a re-usable and non-reusable package.

The other option would be to clearly specify how we want to expose these methods, but I'm writing this note to basically say that in the next major release of the CLI (which is in theory imminent) some APIs may change or break, either way, on cli-utils or not 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
2 participants