graphiql: [graphql-lsp] Template string fragment get `Unknown fragment` error
When inserting a fragment inside a template string, the fragment does not get recognized when it gets called in the rest of the gql string

IDE: VSCode 1.75.1
Extensions:
- GraphQL: Language Feature Support
v0.8.5 - GraphQL: Syntax Highlighting
v1.0.6
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 28 (10 by maintainers)
I’m still having this issue:
fragment file:
.graphqlconfig:
@yamatsum yes it was one of the goals of the last refactor, but the test cases I resolved for don’t seem to cover some of these cases. if someone could provide a test case for MessageProcessor.spec.ts that re-creates this reliably it would be awesome!
@acao if it helps — i’ve noticed since that pretty consistently the error disappears when i:
after that, it seems like pretty much 100% of the time, the error disappears for all the fragments defined in the 1st file.
A college (MAC) has the same issue, but I don’t (Linux) for the same codebase. Interestingly, some fragments are recognised, some not, so not a consistent problem. What’s more interesting is that one particular fragment is recognised in one file, but not in another - Strange!
We have all the fragments in different files. Only one of them has the issue where all have similar structures.
I couldn’t notice a pattern how it happens. There were no issue until some point (see downgrade not below). Then some files previously working fine started displaying red marks without any modifications.
0.11.0to0.9.3resolves the issue.0.11.0revives the issue on the same fragment.i have a theory this bug has resurfaced because of another schema cacheing bug I’ve been working on - thus the fragments are “Unknown” because their base type is missing
hey! having the same issue as @sachingaikwad123
@acao I switched to the pre-release and now the option
extensions.languageService.enableValidation: falseis working 🎊also, the go to fragment definition is working partially, it’s opening the file where the fragment but the cursos do not go the the definition line.
I’ll close it, it should have been fixed in https://github.com/graphql/graphiql/pull/3861
@sachingaikwad123 can you see if the pre-release in #3521 fixes the issue? we have tests that I think should confirm this issue is resolved.
what I discovered was we were updating the fragment cache for onUpdate and onWatchedFilesUpdate, but not on onOpenOrAdd, and some other issues with fragment cache keys that piled up along the way. now we have an integration test suite for the server that confirms a happy path for validating fragments and fragments on queries across changes to all files. i will double check to make sure we are still confirming validation is empty where it should be on every mutative event
Adding “documents” to my config file worked, thanks!
@VinceBT-BG music to my ears! another happy user. I will add something to the FAQ section for users using legacy
schemaPathawesome gif tool by the way, i like the keyboard icons, maybe I will use this!
I was indeed using
schemaPathinstead ofschemain the configuration! I tried on the example and it worked, I also tried in my project and I don’t have the errors anymore, thanks !EDIT:
Indeed when using
schemaPath, in order for the fragments to work, the files need to be specified in anincludesfield, whereas ifschemais present, it will work if placed indocumentsinstead.