0no-co / gql.tada

🪄 Magical GraphQL query engine for TypeScript
https://gql-tada.0no.co
MIT License
2.44k stars 34 forks source link

RFC: ENV Variable loading #324

Closed sannajammeh closed 1 week ago

sannajammeh commented 3 weeks ago

Summary

We work heavily with GraphQL schemas locked down behind Authorization headers and would like URL introspection to work without having to gitignore tsconfig.json. Take the following schema config:

        {
            "name": "craft",
            "schema": {
              "url": "https://xxxx.com",
              "headers": {
                "Authorization": "Bearer XXXXXX"
              }
            },
            "tadaOutputLocation": "./src/graphql/craft-env.d.ts"
          }

Proposed Solution

We propose the LSP being able to load .env.local & .env files so this is possible:

        {
            "name": "craft",
            "schema": {
              "url": "https://xxxx.com",
              "headers": {
                "Authorization": "Bearer $(CRAFT_API_TOKEN)"
              }
            },
            "tadaOutputLocation": "./src/graphql/craft-env.d.ts"
          }

Implement dotenv env parsing as a step before introspecting

Requirements

kitten commented 3 weeks ago

I'm not a big fan of this and have recently I think left a comment with more explanation on this.

It's relatively simple to write a script with the existing CLI commands to pull the schema (it's not exactly best practice to keep pulling the schema from a live API indefinitely and repeatedly) This can also be done with the CLI's JS utilities, which can be imported directly.

Further, it's not like we'd be adding just environment variables support, since we're talking about loading them into the LSP. We'd also have to resolve a dotenv file, which isn't exactly something I think is expected to be happening in the TSServer process, and this would also further open us up to more requests, since this is non-standard to then alter the dotenv location, etc etc

It's an open-ended request that doesn't really resolve the root problem that you could attempt to resolve with what exists already: having a local SDL file, as per: https://gql-tada.0no.co/get-started/workflows#downloading-schemas

Sorry if that's not exactly the answer you're looking for but hope this makes sense

kitten commented 1 week ago

Closing since there hasn't been more follow-up to this. Let me know if there's further questions around this ✌️