timkendall / tql

A GraphQL query builder for TypeScript. Avoid the pain of codegen.
https://tql.dev
MIT License
133 stars 6 forks source link

Add support to pass http headers when running codegen cli #113

Closed lorefnon closed 2 years ago

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
tql ✅ Ready (Inspect) Visit Preview May 9, 2022 at 6:02PM (UTC)
lorefnon commented 2 years ago

I don't believe yargs is flexible enough for this:

As added here, this PR proposes two usages:

You can also pass headers (eg. for authentication) to your graphql API endpoint if needed:

npx @timkendall/tql-gen http://api.example.com/graphql --headers.Authorization="Bearer 20394823423"

or

npx @timkendall/tql-gen http://api.example.com/graphql --headers="Authorization: Bearer 20394823423"

In either usage patterns, you can pass multiple headers by repeated usage of --headers

The first usage is what yargs can support out of the box. I also wanted to support the second usage because that is how headers are represented in http request. For supporting both (including repeated invocations) I had added that parsing logic.

If you prefer I can only retain the first usage and simplify the parsing logic.

timkendall commented 2 years ago

Let's stick with the simpler parsing logic. I like the fancy version but it's likely going to be hard to port over to the Rust implementation of the CLI (unless one of their mature CLI arg libraries supports this format out of the box).

lorefnon commented 2 years ago

Thanks. Curious about the motivation for the rust rewrite ? Is it intended to improve performance for cases when the graphql schema changes very frequently and the codegen has to be run repeatedly ?

timkendall commented 2 years ago

@lorefnon Exactly.