graphiql: [lsp-server] š VSCode validation error Unknown fragment in v0.11.0
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
I get errors after updating āGraphQL: Language Feature Supportā to v0.11.0.
FooFragmentis defined another file.- No errors if defined in the same file.
Expected Behavior
No errors when using fragments from another files.
Steps To Reproduce
- define fragment
- define query or fragment in another file.
- use fragment defined in step 1
Environment
- LSP Server Version: latest
- OS: macOS 13.5.1
- LSP Client: VSCode v1.89.1
- graphql: v16.8.1
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 48
- Comments: 24 (4 by maintainers)
@DerPlayer2001 not yet, I will let folks know here when it is!
update: still trying to find a job, I will get to this once I do
Hello, I think this pull request solves the issue thanks to @wenchienchen-asanaās comment.
I also noticed this behavior and it was even more subtle in my case⦠all I had to do was simply open the file containing the fragment and then the error disappeared in the file/query where the fragment was spread. But it would come back with any reload or edit.
Not sure how recommended it is, but I opted to manually downgrade through VS Codeās extension manager, where it seems 0.9.3 was the last version prior to 0.11.0:
I was running into the issue where Go to Definition does not work until I open the file containing the fragment in VS Code in my project, where fragments are defined in tagged templates in TypeScript. I found that
textappears to be a GraphQL document (not the original TypeScript file) in https://github.com/graphql/graphiql/blob/d217a65efcf9d4c19368f71310339c831556f26b/packages/graphql-language-service-server/src/parsers/babel.ts#L28 when invoked from https://github.com/graphql/graphiql/blob/d217a65efcf9d4c19368f71310339c831556f26b/packages/graphql-language-service-server/src/MessageProcessor.ts#L1241Changing that line to parse the raw file with
await readFile(filePath, 'utf-8')instead ofdocument.rawSDLappears to fix this particular issue, as well as the syntax errors reported on initialization, however there is still an issue where it always goes to the first fragment in the file when clicked (which I can work around with a customlocateCommand).The new version is now out and at least in our project if fixes the problem š„³ https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql
@acao Sry Iām not familiar with your test suit here I created a lightweight project displaying the bug. In the Readme you will find detailed instructions on how to reproduce it. I hope this helps.
Did the same and worked for me!
Emergency situation: With the recession in Germany, I was caught up in a 30% engineering org layoff in the summer, and without being able to find a job, lost my apartment and had to move back to the US a few weeks ago. I have to prioritize at least some income before I can jump back into open source work.
Meanwhile, as always, PRs are welcome, even a draft PR that adds a failing test case, as re-creating a bug like this is very hard and time consuming, and is the main reason I havenāt been able to solve this. You can use the new functional spec suite for MessageProcessor, which is designed to model real workflows and project configurations, including several scenarios like these.
I have the same problem. I use GraphQl-Codegen with the client preset, which works as expected. I get syntax highlighting and autocomplete options inside the gql tags. But when I use fragments from other files their are not recognized. I had these fragments also working, also with the fragment names showing up as autocomplete options, but I canāt reproduce it. When I rename the generated gql tag to e.g. graphql and adjust the imports suddenly the errors disappear and I get also the right autocomplete options, but after next reload of vscode the errors are there again and autocomplete stops working. I got error messages inside the LSP output for I guess every file which contains a gql tag:
I think there was not yet a new release of the vscode extension, 0.13.0 was already released last month
Same issue here, only downgrading to 0.9.3 fixes it
While I seem to have a slightly different setup than others, I also encountered a similar issue and I was able to figure out whatās causing it in my case. I still had some .graphql files that contain import comments at the top of the file, e.g.
Looking at the logs (in neovim using
:LspLogsin my case), the error I saw was:Since I donāt need these import comments anymore, I was able to remove them. I assume this functionality to resolve these imports was added at one point or it was made to throw an error if the import fails. In my case, the imports are irrelevant anyway because all the documents that could potentially be imported are declared as a pattern in
documents, so their fragments are available even without the import.This is kind of a breaking bug, all fragments have broken in my project as well