Skip to content

Commit

Permalink
bugfix: Handle NonNull/List Types Properly (#56)
Browse files Browse the repository at this point in the history
* bugfix: Recurse on FieldKind for NonNull/List Types

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.

* bump patch version

* update README for latest version
  • Loading branch information
bradschwartz authored Sep 27, 2024
1 parent 3c8cede commit 0db6f88
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.4.3 - 2024-09-27

### Fixed

* Fixes where NonNull and ListTypes were defaulting to scalar types for anchor links

## 0.4.2 - 2024-09-26

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ by adding `graphql_markdown` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:graphql_markdown, "~> 0.1.2"}
{:graphql_markdown, "~> 0.4.3"}
]
end
```
Expand Down
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 mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule GraphqlMarkdown.MixProject do
use Mix.Project

@project_url "https://github.com/podium/graphql_markdown"
@version "0.4.2"
@version "0.4.3"

def project do
[
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 0db6f88

Please sign in to comment.