question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Maintain comments when parsing schema

See original GitHub issue
type GlobalCinemaVenue implements Node @preLoad {
  # @todo Refactor into a dynamic set of identifiers, i.e.
  """
  https://webediamoviespro.com identifier.
  """
  foreignWebediaId: String
}

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
potetocommented, Jul 7, 2020

@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 */, which is far too coarse grained as it disables the lint rule for the entire tagged literal.

/* 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:

  1. The content of a parsed tagged template literal (ie the TemplateElement node) is an unstructured string and therefore un-visitable without a third-party, domain specific parser
  2. A “comment” within the tagged template literal is specific to the domain of the tag and not a concern for eslint
1reaction
dchamberscommented, May 15, 2022

Hi @IvanGoncharov 👋 . We use graphql-eslint but are currently unable to disable linting rules because of tooling we have that uses the parse, visit and print functions from graphql, therefore causing the comments to be stripped from the transformed document. Any update on when this might become possible now that we’re in the 16.x range?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can comments be used in JSON? - Stack Overflow
No. JSON is data-only. If you include a comment, then it must be data too. You could have a designated data element called...
Read more >
JSON Comment Example — How to Comment in JSON Files
A way to skirt around the comments issue is to add data to your JSON file that function as comments. Let's go through...
Read more >
Comments Within SQL Statements - Oracle Help Center
Comments associated with schema and nonschema objects are stored in the data dictionary. Refer to COMMENT for a description of this form of...
Read more >
Using Comments in JSON with Node.js and JavaScript ...
I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed ...
Read more >
Disposition of comments for the Efficient Extensible ... - W3C
EXI enables limited typed encoding support in schema-less encoding. ... So, an EXI parser use large memory to keep grammar data, if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found