-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1195 from maartenvanvliet/validate-unions
Validate type references for invalid wrapped types
- Loading branch information
Showing
7 changed files
with
238 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
test/absinthe/phase/schema/type_references_exist_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
defmodule Absinthe.Schema.Validation.TypeReferencesExistTest do | ||
use Absinthe.Case, async: true | ||
|
||
describe "fields" do | ||
@schema ~S{ | ||
defmodule FieldSchema do | ||
use Absinthe.Schema | ||
query do | ||
field :foo, :string | ||
field :bar, non_null(:string) | ||
field :baz, :qux | ||
end | ||
end | ||
} | ||
|
||
test "errors unknown type reference" do | ||
error = ~r/In field Baz, :qux is not defined in your schema./ | ||
|
||
assert_raise(Absinthe.Schema.Error, error, fn -> | ||
Code.eval_string(@schema, [], __ENV__) | ||
end) | ||
end | ||
end | ||
|
||
describe "objects" do | ||
@schema ~S{ | ||
defmodule ObjectImportSchema do | ||
use Absinthe.Schema | ||
query do | ||
field :foo, :string | ||
end | ||
object :baz do | ||
field :name, :string | ||
end | ||
object :bar do | ||
import_fields non_null(:baz) | ||
end | ||
end | ||
} | ||
test "errors on import_fields with wrapped type" do | ||
error = ~r/In object Bar, cannot accept a non-null or a list type.\n\nGot: Baz!/ | ||
|
||
assert_raise(Absinthe.Schema.Error, error, fn -> | ||
Code.eval_string(@schema, [], __ENV__) | ||
end) | ||
end | ||
|
||
@schema ~S{ | ||
defmodule ObjectInterfaceSchema do | ||
use Absinthe.Schema | ||
query do | ||
field :foo, :string | ||
end | ||
object :baz do | ||
field :name, :string | ||
end | ||
object :qux do | ||
interface list_of(:baz) | ||
end | ||
end | ||
} | ||
test "errors on interface with wrapped type" do | ||
error = ~r/In object Qux, cannot accept a non-null or a list type./ | ||
|
||
assert_raise(Absinthe.Schema.Error, error, fn -> | ||
Code.eval_string(@schema, [], __ENV__) | ||
end) | ||
end | ||
end | ||
|
||
describe "interface" do | ||
@schema ~S{ | ||
defmodule InterfaceSchema do | ||
use Absinthe.Schema | ||
query do | ||
field :foo, :string | ||
end | ||
interface :qux do | ||
interface list_of(:baz) | ||
end | ||
end | ||
} | ||
test "errors on interface with wrapped type" do | ||
error = ~r/In interface Qux, cannot accept a non-null or a list type./ | ||
|
||
assert_raise(Absinthe.Schema.Error, error, fn -> | ||
Code.eval_string(@schema, [], __ENV__) | ||
end) | ||
end | ||
end | ||
|
||
describe "input object" do | ||
@schema ~S{ | ||
defmodule InputObjectSchema do | ||
use Absinthe.Schema | ||
query do | ||
field :foo, :string | ||
end | ||
input_object :bar do | ||
import_fields non_null(:baz) | ||
end | ||
end | ||
} | ||
test "errors on import_fields with wrapped type" do | ||
error = ~r/In input object Bar, cannot accept a non-null or a list type.\n\nGot: Baz!/ | ||
|
||
assert_raise(Absinthe.Schema.Error, error, fn -> | ||
Code.eval_string(@schema, [], __ENV__) | ||
end) | ||
end | ||
end | ||
|
||
describe "union type" do | ||
@schema ~S{ | ||
defmodule UnionSchema do | ||
use Absinthe.Schema | ||
query do | ||
field :foo, :string | ||
end | ||
union :bar do | ||
types [list_of(:baz)] | ||
end | ||
end | ||
} | ||
test "errors on types with wrapped type" do | ||
error = ~r/In union Bar, cannot accept a non-null or a list type./ | ||
|
||
assert_raise(Absinthe.Schema.Error, error, fn -> | ||
Code.eval_string(@schema, [], __ENV__) | ||
end) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters