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

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

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 4
  • Comments: 15 (7 by maintainers)

Most upvoted comments

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"
}

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 schemaPath

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

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.