[lsp-server] 🐞 JS/TS files should only be checked when included in `documents` config glob
- Dominant language
- TypeScript
- Stars
- 16.9k
- Forks
- 1.9k
- Avg merge
- 22h 45m
- Merged PRs (30d)
- 70
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current Behavior
It seems that the LSP checks and validates GraphQL code embedded in JS/TS files, even when `.graphqlrc` only lists `*.graphql` globs in `documents`.
This even happens when `documents` explicitly excludes JS/TS files, e.g. via `!**.{js,ts}`.
### Expected Behavior
No checks/validations should be run on GraphQL code inside of JS/TS files when a config with `documents` glob(s) is present, which does _not_ include those JS/TS files (or even excludes them).
### Steps To Reproduce
Repro: https://github.com/echocrow/gql-tada-vs-lsp-repro
1. Set up `.graphqlrc` config:
```json
{
"schema": "src/my-schema.graphql",
"documents": "src/**/*.graphql"
}
```
2. Create `index.ts`:
```ts
const MyExample = graphql(`
fragment MyExample on Foobar @my_tool_directive {
foobar
}
`);
```
In this minimal example, the LSP will unexpectedly check the GraphQL code in this TS file and flag the following:
```
[GraphQL: Validation] Unknown directive "@my_tool_directive".
```
### Environment
* IDE: vscode `v1.88.1`
* IDE Extension: [GraphQL.vscode-graphql](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql) `v0.9.3`
### Anything else?
Motivation:
There days, various tools allow us to embed GraphQL directly in JS/TS files. Sometimes, these tools also introduce new directives, or new ways of structuring fragments/queries/mutations.
However, this can leave to false-positive errors flagged by the GraphQL LSP when it validates JS/TS-embedded GraphQL code. It makes sense that it does not know about those tool-specific directives, but it is unexpected that the embedded GraphQL code is checked by the LSP at all.
Contributor guide
Assessment
This issue has not been assessed yet.