graphql-eslint: Cannot query field "admin_notification" on type "Subscription" when multiple projects defined in .graphqlrc.yml
Describe the bug
Here is my .graphqlrc.yml:
projects:
first:
schema: ./first.graphql
documents: ./src/first-gql.js
second:
schema: ./second.graphql
documents: ./src/second-gql.js
Here is my ./src/first-gql.js file:
const queryUsers = gql`
query users($first: Int) {
users(first: $first) {
id
symbol
}
}
`;
Here is my ./src/second-gql.js file:
const subscribeAdminNotification = gql`
subscription admin_notification(
$limit: Int
$order_by: [admin_notification_order_by!]
$where: admin_notification_bool_exp
) {
admin_notification(limit: $limit, order_by: $order_by, where: $where) {
id
level
}
}
`;
When running npx eslint --ext graphql,js . the graphql-eslint linter complains that Cannot query field "admin_notification" on type "Subscription", because it is looking in the wrong .graphql schema!!!
If I remove the first schema definition from .graphqlrc.yml, then it works OK.
Expected behavior
graphql-eslint should lint .js files against their related .graphql schema definition (as defined by the documents field in .graphqlrc.yml)
Otherwise, it breaks compatibility with graphql-config@3 which documentation states that it’s supporting multiple projects
May I know how do you lint when you have multiple .graphql files/projects in .graphqlrc.yml?
Thanks for your help!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 19 (6 by maintainers)
Wow, it just works!
graphql-eslintis now correctly lintinggqltags belonging to multiple projects.And as a bonus,
vscode.graphqlextension now works perfectly.Amazing, Thanks @B2o5T and @dotansimha for the fix and your precious help!
I let you close the issue when you feel appropriate 😃
Fixed in
@graphql-eslint/eslint-plugin@1.1.4😃 Thanks @B2o5T ❤️Ok, I don’t know then what could be the cause…What is reproducible using this public repo is that:
npx eslint ./query2.js) ofjsfiles containinggqltags belonging to different graphql schema worksnpx eslint --ext graphql,js .) ofjsfiles containinggqltags belonging to different graphql schema doesn’t workThis should explain why
vscode.graphqlextension doesn’t work for me when.graphqlrchas multiple projects, as it’s probably using a global expression (my guess).Or you can
npm packin the source directory and point Yarn/Npm to load the artifacttgz.@B2o5T if you’ll push it and create the PR from a branch in this repo (instead of a fork), you’ll get an alpha release from the PR.
I think multi-project should work, since we are using
graphql-config, and it does support. We are usinggetProjectForFileto get the correct schema per each file we are runninggraphql-eslinton, so if the file is included correctly in the project ofgraphql-config, it should load the schema correctly.I think there might be an issue here related to virtual files loaded from code-files? @B2o5T what do you think? I think that here we get the virtual path, and then it leads to an an empty project, since the virtual file doesn’t match the project?
@waterdrop01 can you please try to put your GraphQL operation in a
.graphqlfile and try to update your GraphQL-Config file accordingly? Just to verify that it only happens with virtual files.It seems like your issue is related to https://github.com/dotansimha/graphql-eslint/issues/525 that will be fixed soon
Thank you so much @waterdrop01 for your reproduction repo, it is so much helpful to found where the issue comes! You can try to install
1.1.4-alpha-4a8e08f.0version of@graphql-eslint/eslint-plugin.The issue is comes from caching schemas. Currently, schema is cached by
filedirof every file, and schema forquery2.jsfile was incorrectly loaded duequery1.jsandquery2.jsare located in the same directory. I changed caching schemas by real file path @dotansimha I think it’s better.UPDATE: For better performance, it’s better if we’ll cache schema by
schemaKeylike we already cache withoutgraphql-config. I added a new commit in my PR to fix this.Well, actually directly linting the documents file works:
npx eslint ./query2.jsBUT linting all files with
npx eslint --ext graphql,js .still throw the error:I created a repository so you can reproduce the issue.
Ok, I confirm the fix works for me 👍 Awesome
@dotansimha thanks, I’ll try for my next one 😆