graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

Some fragments show red underlines in VSCode that disappear after editing/re-saving file containing fragment

Open benasher44 opened this issue 4 years ago • 8 comments

Hi there! We have a graphql config file like this:

schema: "../backend/src/graphql_server/**/*.graphql"
documents: "./src/graphql/**/*.graphql"
extensions:
  codegen:
    overwrite: true
    config:
      noNamespaces: true
      strict: true
      scalars:
        Date: string
        DateTime: string
      withHooks: true
      withComponent: false
      withHOC: false
      reactApolloVersion: 2
    generates:
      src/generated/graphql/graphql.tsx:
        plugins:
          - "typescript"
          - "typescript-operations"
          - "typescript-react-apollo"
          - "fragment-matcher"

We have many fragments defined in documents path(s). There are a (large) handful of fragments that seem to not be initially recognized, when that fragment is referenced in another document graphql file. For example, let's say I have a file containing this fragment:

fragment A {
   ...B
}

If B is defined in the same file, this works, but if B is defined in another file, it may get a red underline. Mousing over it shows the error Unknown fragment "B". GraphQL: Validation.

However, I've found that if I go to the file containing B, delete a character from the fragment's name, add it back, save, go back to the file containing fragment A, remove and re-add the reference to fragment B (in fragment A), the previously unknown fragment B shows up in intellisense, and the red underline disappears. This change does not stick if I reload the window (assuming this is restarting the graphql language server).

The only thing I can tell for sure is that this doesn't impact referencing a fragment in the same file. I haven't been able to figure out some other pattern that would allow me to come up with a standalone, sharable reproduction project.

Versions

VSCode: 1.62.3 GraphQL Extension: 0.3.26

benasher44 avatar Nov 27 '21 18:11 benasher44

Thank you, I noticed this as well when working with fragments recently. It’s by one of a few potential issues.

I added logic to re-build all the caches used for lookup on every request, and this is probably unnecessary, causing performance issues, and potentially causing race conditions where parts of the project-wide fragment cache are not available for reference on certain events.

acao avatar Nov 28 '21 18:11 acao

Hi @acao!

Were there any updates to this recently? We have red underlines in VSCode as well in our fragments (in external files), which disappear after editing the fragment in that file.

JMitnik avatar Mar 15 '22 10:03 JMitnik

The issue is still in place. Are there any updates?

alexey-kachalov avatar Sep 13 '22 10:09 alexey-kachalov

Same issues. Disappear after renaming the fragment. Is there any way to manually rebuild the fragments cache?

Rigo-m avatar Oct 07 '22 09:10 Rigo-m

Hey @acao,

Are there any updates? I experience exactly the same issue in VSCode.

avlaguta avatar Mar 07 '23 18:03 avlaguta

The related issue: #3066

avlaguta avatar Mar 07 '23 18:03 avlaguta

I was trying to move from Apollo extension to this, and this is still an issue apparently?

jimisaacs avatar Apr 19 '23 15:04 jimisaacs

Using schema instead of schemaPath in my config file fixed this issue for me, as referenced in #3066 🎉

manspaniel avatar Sep 19 '23 10:09 manspaniel