0no-co / gql.tada

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

gql-tada generate-output only respects the first @0no-co/graphqlsp plugin configuration #190

Closed n4bb12 closed 4 months ago

n4bb12 commented 4 months ago

Describe the bug

Given a tsconfig.json containing the following plugin configuration

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "@0no-co/graphqlsp",
        "schema": "src/graphql/foo/schema.gql",
        "tadaOutputLocation": "src/graphql/foo/graphql-env.d.ts"
      },
      {
        "name": "@0no-co/graphqlsp",
        "schema": "src/graphql/bar/schema.gql",
        "tadaOutputLocation": "src/graphql/bar/graphql-env.d.ts"
      }
    ]
  }
}

When initializing the TS LSP in VSCode, all plugins are respected, and both graphql-env.d.ts files get generated.

Using the gql.tada CLI with gql-tada generate-output, only the first configuration is respected. The second configuration is ignored. You can swap the order to verify.

The context for using more than one plugin configuration is the need to talk to more than one GraphQL API.

Reproduction

https://github.com/n4bb12/gql-tada-repro

gql.tada version

gql.tada: 1.4.3 @0no-co/graphqlsp: 1.9.1 typescript: 5.4.4

Validations

kitten commented 4 months ago

This is not tested and while it might work, provided you alter the detected template in these settings, we have some support for multi-schema setups planned: https://github.com/0no-co/GraphQLSP/discussions/223#discussioncomment-9050883

However, it'll likely not involve repeating the plugin and instead expand the generated functions with a type hint that the LSP can pick up while allowing an array of schemas and outputs to be passed

tianyingchun commented 4 months ago

when this feature will be planed :)

JoviDeCroock commented 4 months ago

@tianyingchun this is open-source, feel free to submit an RFC outlining your approach and PR'ing the functionality.

kitten commented 4 months ago

@tianyingchun: Please read the reply in the thread I linked above in my last reply: https://github.com/0no-co/GraphQLSP/discussions/223#discussioncomment-9050883

It clearly states that this is something we'll address after the next batch of RFCs is resolved and released.

Again to repeat what's stated there, the RFC I have in mind would mostly get the LSP to allow for multiple schemas to be loaded, for gql.tada’s output file to contain a type-hint for the schema it was sourced from, and the LSP to then pick that up to choose the correct schema for its type hints / autocompletions / etc.

kitten commented 4 months ago

Closing in favour of #248

kitten commented 4 months ago

Multi-Schema Support has been released in gql.tada 1.6.0 (+ @0no-co/graphqlsp@^0.12.0). There's more information in the corresponding announcement devlog post: https://gql-tada.0no.co/devlog/2024-04-26