JetBrains / js-graphql-intellij-plugin

GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/
MIT License
879 stars 97 forks source link

Auto-complete issue with multiple projects and schemas #714

Open benjamindulau opened 1 month ago

benjamindulau commented 1 month ago

Describe the bug

We're trying to setup multiple schemas in a project but auto-complete in code injections seems to only supports one of the defined project schemas.

One schema is our internal schema. The other one is a dumped schema from Strapi and is the reason why we need to add multi-schema support in the project.

Before we had this configuration:

schema:
    - 'src/ST/GraphQL/schema/**/*.graphql'

Only one schema, so far so good..

Now we're trying to work with this configuration

# .graphqlrl.yml
projects:
    # our own schema
    catalog:
        schema:
            - 'src/ST/GraphQL/schema/**/*.graphql'
    # the Strapi schema that we dumped
    cms:
        schema:
            - 'assets/website/remix/app/types/cms.graphql'

Problem is we get autocomplete for the first schema (catalog) but not the other one, here is a video showing this: https://github.com/JetBrains/js-graphql-intellij-plugin/assets/430689/aad02209-2b39-4187-b9ba-daa4f838ee59

And as you can see in the following screenshots, both schemas are recognized by the plugin, and the guides field exists in the dumped cms.graphql schema file used by the plugin: Capture d’écran 2024-05-20 à 12 16 15 Capture d’écran 2024-05-20 à 12 18 24

Version and Environment Details Operation system: macOS Ventura 13.2.1 IDE name and version: Capture d’écran 2024-05-20 à 12 21 23 Plugin version: 241.14494.150

benjamindulau commented 1 month ago

Note: It works better if I configure a single project with both schemas documents:

schema:
    - 'src/ST/GraphQL/schema/**/*.graphql'
    - 'assets/website/remix/app/types/cms.graphql'

But it makes less sense I think, since they are two distincts schemas.

Also to get proper "multi schema" support, it should handle cases where there are duplicate field names across multiple schemas...

There is no way to inform PhpStorm which schema the query is intended for, so when different schemas contains identical field names, it considers the field from the first matching document to be valid but not the others.

It would be nice to be able to add some contextual information when making queries, like adding the targeted schema to /* GraphQL */ comment for instance.

Another annoying thing: we don't need to use the /* GraphQL */ comment for GraphQL code injection when using a function named graphql(), which is great for DX. But we do if we use another name for the function, like cmsGraphql() in our case. Is there a way to tell PhpStorm that cmsGraph() acts like graphql()?