apollographql / eslint-plugin-graphql

:vertical_traffic_light: Check your GraphQL query strings against a schema.

Home Page:https://www.npmjs.com/package/eslint-plugin-graphql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle fragments that are defined separately from use

lorensr opened this issue · comments

Linting the below file results in errors:

   4:3   error  Fragment "ReviewEntry" is never used  graphql/template-strings
  22:10  error  Unknown fragment "ReviewEntry"        graphql/template-strings

Is there a way to either:

A. support this format of using fragments, or
B. turn off just this rule?

import gql from 'graphql-tag'

export const REVIEW_ENTRY = gql`
  fragment ReviewEntry on Review {
    id
    text
  }
`

export const ON_REVIEW_CREATED_SUBSCRIPTION = gql`
  subscription onReviewCreated {
    reviewCreated {
      ...ReviewEntry
    }
  }
  ${REVIEW_ENTRY}
`

i go into more detail here but has to due with not being able to statically analyze the interpolated fragment.

the resolution here may be to ignore the NoUsedFragment rule, but the only way to configure this right now is to safelist the list of validators you want to use.

addressing #98 should make this more straightforward.