ardatan/graphql-toolkit

Empty space before second comment

vreality64 opened this issue ยท 4 comments

Hello. I'm using merge-graphql-schemas which uses this schema merge. I checked the auto-generated SDL and found the following issues about comment symbol #.

Source

type Some {
  # comment
  #  - first line
  #  - second line
  field: Int
}

Merged - empty space after the second line

type Some {
  # comment
   #  - first line
   #  - second line
  field: Int
}

Empty space is look like bug. Is it intended?

export function printComment(comment: string): string {
return '\n# ' + comment.replace(/\n/g, '\n # ');
}

In the test code, it was removed using the stripWhitespaces utility function. Here are playground link

Also I have another question. Is there option for strip away # generation? I only want to keep not comment but description.

We're working on a fix for indentation issue in #483. To have descriptions instead of comments, you can pass commentDescriptions: false to the options;

mergeTypes(types, { commentDescriptions: false });

@ardatan

We're working on a fix for indentation issue in #483.

Glad to hear that. ๐Ÿ‘

commentDescriptions: false to the options

I tested commentDescriptions options, however return is not same type. (playground)

with commentDescription

mergeTypes(types, { commentDescriptions: true })
// -> SDL string

without commentDescription

mergeTypes(types, { commentDescriptions: false })
// -> Document Node

The reason is below code. However I'm not sure why this happen. In my opinion, it should be same due to option name.

if (config && config.commentDescriptions) {
result = printWithComments(doc);
} else {
result = doc;
}

suggestion

if (config && config.commentDescriptions) { 
  result = printWithComments(doc); 
} else { 
  result = print(doc); 
}

@vreality64 This is done on purpose, because comments are not the part of DocumentNode anymore so we need to return string.

Available in v0.9.8 !!!