Processor `@graphql-eslint/graphql` might fail to process due to GraphQL comments.
See original GitHub issueIntro
Not sure if this is really graphql-eslint
or graphql-tag-pluck
issue, but I’ve found a clear reproducible case using this repository, so I thought, I’ll report it here. Also, I’ve made a repository where the issue is reproducible.
Describe the bug
It seems that if processor: '@graphql-eslint/graphql'
option is used together with .graphql
or .gql
files and if those files contain comments, processor might fail to process the file.
E.g.
- This one is processed without any issues:
fragment UserFields on User { id name }
- This one is processed as well without any issues:
# Just any comment without any other file mentions fragment UserFields on User { id name }
- This file fails:
# Lets mention another file, e.g.: User1.fragment.gql in this comment fragment UserFields on User { id name }
To Reproduce
Use this repository: https://github.com/lukaskl/graphql-eslint-parse-issue
git clone git@github.com:lukaskl/graphql-eslint-parse-issue.git
cd graphql-eslint-parse-issue
yarn install --frozen-lockfile
yarn eslint .
✅ Expected result
The output should be something like this:
➜ graphql-eslint-parse-issue yarn eslint .
yarn run v1.15.2
***/src/User0.fragment.gql
3:4 warning This field is marked as deprecated in your GraphQL schema (reason: Use `firstName` instead.) @graphql-eslint/no-deprecated
***/src/User1.fragment.gql
4:4 warning This field is marked as deprecated in your GraphQL schema (reason: Use `firstName` instead.) @graphql-eslint/no-deprecated
***/src/User2.fragment.gql
4:4 warning This field is marked as deprecated in your GraphQL schema (reason: Use `firstName` instead.) @graphql-eslint/no-deprecated
✖ 3 problems (0 errors, 3 warnings)
🔴 Actual result
➜ graphql-eslint-parse-issue yarn eslint .
yarn run v1.15.2
$ ***/node_modules/.bin/eslint .
[graphql-eslint/processor]: Unable to process file "***/src/User2.fragment.gql": SyntaxError: Unexpected token (1:0)
at Object._raise (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:776:17)
at Object.raiseWithData (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:769:17)
at Object.raise (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:737:17)
at Object.unexpected (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:9253:16)
at Object.parseExprAtom (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:10743:20)
at Object.parseExprAtom (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:4996:20)
at Object.parseExprSubscripts (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:10318:23)
at Object.parseUpdate (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:10298:21)
at Object.parseMaybeUnary (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:10276:23)
at Object.parseExprOps (***/node_modules/@graphql-tools/graphql-tag-pluck/node_modules/@babel/parser/lib/index.js:10141:23) {
loc: Position { line: 1, column: 0 },
pos: 0
}
***/src/User0.fragment.gql
3:4 warning This field is marked as deprecated in your GraphQL schema (reason: Use `firstName` instead.) @graphql-eslint/no-deprecated
***/src/User1.fragment.gql
4:4 warning This field is marked as deprecated in your GraphQL schema (reason: Use `firstName` instead.) @graphql-eslint/no-deprecated
***/src/User2.fragment.gql
4:4 warning This field is marked as deprecated in your GraphQL schema (reason: Use `firstName` instead.) @graphql-eslint/no-deprecated
✖ 3 problems (0 errors, 3 warnings)
Environment:
- OS:
macOS Catalina
@graphql-eslint/eslint-plugin@:
0.9.1
- NodeJS:
v14.13.1
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Processor `@graphql-eslint/graphql` might fail to process due ...
gql files and if those files contain comments, processor might fail to process the file. E.g.. This one is processed without any issues:....
Read more >graphql-eslint - Bountysource
Processor `@graphql-eslint/graphql` might fail to process due to GraphQL comments. $ 0. Created 1 year ago in dotansimha/graphql-eslint with 5 comments.
Read more >Full Stack Error Handling with GraphQL and Apollo
As a package author, I would like to be able to write components/middleware that could handle errors automatically in the most appropriate ...
Read more >@graphql-eslint/eslint-plugin - npm
If you are using GraphQL fragments in separate files, some rules might yield incorrect results, due the missing information. To workaround that, ...
Read more >Linting GraphQL Schema and queries - Rule of Tech
Here are some pointers to tools you can use to start linting your GraphQL schema. Resources: eslint-plugin-graphql: Checks tagged query strings ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you have documents in both javascript files and
.graphql
files, your config need to be looks like thisand try to add this fragment to javascript file
We’ll give me this output
I can confirm that, moving
processor: '@graphql-eslint/graphql',
inside of theoverrides
works well 👍 Thank you!And if there is no wish to do anything here more (e.g. documentation or examples update), then we can simply close this ticket.