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

[graphql-lsp] Template string fragment get Unknown fragment error #3066

Open
VinceBT-BG opened this issue Mar 1, 2023 · 15 comments
Open

[graphql-lsp] Template string fragment get Unknown fragment error #3066

VinceBT-BG opened this issue Mar 1, 2023 · 15 comments
Labels
bug lsp-server graphql-language-service-server

Comments

@VinceBT-BG
Copy link

VinceBT-BG commented Mar 1, 2023

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

2023-03-01 11 27 00

IDE: VSCode 1.75.1

Extensions:

  • GraphQL: Language Feature Support v0.8.5
  • GraphQL: Syntax Highlighting v1.0.6
@avlaguta
Copy link

avlaguta commented Mar 7, 2023

The related issue:
#2064

@acao
Copy link
Member

acao commented Jun 24, 2023

there must have been a change that broke this use case. it works if the fragments are in a separate file, or are defined in the same graphql string, which is what the tests cover

@acao
Copy link
Member

acao commented Jun 24, 2023

Huh, I can't seem to reproduce the bug now, is it fixed for you in the latest version?

fragment-validation-bug

@VinceBT-BG
Copy link
Author

VinceBT-BG commented Jun 26, 2023

I tried to reproduce your example and I don't have the same result, can you show your config/schema ?

2023-06-26 15 49 31

PS: I am on MacOS Ventura 13.4.1, using

  • GraphQL: Syntax Highlighting v1.2.2 (latest)
  • GraphQL: Language Feature Support v0.8.16 (latest)

@acao
Copy link
Member

acao commented Jun 26, 2023

@VinceBT-BG here is the config:

export default {
   schema: "src/schema/schema.graphql",
   documents: "src/queries/**/*.ts",
};

and a very simple schema for testing purposes:

# for example
type ExampleType {
   shelter: String
   something: String
   however: String
}

type Query {
    exampleField: ExampleType
    love: String
    message: String
}

the syntax highlighting isn't relevant here to be clear, this is a bug you're having with the LSP server, but what I'm guessing is that the documents config isn't provided?

@VinceBT-BG
Copy link
Author

VinceBT-BG commented Jun 26, 2023

I was indeed using schemaPath instead of schema in 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 !

2023-06-26 17 18 01

EDIT:

Indeed when using schemaPath, in order for the fragments to work, the files need to be specified in an includes field, whereas if schema is present, it will work if placed in documents instead.

@acao
Copy link
Member

acao commented Jun 26, 2023

@VinceBT-BG music to my ears! another happy user. I will add something to the FAQ section for users using legacy schemaPath

awesome gif tool by the way, i like the keyboard icons, maybe I will use this!

@acao acao closed this as completed Jun 26, 2023
@Crunchyman-ralph
Copy link

I'm still having this issue:
2023-09-28 22 10 07

fragment file:

import { gql } from '@sb/webapp-api-client/graphql';

export const processTestItemListQuery = gql(/* GraphQL */ `
  query processTestItemListQuery {
    allProcessTestItems(first: 100) {
      edges {
        node {
          ...processTestItemListItemFragment
        }
      }
    }
  }
`);

export const processTestItemListItemDeleteMutation = gql(/* GraphQL */ `
  mutation processTestItemListItemDeleteMutation($input: DeleteProcessTestItemMutationInput!) {
    deleteProcessTestItem(input: $input) {
      deletedIds
    }
  }
`);

export const processTestItemListItemFragment = gql(/* GraphQL */ `
  fragment processTestItemListItemFragment on ProcessTestItemType {
    id
    name
    price
  }
`);

.graphqlconfig:

{
  "name": "Untitled GraphQL Schema",
  "projects": {
    "api": {
      "name": "GraphQL API",
      "schema": "packages/webapp-libs/webapp-api-client/graphql/schema/api.graphql"
    },
    "contentful": {
      "name": "Contentful API",
      "schema": "packages/webapp-libs/webapp-contentful/graphql/schema/contentful.graphql"
    }
  },
  "documents": "**/*.ts"
}

@ypresto
Copy link

ypresto commented Jan 11, 2024

@acao I still have same issue now. Should I create new issue or could you reopen this issue? 🙏

@acao
Copy link
Member

acao commented Jan 11, 2024

@ypresto can you open a new issue, and please provide the config? if it's a multi project config then it's a different bug with the same message

@joshmedeski
Copy link

Adding "documents" to my config file worked, thanks!

@acao acao changed the title [vscode-graphql-syntax] Template string fragment get Unknown fragment error [graphql-lsp] Template string fragment get Unknown fragment error Jan 24, 2024
@acao acao added lsp-server graphql-language-service-server and removed vscode-graphql-syntax labels Jan 24, 2024
@sachingaikwad123
Copy link

sachingaikwad123 commented Feb 26, 2024

I am still facing this issue in my vscode. Here is my graphql-config:

{
"schema": "http://127.0.0.1:8000/graphql/",
"documents": ["src/**/*.{ts,tsx}"]
}

My fragment is defined in another file.

Q: Is there any solution for this?

VSCode version: 1.86.2
GraphQL: Language Feature Support: 0.9.1
vscode-graphql-syntax: 1.3.2

@acao acao reopened this Mar 5, 2024
@acao
Copy link
Member

acao commented Mar 5, 2024

@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

@matheusAle
Copy link

hey! having the same issue as @sachingaikwad123

@acao I switched to the pre-release and now the option extensions.languageService.enableValidation: false is 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.

@acao acao closed this as completed Apr 16, 2024
@acao acao reopened this Apr 16, 2024
@acao
Copy link
Member

acao commented Apr 16, 2024

The only thing i want to clarify here with the incoming fix is that we are not inferring information from template string expressions. If a fragment is present in any file in the project, it can be used in any query, and it's up to the client framework to decide how to resolve fragments

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

No branches or pull requests

8 participants