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

.env file and .graphqlconfig in sub directory does not find variables when running queries in another nested subdirectory or scratch file #644

Closed LiamKarlMitchell closed 1 year ago

LiamKarlMitchell commented 1 year ago

Before you create the issue

Describe the bug Project seems to be looking in the wrong place for .env file when the .env and/or .graphqlconfig are not in the top level directory.

I found with a directory structure per below and using Intelij and GraphQL plugin version 3.3.0 That whilst the GraphQL tab introspection worked successfully to download/write the schema.graphql running queries from scratch graphql files or from a new graphql file did not work as it could not find the env variables.

However when the .env was put in the "project-app" root folder I was able to run the queries from Intelij, similar when it was placed at the location "project-app/project_app/lib/graphql/.env" but those places are not where the .env should be found in this case.

If the logic to find the .env is not working, could we please have a way to define the .env file to use per endpoint configured in the .graphqlconfig file?

To Reproduce For this particular project it has other folders and things in the top level and the Flutter app project is actually in the "project_app" directory for example.

project-app/project_app/.env

GRAPHQL_URL=http://localhost:10030/graphql
GRAPHQL_TOKEN_FOR_DEV_IDE=1:1234

project-app/project_app/lib/graphql/test.graphql

query me {
  id
}

project-app/project_app/.graphqlconfig

{
  "name": "Project App - Dev",
  "schemaPath": "lib/graphql/schema.graphql",
  "extensions": {
    "endpoints": {
      "Default GraphQL Endpoint": {
        "url": "${env:GRAPHQL_URL}",
        "headers": {
          "user-agent": "JS GraphQL",
          "Authorization": "Bearer ${env:GRAPHQL_TOKEN_FOR_DEV_IDE}"
        },
        "introspect": true
      }
    }
  }
}

Expected behavior A clear and concise description of what you expected to happen.

It should find the .env file relative to the .graphqlconfig or perhaps let us say what the .env file path is in the .graphqlconfig to handle cases where finding it is confused.

Putting the .env in project-app/.env works, but that is not ideal for us as it should be relative to the other files in the project_app sub directory.

Screenshots image

Schema discovery works

image

Running query from scratch file asks for .env variables that should be already defined in the .env in same directory as .graphqlconfig? Same issue with queries in a directory that is not the same as .graphqlconfig

image

Version and Environment Details Operation system: Windows 10 IDE name and version: Intelij IDEA 2022.3.1 (Ultimate Edition) Plugin version: 3.3.0 & 3.4.0

LiamKarlMitchell commented 1 year ago

My WebStorm and PHPStorm are still only seeing version 3.4.0 of the plugin not version 4.0 Do I need to invalidate caches to get plugin to update to latest version?

image

vepanimas commented 1 year ago

@LiamKarlMitchell what version of WebStorm or PhpStorm do you use?

LiamKarlMitchell commented 1 year ago

WebStorm 2023.1 Build #WS-231.8109.174, built on March 28, 2023

Non-Bundled Plugins: com.intellij.lang.jsgraphql (3.4.0)

PhpStorm 2022.3.3 Build #PS-223.8836.42, built on March 10, 2023

Non-Bundled Plugins: com.intellij.lang.jsgraphql (3.4.0)

VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10 10.0

I can upgrade PHPStorm to 2023.1 but since WebStorm is showing old version not sure if it will have an impact

vepanimas commented 1 year ago

@LiamKarlMitchell it's strange, looks like an issue with the Marketplace🤷‍♂️. Please, try to invalidate caches as you proposed.

LiamKarlMitchell commented 1 year ago

Invalidating caches and restarting did not work. But I found this https://youtrack.jetbrains.com/issue/IDEA-274852 Which says we can run an action for "Check for plugin updates" which did the trick!

vepanimas commented 1 year ago

Didn't know about that action, thank you for letting me know 👍

I hope, that your issue is resolved in the update. Feel free to share any feedback!