eslint-plugin-graphql icon indicating copy to clipboard operation
eslint-plugin-graphql copied to clipboard

Invalid Interpolation Case

Open 0xcaff opened this issue 7 years ago • 5 comments

Hello, I use fragments the following way. I have the following files:

// `fragments/StatsField.graphql`
fragment StatsFields on SongUserStats {
  id
  playCount
  lastPlayed
  liked
}



// test.js
import StatsFields from './fragments/StatsFields.graphql';

const query = gql`
  query {
    stats {
      ...StatsField
    }
  }

  ${StatsFields}
`;

Linting with the following configuration:

  "graphql/template-strings": [
    "warn",
    {
      "env": "literal",
      "tagName": "gql"
    }
 ]

gives the following warning:

  27:7  warning  Invalid interpolation - not a valid fragment or variable  graphql/template-strings

I'd expect this to work, linting the query with information from the fragment in fragments/StatsField.graphql.

0xcaff avatar Jan 27 '18 16:01 0xcaff

I had the same issue. This is a deal breaking to use this library. Is there any way to work around it?

MichaelSu1983 avatar Jun 15 '18 03:06 MichaelSu1983

Unfortunately I don't see any other workaround then putting /* eslint-disable graphql/template-strings */ at the top of the file. It's not possible to disable that particular line, because I cannot add javascript comments inside gql blocks.

chrisvoo avatar Oct 15 '18 08:10 chrisvoo

Try to review your .eslintrc.js file:

  rules: {
    'graphql/template-strings': [
      'error',
      {
        env: 'apollo', // ☝️ <--- here should be `apollo`, 
                       // maybe you have here a wrong `literal` env value
        tagName: 'gql',
        schemaString: fs.readFileSync(path.resolve(__dirname, './schema.graphql'), 'utf8'),
      },
    ],

nodkz avatar Mar 21 '19 11:03 nodkz

Try to review your .eslintrc.js file:

  rules: {
    'graphql/template-strings': [
      'error',
      {
        env: 'apollo', // ☝️ <--- here should be `apollo`, 
                       // maybe you have here a wrong `literal` env value
        tagName: 'gql',
        schemaString: fs.readFileSync(path.resolve(__dirname, './schema.graphql'), 'utf8'),
      },
    ],

Hi there! I have such config, but I still get Invalid interpolation error.

rules: {
   'graphql/template-strings': [
     'error',
     {
       env: 'apollo',
       tagName: 'gql',
       schemaJson: require('./graphql.schema.json'),
     }
   ]
 }

error Invalid interpolation - fragment interpolation must occur outside of the brackets graphql/template-strings

vladcast avatar Nov 21 '19 14:11 vladcast

Has anyone found a solution to this problem?

callmeberzerker avatar Jul 29 '21 19:07 callmeberzerker