Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting unknown fragment lint error #2071

Closed
waynezhang1995 opened this issue Nov 28, 2021 · 29 comments · Fixed by #2072
Closed

getting unknown fragment lint error #2071

waynezhang1995 opened this issue Nov 28, 2021 · 29 comments · Fixed by #2072
Labels
bug lsp-server graphql-language-service-server

Comments

@waynezhang1995
Copy link

Actual Behavior

we are using Relay and after the recent updates(starting from version 0.3.23), all the fragments are getting flagged as unknown fragment.

Expected Behavior

Steps to Reproduce the Problem Or Description

Specifications

  • GraphQL for VSCode Extension Version: > 0.3.23
  • VSCode Version: Version: 1.61.0 (Universal)
  • OS Name: Mac OS
  • OS Version: Big sur 11.6.1
  • graphql config filename and format example:

Logs Of TS Server || GraphQL Language Service

@acao
Copy link
Member

acao commented Nov 28, 2021

Huh ok! Can you show me a sample graphql-config? Are you using a compatibility layer for relay + graphql config? What version of relay?

We upgraded graphql-config to v4 which may impact compatibility with relay.

@acao
Copy link
Member

acao commented Nov 28, 2021

does this error show all the time or only some of the time?

@waynezhang1995
Copy link
Author

waynezhang1995 commented Nov 28, 2021

Huh ok! Can you show me a sample graphql-config? Are you using a compatibility layer for relay + graphql config? What version of relay?

We upgraded graphql-config to v4 which may impact compatibility with relay.

Hey, thanks for responding. Our graphql.config.js has very minimum settings but it worked with previous versions

module.exports = {
  schema: 'schema.graphql',
  extensions: {
    endpoints: {
      local: {
        url: <....>,
      },
      dev: {
        url: '<....>',
      },
    },
  },
};

relay version: 11.0.3.
Could you elaborate a bit on the compatibility layer? anything we need to add to the config? thanks

@waynezhang1995
Copy link
Author

getting this error all the time

@esquevin
Copy link
Contributor

Encountering the exact same issue. Suddenly fragments are flagged as unknown fragment.

I think a regression was introduced with the latest release. Sadly I'm not able to roll back to a former version as the Install another version… action in vscode just spin infinitely and does not list former versions.

@acao
Copy link
Member

acao commented Nov 30, 2021

Are either of you including files with fragments in documents In graphql-config?

@esquevin
Copy link
Contributor

My .graphqlconfig only contains

{ "schema": "./graphql-schema.json" }

There are no fragments defined in this file.

@acao
Copy link
Member

acao commented Nov 30, 2021

I will look into this one after work tonight, sorry y’all!

I’m surprised it worked without documents configured!

@acao
Copy link
Member

acao commented Nov 30, 2021

this we moved over a year or two ago for legacy relay support:

https://github.com/relay-tools/relay-graphql-js/tree/main/packages/graphql-config

but if it worked before and then didn’t, there are a number of factors. What was the previous version? We made many changes in the language server last year that were published to marketplace and not published to openvsx for a while because of a license agreement bug

our readme instructs you to use documents to point to js, ts, graphql, etc files containing fragments

@acao acao transferred this issue from graphql/vscode-graphql Nov 30, 2021
@acao acao added bug lsp-server graphql-language-service-server labels Nov 30, 2021
@acao
Copy link
Member

acao commented Nov 30, 2021

I think I have a fix, I will need to do more extensive testing, but #2072 I think will address this and many things.

@acao
Copy link
Member

acao commented Nov 30, 2021

Nope. No luck on this one tonight. I have some leads though. Needs way more unit tests

@acao acao reopened this Nov 30, 2021
@esquevin
Copy link
Contributor

esquevin commented Dec 1, 2021

Thank for your efforts anyway =)
Meanwhile I've configured documents and don't have issues anymore

@acao
Copy link
Member

acao commented Dec 6, 2021

@esquevin exciting to hear!

I think I might just document this as a breaking change then. I think this will be the more graphql-config way to do this, and help us reduce unnecessary resource churn by parsing catch-all blobs of files.

@ernieturner
Copy link

@esquevin Do you have an example of what you set your documents value to in your config? I'm trying to get this to work via that method but I'm still having troubles. All of the fragments I use are in *.graphql.ts files but setting the config to documents: ["**/*.graphql.ts"] doesn't seem to work for me. Curious if I'm doing something wrong here.

@esquevin
Copy link
Contributor

I'm using this

{ 
  "schema": "./graphql-schema.json",
  "documents": "src/**/*.{graphql,js,ts,jsx,tsx}"
 }

@eMerzh
Copy link
Contributor

