Skip to content

Commit

Permalink
Merge pull request #1019 from binaryseed/type-kind-updates
Browse files Browse the repository at this point in the history
Corrections on __TypeKind
  • Loading branch information
binaryseed committed Jan 2, 2021
2 parents e74c9d5 + 678b8e7 commit 0f3df91
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Bug Fix: [Interface nullability](https://github.com/absinthe-graphql/absinthe/pull/1009) corrections
- Bug Fix: Fix [field listing for Inputs](https://github.com/absinthe-graphql/absinthe/pull/1015) that import fields
- Bug Fix: Properly [trim all descriptions](https://github.com/absinthe-graphql/absinthe/pull/1014) no matter the mechanism used to specify them
- Bug Fix: Fix incorrect specification of [`__TypeKind`](https://github.com/absinthe-graphql/absinthe/pull/1019)

## 1.5.5

Expand Down
27 changes: 0 additions & 27 deletions lib/absinthe/introspection/kind.ex

This file was deleted.

24 changes: 24 additions & 0 deletions lib/absinthe/introspection/type_kind.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Absinthe.Introspection.TypeKind do
@moduledoc false

# https://spec.graphql.org/draft/#sec-Type-Kinds

defmacro __using__(kind) do
quote do
@behaviour unquote(__MODULE__)
def kind, do: unquote(kind)
end
end

@type type_kind ::
:scalar
| :object
| :interface
| :union
| :enum
| :input_object
| :list
| :non_null

@callback kind() :: type_kind()
end
5 changes: 2 additions & 3 deletions lib/absinthe/type/built_ins/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ defmodule Absinthe.Type.BuiltIns.Introspection do

enum :__type_kind,
values: [
:schema,
:scalar,
:object,
:interface,
:union,
:enum,
:non_null,
:input_object,
:list
:list,
:non_null
]

enum :__directive_location,
Expand Down
1 change: 0 additions & 1 deletion lib/absinthe/type/directive.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Absinthe.Type.Directive do

alias Absinthe.Type
alias Absinthe.Language
use Absinthe.Introspection.Kind

@typedoc """
A defined directive.
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Absinthe.Type.Enum do
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :enum

alias Absinthe.{Blueprint, Type}

Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/input_object.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Absinthe.Type.InputObject do
```
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :input_object
use Absinthe.Type.Fetch

alias Absinthe.Type
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule Absinthe.Type.Interface do
```
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :interface

alias Absinthe.Type
alias Absinthe.Schema
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Absinthe.Type.List do
```
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :list
use Absinthe.Type.Fetch

@typedoc "
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/non_null.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Absinthe.Type.NonNull do
```
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :non_null
use Absinthe.Type.Fetch

@typedoc """
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/object.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule Absinthe.Type.Object do
"""

alias Absinthe.Type
use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :object

@typedoc """
A defined object type.
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/scalar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Absinthe.Type.Scalar do
```
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :scalar

alias Absinthe.Type

Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/type/union.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Absinthe.Type.Union do
```
"""

use Absinthe.Introspection.Kind
use Absinthe.Introspection.TypeKind, :union

alias Absinthe.{Schema, Type}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule Elixir.Absinthe.Integration.Execution.Introspection.TypeKindTest do
use Absinthe.Case, async: true

@query """
query {
__type(name: "__TypeKind") {
name
enumValues {
name
}
}
}
"""

# https://spec.graphql.org/draft/#sel-HAJbLA6GABABKwzN
#
# enum __TypeKind {
# SCALAR
# OBJECT
# INTERFACE
# UNION
# ENUM
# INPUT_OBJECT
# LIST
# NON_NULL
# }

@expected [
"SCALAR",
"OBJECT",
"INTERFACE",
"UNION",
"ENUM",
"INPUT_OBJECT",
"LIST",
"NON_NULL"
]

test "Contains expected values" do
{:ok,
%{
data: %{
"__type" => %{
"name" => "__TypeKind",
"enumValues" => enum_values
}
}
}} = Absinthe.run(@query, Absinthe.Fixtures.ContactSchema, [])

type_kind_values = enum_values |> Enum.map(& &1["name"])

assert Enum.sort(type_kind_values) == Enum.sort(@expected)
end
end

0 comments on commit 0f3df91

Please sign in to comment.