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

Types are not recognized in certain cases #667

Closed BoD closed 1 year ago

BoD commented 1 year ago

My project's structure is:

- graphqlSchema
  - src
    - main
      - graphql
        - servicea
          - schema.graphqls
          - operations.graphql
        - serviceb
          - schema.graphqls
          - operations.graphql
- feature1
  - src
    - main
      - graphql
        - servicea
          - operations.graphql
        - serviceb
          - operations.graphql

Here's my graphql.config.yml:

projects:
  'graphqlSchema/service-a':
    schema: graphqlSchema/src/main/graphql/servicea/schema.graphqls
    include:
      - graphqlSchema/src/main/graphql/servicea/*.graphql

  'graphqlSchema/service-b':
    schema: graphqlSchema/src/main/graphql/serviceb/schema.graphqls
    include:
      - graphqlSchema/src/main/graphql/serviceb/*.graphql

  'feature1/service-a':
    schema: graphqlSchema/src/main/graphql/servicea/schema.graphqls
    include:
      - feature1/src/main/graphql/servicea/*.graphql
      - graphqlSchema/src/main/graphql/servicea/*.graphql

  'feature1/service-b':
    schema: graphqlSchema/src/main/graphql/serviceb/schema.graphqls
    include:
      - feature1/src/main/graphql/serviceb/*.graphql
      - graphqlSchema/src/main/graphql/serviceb/*.graphql

Now if I open feature1/src/main/graphql/servicea/operations.graphql, everything is red, the fields cannot be resolved.

Now if I change the order of declaration in the graphql.config.yml like so:

projects:
  'feature1/service-a':
    schema: graphqlSchema/src/main/graphql/servicea/schema.graphqls
    include:
      - feature1/src/main/graphql/servicea/*.graphql
      - graphqlSchema/src/main/graphql/servicea/*.graphql

  'feature1/service-b':
    schema: graphqlSchema/src/main/graphql/serviceb/schema.graphqls
    include:
      - feature1/src/main/graphql/serviceb/*.graphql
      - graphqlSchema/src/main/graphql/serviceb/*.graphql

  'graphqlSchema/service-a':
    schema: graphqlSchema/src/main/graphql/servicea/schema.graphqls
    include:
      - graphqlSchema/src/main/graphql/servicea/*.graphql

  'graphqlSchema/service-b':
    schema: graphqlSchema/src/main/graphql/serviceb/schema.graphqls
    include:
      - graphqlSchema/src/main/graphql/serviceb/*.graphql

Then I no longer have the issue, the fields are resolved and not red in feature1/src/main/graphql/servicea/operations.graphql.

I don't understand why.

Also, in my case it would make more sense to declare the graphqlSchema projects first as they are a dependency of the feature ones.

To Reproduce You can clone this repo: git@github.com:BoD/apollo-kotlin-template-multi-modules-and-services.git and checkout the gql-plugin-config-order-issue branch.

Version and Environment Details Operation system: MacOS IDE name and version: IntelliJ IDEA 2023.1.1 Plugin version: 4.0.0

Additional context I noticed this when programmatically contributing the config via the extension point, from the Apollo Kotlin plugin I'm working on. The issue is identical whether the config comes from the config file or from the extension point.

vepanimas commented 1 year ago

Hi! Could you please check a build from https://github.com/JetBrains/js-graphql-intellij-plugin/issues/661#issuecomment-1523498575?

BoD commented 1 year ago

@vepanimas Yes, it does work with that version!

BoD commented 1 year ago

Closing as the fix was released in 4.0.1