eMerzh commented Apr 11, 2022

go the same issue here...

if i define no dcoument , the output of the graphql-language-service-usage-logs is 👌 but then i get a lot of unknown fragment
if i define for example documents: './src/**/*.jsx' (where my graphq`` tags are .... ) then i got :

Unable to find any GraphQL type definitions for the following pointers:

  • ./src/**/*.jsx

but my editor does not show any error (while showing doc, ... as it should)

@eMerzh
Copy link
Contributor

eMerzh commented Apr 11, 2022

sorry for double notif,
but i also just encounter also a project where fragments are kinda managed outside of regular lib...
i know this is probably not supported but evertything else works (complete, warning, doc, ...)but i have the lint yelling at me for the fragments.

If i could silence them maybe it can "solve" both problems

@acao
Copy link
Member

acao commented Apr 11, 2022

The fragments should be picked up if they are specified in files listed in documents, but that's not working for you for some reason. Hope to have a look at this in the coming weeks.

@xorander00
Copy link

I'm running into this issue myself right now. Figured I'd throw in my $0.02.

When I first open a document (e.g. simple query with fragment spread field selection), it shows the ol' "Unknown fragment ..." error. Then I found that if I open the file where I have my fragments defined and immediately save it, then go back go the query document and save that one, it seems to pick up the fragment definitions and the errors disappear. Just to check I tried auto-completions/suggestions and it worked fine and showed fragments in the list.

I'm on FreeBSD 13.0/amd64 and NeoVim 0.6.0 with the latest graphql-lsp. My graphql config is as follows...

{
  "schema": "./src/graphql/generated/schema.json",
  "documents": [
    "./src/graphql/documents/*.graphql",
    "./src/graphql/documents/**/*.graphql"
  ]
}

@xorander00
Copy link

Just tested it out again a few more times since I wasn't 100% sure it wasn't some weird anomaly. I can confirm that the following happens (in my case at least):

  1. Open query document for editing (myQuery.graphql), see LSP report unknown fragment errors.
  2. Open document that defines fragments (myFragments.graphql) in same instance of editor+lsp.
  3. Insert newline, delete newline, and then save myFragments.graphql.
  4. Switch back to myQuery.graphql, insert newline, delete newline, and then save myQuery.graphql.
  5. Watch errors instantly disappear and completions are now available for fragment types.

@eMerzh
Copy link
Contributor

eMerzh commented Apr 15, 2022

just wondering if it was related to relay (i use relay) and if it requires some special config in the graphql-config file

@hiro1107
Copy link

I got this error just because of some VS code plugin. Possibly you can try removing unofficial GraphQL plugins and check if you still see errors or not.

@acao
Copy link
Member

acao commented Jun 24, 2023

we fixed the issue with loading from documents, there had been a breaking change in graphql-config we overlooked, we now support loading the code files properly

@acao acao closed this as completed Jun 24, 2023
@lewebsimple
Copy link

For anyone stumbling on this issue, removing ignoreNoDocuments: true from the graphql.config.js / codegen.ts file solved the issue for me.

@acao
Copy link
Member

acao commented Jul 28, 2023

thanks @lewebsimple , we may be able to set this on loadDocuments() or set some defaults if this config isn't provided

@lewebsimple
Copy link

Hmmm … turns out the problem came back after a little while so it’s probably something else. Sorry about the confusion…

@stephenjason89
Copy link

stephenjason89 commented Aug 22, 2023

Hello @acao I'm having the same issue as well. I only have the graphql schema on my graphql config. If i point the documents to my fragment.ts file then it breaks the auto completion and references.

Here's my graphql.config.yml
image

I also have this codegen dir but don't know how to incorporate this or why i need to in the graphql config

image

I'm coming from intellij idea and using js-graphql everything is working.

I just recently migrated to vs code and would like to make this work.

Thank you

@jimisaacs
Copy link

jimisaacs commented Aug 23, 2023

Was getting the same error, found out it's because the extension can't handle loading fragments at symlinks.

Example graphql.config.yml:

# $schema: https://raw.githubusercontent.com/kamilkisiela/graphql-config/master/config-schema.json
projects:
  myproject:
    schema: ./projects/myproject/schema.graphqls
    documents:
      # This directory contains symlinks to all the graphql files for myproject (operations and fragments)
      - ./projects/myproject/**/*.graphql
      # The VSCode extension doesn't follow symlinks for fragment inclusion, so need to explicitly include them
      - ../some/other/explicit/location/of/myproject-fragments.graphql

@jimisaacs
Copy link

Maybe it's not the VSCode extension, but the language server 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug lsp-server graphql-language-service-server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants