-
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.
Fix/add tests for compile time default value evaluation (#1026)
* Fix and add tests for compile time default_value evaluation * More tests * Update CHANGELOG * Remove failing test * Make the current time different
- Loading branch information
1 parent
2aed570
commit 4154c91
Showing
10 changed files
with
272 additions
and
57 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
25 changes: 22 additions & 3 deletions
25
test/absinthe/integration/execution/variables/default_value_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 |
---|---|---|
@@ -1,14 +1,33 @@ | ||
defmodule Elixir.Absinthe.Integration.Execution.Variables.DefaultValueTest do | ||
use Absinthe.Case, async: true | ||
|
||
@query """ | ||
@times_query """ | ||
query ($mult: Int = 6) { | ||
times(base: 4, multiplier: $mult) | ||
} | ||
""" | ||
|
||
test "scenario #1" do | ||
@default_value_query """ | ||
query { | ||
microsecond | ||
} | ||
""" | ||
|
||
test "query field arg default_value and resolve execution" do | ||
assert {:ok, %{data: %{"times" => 24}}} == | ||
Absinthe.run(@query, Absinthe.Fixtures.TimesSchema, []) | ||
Absinthe.run(@times_query, Absinthe.Fixtures.TimesSchema, []) | ||
end | ||
|
||
test "query field default is evaluated only once" do | ||
{:ok, %{data: %{"microsecond" => first_current_microsecond}}} = | ||
Absinthe.run(@default_value_query, Absinthe.Fixtures.DefaultValueSchema, []) | ||
|
||
Process.sleep(5) | ||
|
||
{:ok, %{data: %{"microsecond" => second_current_microsecond}}} = | ||
Absinthe.run(@default_value_query, Absinthe.Fixtures.DefaultValueSchema, []) | ||
|
||
# If the code to grab the default_value was executed twice, this would be different | ||
assert first_current_microsecond == second_current_microsecond | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Absinthe.Fixtures.DefaultValueSchema do | ||
use Absinthe.Schema | ||
use Absinthe.Fixture | ||
|
||
# Note: More examples in Absinthe.Fixtures.Query.TestSchemaFieldArgDefaultValueWithImportFields | ||
|
||
query do | ||
field :microsecond, :integer, default_value: DateTime.utc_now().microsecond |> elem(0) | ||
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
Oops, something went wrong.