-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/add tests for compile time default value evaluation #1026
Merged
binaryseed
merged 5 commits into
absinthe-graphql:master
from
solvedata:fix/add-tests-for-compile-time-default_value-evaluation
Jan 11, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,51 @@ | ||
defmodule Absinthe.Type.QueryTest do | ||
use Absinthe.Case, async: true | ||
|
||
defmodule TestSchema do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to fixtures |
||
use Absinthe.Schema | ||
@module_attribute "goodbye" | ||
alias Absinthe.Fixtures.Query | ||
|
||
defmodule NestedModule do | ||
def nested_function(arg1) do | ||
arg1 | ||
end | ||
end | ||
|
||
def test_function(arg1) do | ||
arg1 | ||
end | ||
|
||
query do | ||
field :normal_string, :string do | ||
arg :arg_example, :string, description: "string" | ||
end | ||
|
||
field :local_function_call, :string do | ||
arg :arg_example, :string, description: test_function("red") | ||
end | ||
|
||
field :function_call_using_absolute_path_to_current_module, :string do | ||
arg :arg_example, :string, | ||
description: Absinthe.Type.QueryTest.TestSchema.test_function("red") | ||
end | ||
|
||
field :standard_library_function, :string do | ||
arg :arg_example, :string, description: String.replace("red", "e", "a") | ||
end | ||
|
||
field :function_in_nested_module, :string do | ||
arg :arg_example, :string, description: NestedModule.nested_function("hello") | ||
end | ||
describe "query field arg keyword description evaluation" do | ||
Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() | ||
|> Enum.each(fn %{ | ||
test_label: test_label, | ||
expected_value: expected_value | ||
} -> | ||
test "for #{test_label} (evaluates description to '#{expected_value}')" do | ||
type = Query.TestSchemaFieldArgDescription.__absinthe_type__("RootQueryType") | ||
|
||
field :external_module_function_call, :string do | ||
arg :arg_example, :string, | ||
description: Absinthe.Fixtures.FunctionEvaluationHelpers.external_function("hello") | ||
assert type.fields[unquote(test_label)].args.arg_example.description == | ||
unquote(expected_value) | ||
end | ||
end) | ||
end | ||
|
||
field :module_attribute_string_concat, :string do | ||
arg :arg_example, :string, description: "hello " <> @module_attribute | ||
end | ||
describe "query field arg default_value evaluation" do | ||
Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() | ||
|> Enum.each(fn %{ | ||
test_label: test_label, | ||
expected_value: expected_value | ||
} -> | ||
test "for #{test_label} (evaluates default_value to '#{expected_value}')" do | ||
type = Query.TestSchemaFieldArgDefaultValue.__absinthe_type__("RootQueryType") | ||
field = type.fields[unquote(test_label)] | ||
|
||
field :interpolation_of_module_attribute, :string do | ||
arg :arg_example, :string, description: "hello #{@module_attribute}" | ||
assert field.args.arg_example.default_value == unquote(expected_value) | ||
end | ||
end | ||
end) | ||
end | ||
|
||
describe "query field arg keyword description evaluation" do | ||
describe "query field arg default_value evaluation with import_fields" do | ||
Absinthe.Fixtures.FunctionEvaluationHelpers.function_evaluation_test_params() | ||
|> Enum.each(fn %{ | ||
test_label: test_label, | ||
expected_value: expected_value | ||
} -> | ||
test "for #{test_label} (evaluates description to '#{expected_value}')" do | ||
type = TestSchema.__absinthe_type__("RootQueryType") | ||
test "for #{test_label} (evaluates default_value to '#{expected_value}')" do | ||
type = | ||
Query.TestSchemaFieldArgDefaultValueWithImportFields.__absinthe_type__("RootQueryType") | ||
|
||
assert type.fields[unquote(test_label)].args.arg_example.description == | ||
unquote(expected_value) | ||
field = type.fields[unquote(test_label)] | ||
|
||
assert field.args.arg_example.default_value == unquote(expected_value) | ||
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed to not work, and i'm guess it was supposed to do the evaluation. Clearly it didn't so just removed and used the
wrap_in_unquote
function. Tests are passing anyway