You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[lsp-server] 🐞 VSCode validation error Unknown fragment in v0.11.0 #3620
I get errors after updating “GraphQL: Language Feature Support” to v0.11.0.
FooFragment is 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
Reacted by Lorenzo Módolo, Michael "Mike" Ferris, Eddie Wang, koutaro-masaki, Pablo Sáez, Fabien Séglard, Ben Soutendijk, Dmytro Klymenko, Michael Schmidt-Voigt, Victor Magalhães and 39 more
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:
Reacted by jhalborg, Eric McCarthy, Hans Krogh Thomsen and Wade Peterson
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:
Reacted by sbiallas, Kevin Smith, Justin Braden, Michael "Mike" Ferris, Jared Ellison, Nikolas Bolya, Mark Slade, Zero Liu and Ivan Bajalovic
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:
Did the same and worked for me!
Reacted by Justin Braden, Andy Hardin, Nikolas Bolya, Blair Lundin and Ivy Feraco
Same issue as here and it's fixed by downgrading to v 9.3.
This is what I found - I get the error where the file containing the fragment couldn't be parsed
[Info - 9:39:01 AM] Could not parse the TypeScript file at <...filepath.ts> to extract the graphql tags:
[Info - 9:39:01 AM] SyntaxError: Unexpected token (4:4)
When I then go to that file and save it, and then go back to where I used the fragment the fragment is picked up and it's working again. I'm guessing the file is parsed successfully and cached when I save the file or something?
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 :LspLogs in my case), the error I saw was:
[ERROR][2024-08-01 11:20:22] ...lsp/handlers.lua:623
"AggregateError: Failed to find any GraphQL type definitions in: ./node_modules/blokkli-beta/dist/**/*.graphql;\n -
Cannot find module '~/components/Teaser/fragment.teaser.graphql'\nRequire stack:\n- /run/media/dulnan/Storage/development...
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.
@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
Reacted by Dimitri POSTOLOV, DerPlayer2001, VBDG, Takagi Kensuke, Lorenzo Módolo, Eric McCarthy, Guney Ozsan, 제스, Niranjan Rajendran, Stephen Bowling and 10 more
Reacted by Caspar Due, Daniel Tijerina, Niranjan Rajendran, andrew hunt, Mark Slade, Juan Latorre, Hans Krogh Thomsen and Mario Vercellotti
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.
Reacted by Sagnik Pradhan
Reacted by Marco Wettstein, Guillaume Esquevin and Landon Marder
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.
So u need a minimal project that exhibits this issue? I don't think this Issue results in failing tests, but in errors in the Intelisense of VSCode (at least that's the case in our Projects). If needed I could provide such a project.
@DerPlayer2001 the test suite would surface the invalid fragment errors you see in vscode. in this case, it would show an invalid fragment definition code validation error which you can assert for.
providing a project config and files would be helpful as well, but would take longer, as we still need to add the failing test case
@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.
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 text appears to be a GraphQL document (not the original TypeScript file) in
Changing that line to parse the raw file with await readFile(filePath, 'utf-8') instead of document.rawSDL appears 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 custom locateCommand).
Reacted by VBDG, Landon Marder, DerPlayer2001, Hironao OTSUBO and Sagnik Pradhan
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 text appears to be a GraphQL document (not the original TypeScript file) in
const contents = await this._parser(document.rawSDL, uri);
Changing that line to parse the raw file with await readFile(filePath, 'utf-8') instead of document.rawSDL appears 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 custom locateCommand).
I can confirm after testing with the modified Line the Errors seem to disappear.
I'm still facing the same issue when using 0.13.0 or 0.13.2 versions.. It only works when I switch back to 0.9.3.
#import './contactDetails.fragment.graphql'fragmentUserDetailsFragmentonUser {
...ContactDetailsFragment # Unknown fragment "ContactDetailsFragment".GraphQL: Validation -> this happens in 0.13.xfirst_namelast_name
}
Activity
sbiallas commentedon Jun 14, 2024
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:

jordanweaver commentedon Jun 14, 2024
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:
sbiallas commentedon Jun 14, 2024
Did the same and worked for me!
VinceBT-BG commentedon Jun 18, 2024
This is kind of a breaking bug, all fragments have broken in my project as well
pronovaso commentedon Jul 3, 2024
Confirm same bugs as mentioned here.
jaredellison-nyt commentedon Jul 19, 2024
Confirming I'm seeing the same bug as well. Adding a plain text version of the logged syntax errors to help others find the github issue.
Reverting to
GraphQL: Language Feature Support v0.9.3resolves the issues.Thanks for the work on this extension, beyond this bug it's an invaluable tool!
ionTea commentedon Jul 26, 2024
Same issue as here and it's fixed by downgrading to v 9.3.
This is what I found - I get the error where the file containing the fragment couldn't be parsed
When I then go to that file and save it, and then go back to where I used the fragment the fragment is picked up and it's working again. I'm guessing the file is parsed successfully and cached when I save the file or something?
dulnan commentedon Aug 1, 2024
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.
#import "~/components/Teaser/fragment.teaser.graphql";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.DerPlayer2001 commentedon Aug 24, 2024
Is there any Progress on resolving this Issue in the Current Version?
acao commentedon Aug 24, 2024
@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
vermario commentedon Nov 20, 2024
Same issue here, only downgrading to 0.9.3 fixes it
acao commentedon Nov 22, 2024
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.
DerPlayer2001 commentedon Nov 22, 2024
@acao
So u need a minimal project that exhibits this issue? I don't think this Issue results in failing tests, but in errors in the Intelisense of VSCode (at least that's the case in our Projects). If needed I could provide such a project.
acao commentedon Nov 22, 2024
@DerPlayer2001 the test suite would surface the invalid fragment errors you see in vscode. in this case, it would show an invalid fragment definition code validation error which you can assert for.
providing a project config and files would be helpful as well, but would take longer, as we still need to add the failing test case
DerPlayer2001 commentedon Nov 22, 2024
@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.
wenchienchen-asana commentedon Jan 24, 2025
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) ingraphiql/packages/graphql-language-service-server/src/parsers/babel.ts
Line 28 in d217a65
graphiql/packages/graphql-language-service-server/src/MessageProcessor.ts
Line 1241 in d217a65
Changing 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).DerPlayer2001 commentedon Jan 30, 2025
I can confirm after testing with the modified Line the Errors seem to disappear.
evanheckert commentedon Feb 4, 2025
Oddly it looks like reverting to 0.9.3 of GraphQL: Language Feature Support did not make the issue go away for me.
React 19 + Typescript 5.7 + codegen
jthoward64 commentedon Feb 4, 2025
Unfortunately the only solution that stuck was dropping graphqp codegen and switching to gql.tada which integrates better with the typescript LSP.
motemen commentedon Feb 7, 2025
Hello, I think this pull request solves the issue thanks to @wenchienchen-asana's comment.
jordanweaver commentedon Mar 14, 2025
I installed the latest version, 0.13.0, and unfortunately, the issue I described above is still present. Re-installing 0.9.3 fixes it. Bummer.
tkappedev commentedon Mar 14, 2025
I think there was not yet a new release of the vscode extension, 0.13.0 was already released last month
vermario commentedon Mar 17, 2025
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
bajalovic commentedon Jul 1, 2025
I'm still facing the same issue when using 0.13.0 or 0.13.2 versions.. It only works when I switch back to 0.9.3.
jer-sen commentedon Dec 3, 2025
Same for me with this kind of code when importing fragment from another file with 0.13.2:
@acao can you check this?