-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maintain comments when parsing schema #2241
Comments
@gajus Thanks for the detailed description, it's definitely something we need to implement 👍 |
@gajus As a temporary solution you can use the same code as prettier: |
@IvanGoncharov, Can I work on this issue? We can add support of adding comments separately in AST at the top level... just as done in prettier... As we perform lexical analysis, we can create a separate comments array whenever a comment is encountered and push the comment in parser._comments... |
@nveenjain Sounds good 👍 |
@IvanGoncharov A number of eslint plugins (e.g. eslint-plugin-relay, eslint-plugin-graphql) make use of this parser to parse GraphQL syntax in their lint rules. One such use case for parsed comments is within GraphQL tagged template literals. Today, it's not possible for someone to disable a specific eslint (or other linter) rule in the tagged literal. With parsed comments, we could allow that with: const query = graphql`
query MyAwesomeQuery($userID: ID!) {
user(id: $userId) {
id
name # eslint-disable-line relay/unused-fields
profilePicture(size: 50) {
...PictureFragment
}
}
}
`; Obviously, this would not actually be supported in eslint itself. The comment could be prefixed with any arbitrary string. Parsing comments would allow GraphQL lint rule authors to make use of comments in whatever format to skip linting that particular line. Without parsed comments, the only way today to disable a GraphQL lint rule is by wrapping the entire block with /* eslint-disable relay/unused-fields */
const query = graphql`
# snip
`;
/* eslint-enable relay/unused-fields */ I've gone back and forth on whether this needs to be addressed in the GraphQL parser or in eslint. I think that it makes the most sense to parse comments here because it's a common feature for parsers and clearly needed for other use cases. I also don't believe this is possible to be reasonably addressed in eslint, because:
|
@poteto Thanks for the detailed description. |
Hi @IvanGoncharov 👋 . We use graphql-eslint but are currently unable to disable linting rules because of tooling we have that uses the |
Is there any update on this issue? Schema stitching is really useful feature, but I'm trying to find a way to keep the comments as we use them to document the API. Is there any workaround? |
Currently when using
parse
, the@todo Refactor into a dynamic set of identifiers, i.e.
is not made available in AST. As a result, this data is lost when implementing utilities for formatting SDL, e.g. https://github.com/gajus/sort-graphql-sdl.It would be nice if there was a way to parse/ print SDL while maintaining comments and descriptions.
The text was updated successfully, but these errors were encountered: