exogen / graphql-markdown

The easiest way to document your GraphQL schema.
MIT License
178 stars 54 forks source link

bug affecting unions #71

Closed scallion5765 closed 3 weeks ago

scallion5765 commented 3 years ago

If a GraphQL schema defines a union, graphql-markdown renders a HTML table with a row for every type that belongs to the union. In each row, it puts the Markdown description for the type. However, it seem to include this description verbatim (without first rendering it into HTML), which causes problems.

To illustrate, I am attaching 3 files:

  1. a small GraphQL schema;
  2. the Markdown file which is rendered for this schema by graphql-markdown 6.0.0;
  3. the HTML which is produced by feeding the Markdown to Pandoc 2.11.4.

The full command which produced files 2 and 3 is:

npx --no-install graphql-markdown schema.graphql > schema.md && docker run --rm -i pandoc/core:2.11.4 --from=gfm < schema.md > schema.html

Here is a snippet from that last file:

<tr>
<td valign="top"><strong><a href="#dog">Dog</a></strong></td>
<td valign="top">*italic*

<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</td></li>
</ul>
</tr>

There are 2 problems there:

@nextdude, you implemented support for unions. Maybe you could take a look?

scallion5765 commented 3 years ago

I couldn't find a way to attach a file, so I'll just paste my first file (the GraphQL schema) here and leave it to you to generate the Markdown file and the HTML file (which are too long to paste here).

type Query {
  mammals: [Mammal]
}

"""
*italic*

* list item 1
* list item 2
* list item 3
"""
type Dog {
  legs: Int
}

"""
abcde
"""
type Seal {
  fins: Int
}

union Mammal = Dog | Seal
exogen commented 3 years ago

It should include it verbatim, that part seems OK: in general the strategy is to leave the schema Markdown alone and let the Markdown renderer (whatever that ends up being) handle it.

But, Markdown renderers differ in when they actually start parsing Markdown within HTML (like the table and list items). GitHub Flavored Markdown wants blank lines in between any HTML tags and Markdown that should be rendered inside them. So my guess is we need to insert some newlines in there when outputting these descriptions.

scallion5765 commented 3 years ago

my guess is we need to insert some newlines in there when outputting these descriptions.

That should work. It's similar to the workaround that I found, which is to put <!-- --> and a newline at the top of the description of a type (for example, Dog or Seal in the previous comment) and a newline followed by <!-- --> at the end of the description.

nextdude commented 3 years ago

@scallion5765 I'll take a look when I get a chance later this week, add a test case or two and see if the newline solution works.