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

Auto-complete issue with multiple projects and schemas #714

Open
benjamindulau opened this issue May 20, 2024 · 3 comments
Open

Auto-complete issue with multiple projects and schemas #714

benjamindulau opened this issue May 20, 2024 · 3 comments

Comments

@benjamindulau
Copy link

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
Copy link
Author

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()?

@vepanimas
Copy link
Collaborator

@benjamindulau The first config you provided is supposed to work in a monorepo scenario. When the plugin tries to match a file with a project in it, in your case it just chooses the first one, because both are applicable. To properly separate the projects, you need to add a documents key to each project’s configuration. Here is the plugin's doc you can refer to, here is the graphql-config doc.

If you need to access both schemas from a single file or query, the only approach is what you described in the second comment. We have some merging logic under the hood for such cases, but it's not perfect, and as you noticed it will show errors. You can try disabling these errors:

image

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()?

That's not supported; only specific and pre-defined injections work due to some technical limitations.

@benjamindulau
Copy link
Author

@vepanimas Thank you for the follow-up.

That's not supported; only specific and pre-defined injections work due to some technical limitations.

I'm curious what are those technical limitations. Are they because of PhpStorm itself? Isn't there a way by defining a custom function name in the configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants