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

Can't dismiss or disable ".graphqlconfig associated with this file does not include it" notification #476

Closed trevor-coleman closed 1 year ago

trevor-coleman commented 3 years ago

Describe the bug

I am currently using the graphql-modules library, and when writing tests I have to write graphql queries for the test suite to execute. Here is an example from the library docs:

const result = testkit.execute(app, {
    document: gql`
      {
        me {
          name
        }
      }
    `,
  });

These queries are not part of the schema, as they are client-side code, and only used for testing, so I have excluded the folders that contain the tests in my .graphql config file.

// .graphqlconfig 
{
  [...] ,

  "excludes": [
    "./**/__tests__/**/*"
   ],

  [...]
}

However every time I open the file, a notification banner is displayed at the top of the screen that says:

The .graphqlconfig associated with this file does not include it. Schema discovery and language tooling will use the entire project.

Also, an 'Edit .graphqlconfigblobs' action is added to my Context Actions menu.

The notification is presented in a way that indicates there is an error, and the context menu action has a bright yellow lightbulb icon next to it, which is typically an indicator of something that can improve your code. Because these are displayed in the same way as errors or other important system messages, they can be quite distracting.

I have many of these test files in my project, and I have specifically excluded all of them from the .graphqlconfig. There should be a way to disable these notifications when they aren't useful/necessary.

To Reproduce

Link to Repo with Reproduction or Steps to Reproduce:

  1. In any project, exclude a file using the .graphqlconfig
  2. Open that file and add a graphql query to it.

Expected behavior

A couple possible solutions to the problem:

  1. Add a "dismiss" button to the notification bar that hides the notification for the rest of the session.
  2. Allow the user to disable the notification for a particular file by including a comment at the top, like //@js-graphql-intellij-plugin-disable-notifications (Requires parsing the text of the file, and requires something to be added to every file.)
  3. Add a setting to allow the user to enable / disable these notifications entirely on a project level. Something like "Warn files are not included in .graphqlconfig" that could default to true
  4. Disable the notification for all files that are specifically excluded from the .graphqlconfig file.
  5. Don't display the warning for files that are specifically excluded in the graphql config file.

I think I like option 4 the best, becuase it's sensible, and if someone excluded a file in the .graphqlconfig that they probably had a good reason to.

Version and Environment Details

Operation system: Big Sur 11.2.3 IDE name and version: Webstorm 2021.1.3 Plugin version: 2.9.1

Additional context

The notification seems to be generated here.

On line 109 of the method there is a check that looks to see whether a file is included in the .graphqlconfigfile

if (GlobalSearchScope.projectScope(project).accept(file)) {
            if (graphQLConfigManager.getClosestConfigFile(file) != null) {
                // has config, but is not included
                return graphQLConfigManager.getClosestIncludingConfigFile(file) == null;
            }
        }

Maybe there could be a getClosestExcludingFile() method on graphQLConfigManager that would check for the closest excluding config file:

if (GlobalSearchScope.projectScope(project).accept(file)) {
            if (graphQLConfigManager.getClosestConfigFile(file) != null) {
               // has config and is excluded
                if(graphqlConfigManager.getClosestExcludingFile(file) !== null) return false

                // has config, but is not included
                return graphQLConfigManager.getClosestIncludingConfigFile(file) == null;
            }
        }
vepanimas commented 3 years ago

@trevor-coleman hi, thank you for the request! I thought about it myself, but I wasn't sure if it was annoying or not, and whether we should somehow change it. As far as I understand the purpose of that editor notification is to indicate explicitly that this file is excluded. I can imagine that some users may accidentally exclude some files, for example, using the wrong globe, and they will not be able to understand why something is not working. Also, it's possible to have many configs, and to find the one which excludes this specific file could be hard.

But I agree that if you know what you're doing It becomes annoying and meaningless. I'll look into that. I'd prefer adding a dismiss button for the whole project and possibly resetting this status when the globes were changed.