graphql-code-generator: schema-ast produces empty GraphQL docblock comments

Describe the bug

For some of my types, the ast-schema plugin generates docblocks comments that are empty: image

Some types that do not have a description do not have those empty comments.

That wouldn’t be much annoying if they didn’t make the parser of the JS GraphQL WebStorm plugin fail the parsing (to workaround, I am now using commentDescriptions: true and everything is fine).

  1. My codegen.yml config file:
schema: "http://localhost:3001/graphql"

generates:
  schema.graphql:
    plugins:
      - schema-ast

Expected behavior

I guess the generator does not put a comment block if it receives null for the comment from the introspection query. It should also do the same for empty strings.

Environment:

  • @graphql-codegen/...: everything in version 1.17.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

It should also do the same for empty strings.

If the introspection query is returning an empty string instead of null for a description, then the issue is with the schema itself and not with codegen or graphql-tools. An empty string is not the same as “no description” and the expected behavior when printing a schema with such a description would be to print the provided value.

Example

I’m seeing the same thing as @Eddman described. I’ve tested this with two different GraphQL-implementations. One is based on https://github.com/99designs/gqlgen and one on https://graphene-python.org/.

Both produce the same thing when using graphql@15.3.0, but it looks normal when graphql@14.7.0 is used.

Edit:

I created a workaround for this issue with a hook on MacOS:

  schema.graphql:
    plugins:
      - schema-ast
    config:
      commentDescriptions: true
      includeDirectives: true
    hooks:
      afterOneFileWrite:
        # Todo: remove this hook once https://git.io/JJod4 has been resolved.
        - perl -i -pe 's/\s*""""""\n//g'

You could also use sed with something like: sed -i '' -e ':a' -e 'N' -e '$!ba' -e 's/[ ]*""""""\n//g', but I think perl is more suitable for the job.