Skip to content

Commit

Permalink
bugfix: Recurse on FieldKind for NonNull/List Types
Browse files Browse the repository at this point in the history
Fixes where NonNull and ListTypes were defaulting to scalar types, because we were returning field_type for their kind, which is just that objects name.

Looking at the `schema.json` fixture for Droid (updated test):

```json
{
	"args": [
                {
                  "defaultValue": null,
                  "description": null,
                  "name": "episode",
                  "type": {
                    "kind": "NON_NULL",
                    "name": null,
                    "ofType": {
                      "kind": "SCALAR",
                      "name": "String",
                      "ofType": null
                    }
                  }
                }
              ],
              "deprecationReason": null,
              "description": "Get droids for episode",
              "isDeprecated": false,
              "name": "droidsInEpisode",
              "type": {
                "kind": "LIST",
                "name": null,
                "ofType": {
                  "kind": "OBJECT",
                  "name": "Droid",
                  "ofType": null
                }
              }
            }
```

Previously, the `field_kind` function would return `Droid`. Now, it will properly return `OBJECT` and links will render properly.
  • Loading branch information
bradschwartz committed Sep 27, 2024
1 parent 3c8cede commit 17d4c62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/graphql_markdown/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ defmodule GraphqlMarkdown.Schema do
def field_kind(type) do
case type["kind"] do
"NON_NULL" ->
field_type(type["ofType"])
field_kind(type["ofType"])

"LIST" ->
field_type(type["ofType"])
field_kind(type["ofType"])

_ ->
type["kind"]
Expand Down
2 changes: 1 addition & 1 deletion test/graphql_markdown_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule GraphqlMarkdownTest do

# anchors need to be downcased to match other parts of the generated markdown
content = File.read!("guides/queries.md")
assert content =~ "Type: [Droid](scalars.html#droid)"
assert content =~ "Type: [Droid](objects.html#droid)"

# union types need to be a valid type for links
content = File.read!("guides/mutations.md")
Expand Down

0 comments on commit 17d4c62

Please sign in to comment.