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
880 stars 97 forks source link

Schemas in Parent directories / node_modules do not work #668

Open reckter opened 1 year ago

reckter commented 1 year ago

Before you create the issue Since the 4.0.0 release, using "../.." in schemaPath (or in schema), doesn't actually grab the schema, and instead just treats it like an empty schema.

Describe the bug

We have a monorepo setup with the following structure:

apps/
    frontend/
        .graphqlconfig # see below
packages/
    schema/
        build/
            graphql/
                api.graphql

The frontend graphqlconfig:

{
    "schemaPath": "../../packages/schema/build/graphql/api.graphql"
}

Now the plugin doesn't pick up the schema correctly, and instead just uses an empty schema, causing all types to be marked as invalid.

Version and Environment Details Operation system: Mac OS Venture IDE name and version: Webstorm 2023.1.1 Build #WS-231.8770.64, built on April 27, 2023 Plugin version: 4.0.0

Additional context

I've tried going through simlinked node_modules folders instead, but that also doesn't solve the issue.

Current workaround seems to be to use the patched version of the plugin from #661 and have one single config in the root folder

vepanimas commented 1 year ago

@jimkyndemeyer could you please help with that? AFAIU relative paths to parent directories are not supposed to work at all🤷‍♂️

jimkyndemeyer commented 1 year ago

@vepanimas From memory, which might be wrong:

I recall that schemaPath in the legacy config resolver worked without this parent directory limitation. Any valid schema file path, including a relative one to a parent directory, just looked for a matching virtual file and picked it up. The globs for include/exclude however, could only match in the current and descendant directories. Not sure whether that followed the old spec, but seemed like people expected it to just work out of the box.

heyline commented 1 year ago

I have the same problem, when I open the webapp project, the path I set is not valid, I now have to open the whole root project for it to work

root/
  webapp
      .graphqlrc.json
  server/
      src/
        main/
           resources/
                  schema.graphqls
  xxxxx  # some other items
  xxxxx  # some other items
allista commented 1 year ago

Have the same issue: we have a monorepo with a lot of packages which all use the same schema downloaded once to the root level:

root/
  schema.graphql
  apps/
    app1/
      .graphqlrc.yml:
        schema: "../../schema.graphql"

Both eslint plugin for graphql and graphql-codegen have no problem recognizing the schema.

vepanimas commented 11 months ago

Schemas defined in parent directories should work in the upcoming 2023.3 release, you can try an already published EAP to check if the issue is solved for you.

jeroenmaas commented 11 months ago

Great that this is being worked on (And probably even fixed!). We're running exact monorepo setup as allista and running in the same issue. I've downloaded the EAP release but unfortunately it still shows all my queries red when scheme is outside of the project.

Using: Build #PY-233.9802.6, built on October 10, 2023 Graphql plugin version: 233.9802.6

Could it be because i'm using pycharm that this fix is not yet available in the EAP release?

vepanimas commented 11 months ago

@jeroenmaas Hi! It could be a related but somewhat different case. When you say that a schema is "outside of the project", does it mean that it is located somewhere in the filesystem that is not directly associated with the current project, or is it simply located in a parent directory?

Could you please provide a minimal repo to reproduce? The repository should have a similar directory structure as your project, including all the necessary GraphQL configurations. It would be really helpful to finally fix all possible corner cases.

jeroenmaas commented 11 months ago

Hi @vepanimas, I've made a repo here: https://github.com/jeroenmaas/example-setup-js-graphql-intellij-plugin-issue.

In order to reproduce the issue open "frontend" as a project. Then the query no longer has highlighting. If opening the root level project it works fine.

Some more context why we use this setup. Our backend is written in python, therefor we use pycharm to open it, but frontend written in Angular and some developers prefer to use webstorm for this. So they open our mono repo and use /frontend as base of their project. We have multiple frontend projects and we'd prefer to have 1 schema so use the backend for storage of schema.graphql

image

All files are located on the filesystem.

vepanimas commented 11 months ago

@jeroenmaas thank you for the detailed explanation! Unfortunately, that's a bit different case. It seems your schema might not be indexed by the IDE, as it's outside of the project root. It should be fixed in a different way, I'll try to take a look a bit later.

jeroenmaas commented 9 months ago

@vepanimas Thank you for taking the time to have a look at this. Do you have any update for me? I understand that this is a different issue due it being outside of the project directory. Would it be helpful to create a new issue for this?