-
Notifications
You must be signed in to change notification settings - Fork 106
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
Reload schema in eslint-server if file with schema was changed #593
Comments
Hi @nodkz ! Keeping open until we'll figure this out :) |
I also I think there is a similar problem with the "no-unused-fields" rule. When I alter an operation to use a previously unused field by adding that exact field to my operation, vscode eslint extension still reports the error in the schema file as unused. So I have to restart the eslint server to make it able to see the changes I made |
I've compiled the following little list of rules that suffers the same issue that I stated in my comment above: "@graphql-eslint/no-unused-fields"
"@graphql-eslint/no-unreachable-types"
"@graphql-eslint/fields-on-correct-type"
"@graphql-eslint/known-type-names"
"@graphql-eslint/unique-operation-name"
"@graphql-eslint/unique-fragment-name"
"@graphql-eslint/require-id-when-available"
"@graphql-eslint/provided-required-arguments"
"@graphql-eslint/known-argument-names" Note that there might be more rules that suffer from the same issue |
There's now a command to restart the eslint server (microsoft/vscode-eslint#477 (comment)) ... would it make sense for this extension to have a watcher on the files containing the schema and restarting the eslint server if any of those changes? If you (as the maintainers) disagree, and argue that this would be better to manage in the vscode-eslint repo, can you please open a ticket there, so we can move this a step forward? It would at least be good to add a note for this on the readme, I think, specially because there already is a section about vscode (https://github.com/dotansimha/graphql-eslint#vscode-integration) 😏 |
I just wanted to add that in #985 I describe that this also affects linting of the schema in the backend, not just the operations in the frontend. The issue is not specific to monorepos or frontend operations :) |
Alrighty... So, this is a little heavy-handed, but it should be a viable workaround for most cases: tl;dr
More detail:
"multiCommand.commands": [
{
"command": "multiCommand.restartGraphQLLinting",
"sequence": ["eslint.restart", "vscode-graphql.restart"]
},
]
"runItOn": {
"watchers": [
{
"match": "**/*.{gql,graphql}",
"isShellCommand": false,
"cmd": "multiCommand.restartGraphQLLinting"
}
]
} DisclaimerAs I mentioned, this is probably heavy-handed. I'm sure there's a much better way to do this through the extension host, but I don't have the time or patience right now to learn much more about vscode extensions than I had to for this. Hope this helps some folks out there while the vscode or graphql teams get around to addressing this more elegantly. |
@jonnyasmar any reason to do it this way over moving the logic that reads the GQL schema out of the extension host (which I'm assuming only runs once when the process starts), and running it instead directly inside the lint rule (which is run each time code is changed). Some advantages would be that it could still lint in memory changes in unsaved files, and does not require restarting the extension host |
Yeh, it would be ideal to not have to restart the linters, but that's a bit over my head. Definitely just a hacky workaround here 😅 |
Hi @nodkz @jonnyasmar @joshribakoff-sm @SimonSimCity @Axedyson, @matthew-valenti, @acidoxee and @jonnyasmar ! Future release with cache invalidation could be tested in the following alpha version |
released in |
@B2o5T It does not seem to behave any differently after upgrading ( I have a
|
It has a 10secs delay to omit reloading schema/documents on every file change |
Looks like closing the document in my editor, and opening that file again works. I guess it's a limitation of vscode itself that it doesn't know to re-run linting on the document when the schema has changed. Another workaround seems to be to make any edit to the document and then undo the change, which also forces the linter to run. |
@joshribakoff-sm if you have any idea how this can be improved feel free to share :) for the invalidation cache I was inspired by eslint-plugin-import solution |
can I ask what's the mechanism to reload on file change? Does it mean we push the file to a cache and invalidate cache every some seconds? |
Is your feature request related to a problem? Please describe.
We open monorepo in VSCode where installed eslint with graphql-eslint plugin. And open some
graphql
file inclient
folder with query operation and decide to refactor server schema. We change code in theserver
folder and after that, some watcher replacesschema.graphql
file with new type definitions. But eslint-server still checksgraphql
operation in theclient
folder with old schema (loaded on vscode start up).Describe the solution you'd like
It will be nice if Eslint-server in VSCode automatically reloads graphql schema and does not use stale information for validation rules.
Describe alternatives you've considered
Run manually "Restart ESLint Server" command when schema.graphql file was changed.
Additional context
Especially it works funny when we use some graphql plugin for vscode and graphql-eslint simultaneously. After schema changes developer gets a validation error from vscode plugin for old field
name
, and from graphql-eslint for the new valuename123
. Most developers will be confused and think that both field names are incorrect.The text was updated successfully, but these errors were encountered: