ardatan/graphql-import

importSchema strips away in-line comments for GraphiQL documentation

Closed this issue ยท 7 comments

Hey guys,

Nice work with this module, but there was one issue I spotted. It seems that the parsing removes in-line comments that are intended to be documentation for GraphiQL.

As an example, say I have this type

# import User from "User.graphql"

# The top level query for this GraphQL server
type Query {
  # A desc
  current_user: User
  # Another desc
  jobs: [String]
}

It turns out like so after importSchema does its thing:

type Query {
  current_user: User
  jobs: [String]
}

I'm guessing as part of post processing, this library just outright strips comments...do we have an escape hatch to maintain comments, or did I just totally miss something?

Thanks!

The new style for adding descriptions to fields and types is using """My description""". Those descriptions will also show up as descriptions in the graphql-playground, for example.

You are using comments instead. Those have no meaning in graphql, so they will be stripped.

I agree with @kbrandwijk, however, there still might be cases where you'd want to preserve comments when using graphql-import. I suggest this should be a configurable option, default should probably be true (=preserve).

Thanks for the info @kbrandwijk, got some catching up to do with the latest going-on's of GQL, but the triple quotes works like a champ!

@schickling I don't agree. A comment line has no meaning anymore in the graphql-js version we use. This also means that they are already missing when we parse the schema for the first time. Preserving them would basically mean recreating support for the old 'comment' style descriptions.
Without that support, we simply have no way of determining what the comment even belongs to, plus we have no way to store it in the AST, so it simply cannot be done.
(graphql-js seems to have a backwards compatibility switch on some commands, but they will be gone in the next version, so let's not start depending on them)

@kbrandwijk I have a file with a *.graphql extension and using the """My Description""" format for descriptions is not showing in my GraphiQL interface, is there a new way of adding descriptions?
thanks

For those using AWS AppSync, I don't think AWS supports the """, only #.

@ericnograles Comments are deprecated in GraphQL as explained above. Closing this issue. Feel free to open a new one for further questions.