From 83746b9140da45ed40e489d31e5e0b6d127ff9bc Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 17 May 2019 23:07:02 -0700 Subject: [PATCH 01/13] Build SDL version of Things test schema --- .../blueprint/schema/schema_declaration.ex | 27 +++++ lib/absinthe/language/schema_declaration.ex | 31 ++++++ .../phase/schema/apply_declaration.ex | 92 ++++++++++++++++ .../validation/type_names_are_unique.ex | 8 ++ lib/absinthe/pipeline.ex | 1 + lib/absinthe/schema/notation/sdl.ex | 22 +--- src/absinthe_parser.yrl | 8 +- .../execution/aliases/alias_test.exs | 2 +- .../execution/aliases/all_caps_alias_test.exs | 2 +- .../aliases/different_selection_sets_test.exs | 2 +- .../aliases/leading_underscore_test.exs | 2 +- .../execution/aliases/weird_test.exs | 2 +- .../execution/aliases/with_errors_test.exs | 2 +- .../integration/execution/context_test.exs | 2 +- .../fragments/basic_root_type_test.exs | 2 +- .../execution/input_object_test.exs | 2 +- .../execution/nested_objects_test.exs | 2 +- .../execution/operation_by_name_test.exs | 10 +- .../errors_include_path_indices_test.exs | 2 +- .../resolution/exceptions/bad_match_test.exs | 2 +- .../exceptions/missing_error_message_test.exs | 2 +- ...r_message_when_returning_multiple_test.exs | 2 +- .../resolution/extra_error_fields_test.exs | 2 +- .../resolution/multiple_errors_test.exs | 2 +- ...multiple_errors_with_extra_fields_test.exs | 2 +- .../integration/execution/root_value_test.exs | 2 +- .../simple_query_returning_list_test.exs | 2 +- .../execution/simple_query_test.exs | 2 +- .../execution/variables/basic_test.exs | 22 ++-- .../integration/parsing/basic_error_test.exs | 2 +- .../integration/validation/cycles_test.exs | 4 +- ...ror_result_when_bad_list_argument_test.exs | 2 +- .../validation/extra_arguments_test.exs | 2 +- ...n_fields_ignored_in_input_objects_test.exs | 2 +- .../validation/invalid_argument_test.exs | 2 +- .../validation/invalid_nested_type_test.exs | 2 +- .../validation/missing_selection_set_test.exs | 2 +- .../validation/required_arguments_test.exs | 2 +- ...unknown_arg_for_list_member_field_test.exs | 2 +- .../validation/unknown_field_test.exs | 2 +- .../unused/with_operation_name_test.exs | 2 +- .../unused/without_operation_name_test.exs | 2 +- .../phase/document/variables_test.exs | 2 +- .../macro_schema.ex} | 2 +- test/support/fixtures/things/sdl_schema.ex | 102 ++++++++++++++++++ 45 files changed, 324 insertions(+), 71 deletions(-) create mode 100644 lib/absinthe/blueprint/schema/schema_declaration.ex create mode 100644 lib/absinthe/language/schema_declaration.ex create mode 100644 lib/absinthe/phase/schema/apply_declaration.ex rename test/support/fixtures/{things_schema.ex => things/macro_schema.ex} (98%) create mode 100644 test/support/fixtures/things/sdl_schema.ex diff --git a/lib/absinthe/blueprint/schema/schema_declaration.ex b/lib/absinthe/blueprint/schema/schema_declaration.ex new file mode 100644 index 0000000000..0e1f664e1a --- /dev/null +++ b/lib/absinthe/blueprint/schema/schema_declaration.ex @@ -0,0 +1,27 @@ +defmodule Absinthe.Blueprint.Schema.SchemaDeclaration do + @moduledoc false + + alias Absinthe.Blueprint + + defstruct description: nil, + module: nil, + field_definitions: [], + directives: [], + source_location: nil, + # Added by phases + flags: %{}, + errors: [], + __reference__: nil, + __private__: [] + + @type t :: %__MODULE__{ + description: nil | String.t(), + module: nil | module(), + directives: [Blueprint.Directive.t()], + field_definitions: [Blueprint.Schema.FieldDefinition.t()], + source_location: nil | Blueprint.SourceLocation.t(), + # Added by phases + flags: Blueprint.flags_t(), + errors: [Absinthe.Phase.Error.t()] + } +end diff --git a/lib/absinthe/language/schema_declaration.ex b/lib/absinthe/language/schema_declaration.ex new file mode 100644 index 0000000000..7b7b330f4f --- /dev/null +++ b/lib/absinthe/language/schema_declaration.ex @@ -0,0 +1,31 @@ +defmodule Absinthe.Language.SchemaDeclaration do + @moduledoc false + + alias Absinthe.{Blueprint, Language} + + defstruct description: nil, + directives: [], + fields: [], + loc: %{line: nil} + + @type t :: %__MODULE__{ + description: nil | String.t(), + directives: [Language.Directive.t()], + fields: [Language.FieldDefinition.t()], + loc: Language.loc_t() + } + + defimpl Blueprint.Draft do + def convert(node, doc) do + %Blueprint.Schema.SchemaDeclaration{ + description: node.description, + field_definitions: Absinthe.Blueprint.Draft.convert(node.fields, doc), + directives: Absinthe.Blueprint.Draft.convert(node.directives, doc), + source_location: source_location(node) + } + end + + defp source_location(%{loc: nil}), do: nil + defp source_location(%{loc: loc}), do: Blueprint.SourceLocation.at(loc) + end +end diff --git a/lib/absinthe/phase/schema/apply_declaration.ex b/lib/absinthe/phase/schema/apply_declaration.ex new file mode 100644 index 0000000000..c057051788 --- /dev/null +++ b/lib/absinthe/phase/schema/apply_declaration.ex @@ -0,0 +1,92 @@ +defmodule Absinthe.Phase.Schema.ApplyDeclaration do + @moduledoc false + + use Absinthe.Phase + alias Absinthe.Blueprint + + @type operation :: :query | :mutation | :subscription + + @type root_mappings :: %{operation() => Blueprint.TypeReference.Name.t()} + + def run(blueprint, _opts) do + blueprint = process(blueprint) + {:ok, blueprint} + end + + # Apply schema declaration to each schema definition + @spec process(blueprint :: Blueprint.t()) :: Blueprint.t() + defp process(blueprint = %Blueprint{}) do + %{blueprint | schema_definitions: Enum.map(blueprint.schema_definitions, &process_schema_definition/1)} + end + + # Strip the schema declaration out of the schema's type definitions and apply ita + @spec process_schema_definition(schema_definition :: Blueprint.Schema.SchemaDefinition.t()) :: Blueprint.Schema.SchemaDefinition.t() + defp process_schema_definition(schema_definition) do + {declarations, type_defs} = + Enum.split_with(schema_definition.type_definitions, &match?(%Blueprint.Schema.SchemaDeclaration{}, &1)) + # Remove declaration + schema_definition = %{schema_definition | type_definitions: type_defs} + case declarations do + [declaration] -> + root_mappings = + declaration + |> extract_root_mappings + %{schema_definition | type_definitions: Enum.map(schema_definition.type_definitions, &maybe_mark_root(&1, root_mappings))} + + [] -> + schema_definition + + [_first | extra_declarations] -> + extra_declarations + |> Enum.reduce(schema_definition, fn declaration, acc -> + acc + |> put_error(error(declaration)) + end) + end + end + + # Generate an error for extraneous schema declarations + @spec error(declaration :: Blueprint.Schema.SchemaDeclaration.t()) :: Absinthe.Phase.Error.t() + defp error(declaration) do + %Absinthe.Phase.Error{ + message: "More than one schema declaration found. Only one instance of `schema' should be present in SDL.", + locations: [declaration.__reference__.location], + phase: __MODULE__ + } + end + + # Extract the declared root type names + @spec extract_root_mappings(declaration :: Blueprint.Schema.SchemaDeclaration.t()) :: root_mappings() + defp extract_root_mappings(declaration) do + for field_def <- declaration.field_definitions, field_def.identifier in ~w(query mutation subscription)a, into: %{} do + {field_def.identifier, field_def.type} + end + end + + # If the type definition is declared as a root type, set the identifier appropriately + @spec maybe_mark_root(type_def :: Blueprint.Schema.node_t(), root_mappings :: root_mappings()) :: Blueprint.Schema.node_t() + defp maybe_mark_root(%Blueprint.Schema.ObjectTypeDefinition{} = type_def, root_mappings) do + case operation_root_identifier(type_def, root_mappings) do + nil -> + type_def + + identifier -> + %{type_def | identifier: identifier} + end + end + defp maybe_mark_root(type_def, _root_mappings), do: type_def + + # Determine which, if any, root identifier should be applied to an object type definitiona + @spec operation_root_identifier(type_def :: Blueprint.Schema.ObjectTypeDefinition.t(), root_mappings :: root_mappings()) :: nil | operation() + defp operation_root_identifier(type_def, root_mappings) do + match_name = type_def.name + Enum.find_value(root_mappings, fn + {ident, %{name: ^match_name}} -> + ident + + _ -> + false + end) + end + +end diff --git a/lib/absinthe/phase/schema/validation/type_names_are_unique.ex b/lib/absinthe/phase/schema/validation/type_names_are_unique.ex index fcbf9671fb..bc36151873 100644 --- a/lib/absinthe/phase/schema/validation/type_names_are_unique.ex +++ b/lib/absinthe/phase/schema/validation/type_names_are_unique.ex @@ -12,6 +12,14 @@ defmodule Absinthe.Phase.Schema.Validation.TypeNamesAreUnique do end defp handle_schemas(%Blueprint.Schema.SchemaDefinition{} = schema, key) do + if Enum.any?(schema.type_definitions, fn + %Blueprint.Schema.SchemaDefinition{} -> + true + _ -> + false + end) do + raise "SchemaDefinition Inside Schema Definition" + end types = Enum.group_by(schema.type_definitions, &Map.fetch!(&1, key)) directives = Enum.group_by(schema.directive_definitions, &Map.fetch!(&1, key)) diff --git a/lib/absinthe/pipeline.ex b/lib/absinthe/pipeline.ex index fc5d60aeeb..13e69bdcd0 100644 --- a/lib/absinthe/pipeline.ex +++ b/lib/absinthe/pipeline.ex @@ -116,6 +116,7 @@ defmodule Absinthe.Pipeline do def for_schema(schema, _options \\ []) do [ Phase.Schema.TypeImports, + Phase.Schema.ApplyDeclaration, Phase.Schema.Introspection, {Phase.Schema.Decorate, [schema: schema]}, Phase.Schema.NormalizeReferences, diff --git a/lib/absinthe/schema/notation/sdl.ex b/lib/absinthe/schema/notation/sdl.ex index e466f06aa9..2921895d43 100644 --- a/lib/absinthe/schema/notation/sdl.ex +++ b/lib/absinthe/schema/notation/sdl.ex @@ -47,25 +47,7 @@ defmodule Absinthe.Schema.Notation.SDL do defp put_ref(node, ref, opts), do: do_put_ref(node, ref, opts) - # @field_types [ - # Blueprint.Schema.FieldDefinition, - # Blueprint.Schema.EnumValueDefinition, - # Blueprint.Schema.InputValueDefinition - # ] - - # TODO: Which else of these need the conversions? - # Blueprint.Schema.DirectiveDefinition, - # Blueprint.Schema.EnumTypeDefinition, - # Blueprint.Schema.InputObjectTypeDefinition, - # Blueprint.Schema.InterfaceTypeDefinition, - # Blueprint.Schema.ObjectTypeDefinition, - # Blueprint.Schema.ScalarTypeDefinition, - # Blueprint.Schema.UnionTypeDefinition - # Blueprint.Schema.EnumValueDefinition - # Blueprint.Schema.InputValueDefinition - - defp do_put_ref(%_{__reference__: nil, name: name} = node, ref, opts) do - # adapter = Keyword.get(opts, :adapter, Absinthe.Adapter.LanguageConventions) + defp do_put_ref(%_{__reference__: nil} = node, ref, opts) do ref = case opts[:path] do @@ -76,7 +58,7 @@ defmodule Absinthe.Schema.Notation.SDL do put_in(ref.location, %{file: {:unquote, [], [path]}, line: node.source_location.line}) end - %{node | __reference__: ref, name: name} + %{node | __reference__: ref} end defp do_put_ref(node, _ref, _opts), do: node diff --git a/src/absinthe_parser.yrl b/src/absinthe_parser.yrl index 53b4e40e4f..7d1f1fb95a 100644 --- a/src/absinthe_parser.yrl +++ b/src/absinthe_parser.yrl @@ -194,10 +194,10 @@ DirectiveDefinition -> 'directive' '@' Name 'on' DirectiveDefinitionLocations Di DirectiveDefinition -> 'directive' '@' Name ArgumentsDefinition 'on' DirectiveDefinitionLocations Directives : build_ast_node('DirectiveDefinition', #{'name' => extract_binary('$3'), 'arguments' => '$4', 'directives' => '$7', 'locations' => extract_directive_locations('$6')}, extract_location('$1')). -SchemaDefinition -> 'schema' : build_ast_node('SchemaDefinition', #{}, extract_location('$1')). -SchemaDefinition -> 'schema' Directives : build_ast_node('SchemaDefinition', #{'directives' => '$2'}, extract_location('$1')). -SchemaDefinition -> 'schema' '{' FieldDefinitionList '}' : build_ast_node('SchemaDefinition', #{'fields' => '$3'}, extract_location('$1')). -SchemaDefinition -> 'schema' Directives '{' FieldDefinitionList '}' : build_ast_node('SchemaDefinition', #{'directives' => '$2', 'fields' => '$4'}, extract_location('$1')). +SchemaDefinition -> 'schema' : build_ast_node('SchemaDeclaration', #{}, extract_location('$1')). +SchemaDefinition -> 'schema' Directives : build_ast_node('SchemaDeclaration', #{'directives' => '$2'}, extract_location('$1')). +SchemaDefinition -> 'schema' '{' FieldDefinitionList '}' : build_ast_node('SchemaDeclaration', #{'fields' => '$3'}, extract_location('$1')). +SchemaDefinition -> 'schema' Directives '{' FieldDefinitionList '}' : build_ast_node('SchemaDeclaration', #{'directives' => '$2', 'fields' => '$4'}, extract_location('$1')). ObjectTypeDefinition -> 'type' Name : build_ast_node('ObjectTypeDefinition', #{'name' => extract_binary('$2')}, extract_location('$1')). diff --git a/test/absinthe/integration/execution/aliases/alias_test.exs b/test/absinthe/integration/execution/aliases/alias_test.exs index 5bed8f6f79..2b2699e3cb 100644 --- a/test/absinthe/integration/execution/aliases/alias_test.exs +++ b/test/absinthe/integration/execution/aliases/alias_test.exs @@ -13,6 +13,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.AliasTest do test "scenario #1" do assert {:ok, %{data: %{"widget" => %{"name" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs b/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs index 731125418a..68c8cd4618 100644 --- a/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs +++ b/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs @@ -11,6 +11,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.AllCapsAliasTest do test "scenario #1" do assert {:ok, %{data: %{"thing" => %{"FOO" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs b/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs index 776f90f4f5..d5db92838d 100644 --- a/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs +++ b/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs @@ -14,6 +14,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.DifferentSelectionSetsTe test "scenario #1" do assert {:ok, %{data: %{"thing1" => %{"id" => "foo"}, "thing2" => %{"name" => "Bar"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/aliases/leading_underscore_test.exs b/test/absinthe/integration/execution/aliases/leading_underscore_test.exs index 70a2ad24ac..4253e6c54d 100644 --- a/test/absinthe/integration/execution/aliases/leading_underscore_test.exs +++ b/test/absinthe/integration/execution/aliases/leading_underscore_test.exs @@ -11,6 +11,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.LeadingUnderscoreTest do test "scenario #1" do assert {:ok, %{data: %{"_thing123" => %{"name" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/aliases/weird_test.exs b/test/absinthe/integration/execution/aliases/weird_test.exs index 7939139ee1..016868aa16 100644 --- a/test/absinthe/integration/execution/aliases/weird_test.exs +++ b/test/absinthe/integration/execution/aliases/weird_test.exs @@ -11,6 +11,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.WeirdTest do test "scenario #1" do assert {:ok, %{data: %{"thing" => %{"fOO_Bar_baz" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/aliases/with_errors_test.exs b/test/absinthe/integration/execution/aliases/with_errors_test.exs index a5f12bcf80..414c5d1c41 100644 --- a/test/absinthe/integration/execution/aliases/with_errors_test.exs +++ b/test/absinthe/integration/execution/aliases/with_errors_test.exs @@ -17,6 +17,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.WithErrorsTest do locations: [%{column: 12, line: 1}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/context_test.exs b/test/absinthe/integration/execution/context_test.exs index b1366e7686..3415407eff 100644 --- a/test/absinthe/integration/execution/context_test.exs +++ b/test/absinthe/integration/execution/context_test.exs @@ -11,6 +11,6 @@ defmodule Elixir.Absinthe.Integration.Execution.ContextTest do test "scenario #1" do assert {:ok, %{data: %{"thingByContext" => %{"name" => "Bar"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, context: %{thing: "bar"}) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, context: %{thing: "bar"}) end end diff --git a/test/absinthe/integration/execution/fragments/basic_root_type_test.exs b/test/absinthe/integration/execution/fragments/basic_root_type_test.exs index f66b2c851e..3c38a7ed65 100644 --- a/test/absinthe/integration/execution/fragments/basic_root_type_test.exs +++ b/test/absinthe/integration/execution/fragments/basic_root_type_test.exs @@ -15,6 +15,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Fragments.BasicRootTypeTest do test "scenario #1" do assert {:ok, %{data: %{"thing" => %{"name" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/input_object_test.exs b/test/absinthe/integration/execution/input_object_test.exs index c865fdcce2..effbd5f873 100644 --- a/test/absinthe/integration/execution/input_object_test.exs +++ b/test/absinthe/integration/execution/input_object_test.exs @@ -12,6 +12,6 @@ defmodule Elixir.Absinthe.Integration.Execution.InputObjectTest do test "scenario #1" do assert {:ok, %{data: %{"updateThing" => %{"name" => "Foo", "value" => 100}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/nested_objects_test.exs b/test/absinthe/integration/execution/nested_objects_test.exs index b67bd46bbb..7edc895023 100644 --- a/test/absinthe/integration/execution/nested_objects_test.exs +++ b/test/absinthe/integration/execution/nested_objects_test.exs @@ -14,6 +14,6 @@ defmodule Elixir.Absinthe.Integration.Execution.NestedObjectsTest do test "scenario #1" do assert {:ok, %{data: %{"thing" => %{"name" => "Foo", "otherThing" => %{"name" => "Bar"}}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/operation_by_name_test.exs b/test/absinthe/integration/execution/operation_by_name_test.exs index 494fd7185e..52e5f1f31d 100644 --- a/test/absinthe/integration/execution/operation_by_name_test.exs +++ b/test/absinthe/integration/execution/operation_by_name_test.exs @@ -16,7 +16,7 @@ defmodule Elixir.Absinthe.Integration.Execution.OperationByNameTest do test "scenario #1" do assert {:ok, %{data: %{"thing" => %{"name" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, operation_name: "ThingFoo", variables: %{"id" => "foo"} ) @@ -31,7 +31,7 @@ defmodule Elixir.Absinthe.Integration.Execution.OperationByNameTest do "Must provide a valid operation name if query contains multiple operations." } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end test "scenario #3" do @@ -43,12 +43,12 @@ defmodule Elixir.Absinthe.Integration.Execution.OperationByNameTest do "Must provide a valid operation name if query contains multiple operations." } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, operation_name: "invalid") + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, operation_name: "invalid") end test "scenario #4" do assert {:ok, %{data: %{"thing" => %{"name" => "Bar"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, operation_name: "ThingBar") + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, operation_name: "ThingBar") end @query """ @@ -82,6 +82,6 @@ defmodule Elixir.Absinthe.Integration.Execution.OperationByNameTest do } ] }} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, operation_name: "Second") + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, operation_name: "Second") end end diff --git a/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs b/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs index cf7066e339..6bc1a1065f 100644 --- a/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs +++ b/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs @@ -23,6 +23,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.ErrorsIncludePathIndi locations: [%{column: 5, line: 4}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs b/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs index a0907e26f1..ee9218bb9f 100644 --- a/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs +++ b/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs @@ -11,7 +11,7 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.Exceptions.BadMatchTe test "scenario #1" do assert_raise(Absinthe.ExecutionError, fn -> - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end) end end diff --git a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs index 6ab52a613d..a0f5af5b7d 100644 --- a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs +++ b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs @@ -7,7 +7,7 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.Exceptions.MissingErr test "scenario #1" do assert_raise(Absinthe.ExecutionError, fn -> - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end) end end diff --git a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs index e738c8779f..52cb3edb66 100644 --- a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs +++ b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs @@ -7,7 +7,7 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.Exceptions.MissingErr test "scenario #1" do assert_raise(Absinthe.ExecutionError, fn -> - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end) end end diff --git a/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs b/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs index 56b75494b4..09b3aae844 100644 --- a/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs +++ b/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs @@ -17,6 +17,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.ExtraErrorFieldsTest locations: [%{column: 12, line: 1}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/resolution/multiple_errors_test.exs b/test/absinthe/integration/execution/resolution/multiple_errors_test.exs index 7747096e8a..b0996b2487 100644 --- a/test/absinthe/integration/execution/resolution/multiple_errors_test.exs +++ b/test/absinthe/integration/execution/resolution/multiple_errors_test.exs @@ -13,6 +13,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.MultipleErrorsTest do %{message: "one", path: ["failingThing"], locations: [%{column: 12, line: 1}]}, %{message: "two", path: ["failingThing"], locations: [%{column: 12, line: 1}]} ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs b/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs index e9fdeead8a..c91be03918 100644 --- a/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs +++ b/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs @@ -23,6 +23,6 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.MultipleErrorsWithExt locations: [%{column: 12, line: 1}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/root_value_test.exs b/test/absinthe/integration/execution/root_value_test.exs index f5f96a56de..8b4f7c2b80 100644 --- a/test/absinthe/integration/execution/root_value_test.exs +++ b/test/absinthe/integration/execution/root_value_test.exs @@ -7,6 +7,6 @@ defmodule Elixir.Absinthe.Integration.Execution.RootValueTest do test "scenario #1" do assert {:ok, %{data: %{"version" => "0.0.1"}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, root_value: %{version: "0.0.1"}) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, root_value: %{version: "0.0.1"}) end end diff --git a/test/absinthe/integration/execution/simple_query_returning_list_test.exs b/test/absinthe/integration/execution/simple_query_returning_list_test.exs index 9914173b73..cd1d460799 100644 --- a/test/absinthe/integration/execution/simple_query_returning_list_test.exs +++ b/test/absinthe/integration/execution/simple_query_returning_list_test.exs @@ -16,6 +16,6 @@ defmodule Elixir.Absinthe.Integration.Execution.SimpleQueryReturningListTest do data: %{ "things" => [%{"id" => "bar", "name" => "Bar"}, %{"id" => "foo", "name" => "Foo"}] } - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/simple_query_test.exs b/test/absinthe/integration/execution/simple_query_test.exs index 7f8791181f..a839d56a08 100644 --- a/test/absinthe/integration/execution/simple_query_test.exs +++ b/test/absinthe/integration/execution/simple_query_test.exs @@ -7,6 +7,6 @@ defmodule Elixir.Absinthe.Integration.Execution.SimpleQueryTest do test "scenario #1" do assert {:ok, %{data: %{"thing" => %{"name" => "Foo"}}}} == - Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/execution/variables/basic_test.exs b/test/absinthe/integration/execution/variables/basic_test.exs index 316feafd9a..658dcf6832 100644 --- a/test/absinthe/integration/execution/variables/basic_test.exs +++ b/test/absinthe/integration/execution/variables/basic_test.exs @@ -10,11 +10,21 @@ defmodule Elixir.Absinthe.Integration.Execution.Variables.BasicTest do """ test "scenario #1" do - assert {:ok, %{data: %{"thing" => %{"name" => "Bar"}}}} == - Absinthe.run( - @query, - Absinthe.Fixtures.ThingsSchema, - variables: %{"thingId" => "bar"} - ) + for schema <- schema_implementations(Absinthe.Fixtures.Things) do + assert {:ok, %{data: %{"thing" => %{"name" => "Bar"}}}} == + Absinthe.run( + @query, + schema, + variables: %{"thingId" => "bar"} + ) + end end + + defp schema_implementations(base) do + [ + Module.safe_concat(base, MacroSchema), + Module.safe_concat(base, SDLSchema) + ] + end + end diff --git a/test/absinthe/integration/parsing/basic_error_test.exs b/test/absinthe/integration/parsing/basic_error_test.exs index 002f6eb015..d48fad560a 100644 --- a/test/absinthe/integration/parsing/basic_error_test.exs +++ b/test/absinthe/integration/parsing/basic_error_test.exs @@ -13,6 +13,6 @@ defmodule Elixir.Absinthe.Integration.Parsing.BasicErrorTest do errors: [ %{message: "syntax error before: '}'", locations: [%{column: 21, line: 2}]} ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/cycles_test.exs b/test/absinthe/integration/validation/cycles_test.exs index 346a3cf6ae..fd1af6d5ac 100644 --- a/test/absinthe/integration/validation/cycles_test.exs +++ b/test/absinthe/integration/validation/cycles_test.exs @@ -28,7 +28,7 @@ defmodule Elixir.Absinthe.Integration.Validation.CyclesTest do locations: [%{column: 1, line: 8}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end @query """ @@ -50,6 +50,6 @@ defmodule Elixir.Absinthe.Integration.Validation.CyclesTest do locations: [%{column: 3, line: 6}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs b/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs index f23c87325e..c0fd1dbfd4 100644 --- a/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs +++ b/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs @@ -18,6 +18,6 @@ defmodule Elixir.Absinthe.Integration.Validation.ErrorResultWhenBadListArgumentT locations: [%{column: 9, line: 2}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/extra_arguments_test.exs b/test/absinthe/integration/validation/extra_arguments_test.exs index 3e965e6f02..aff0b3ed7b 100644 --- a/test/absinthe/integration/validation/extra_arguments_test.exs +++ b/test/absinthe/integration/validation/extra_arguments_test.exs @@ -19,6 +19,6 @@ defmodule Elixir.Absinthe.Integration.Validation.ExtraArgumentsTest do locations: [%{column: 20, line: 2}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs b/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs index e6a450271a..031f997916 100644 --- a/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs +++ b/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs @@ -23,7 +23,7 @@ defmodule Elixir.Absinthe.Integration.Validation.IntrospectionFieldsIgnoredInInp }} == Absinthe.run( @query, - Absinthe.Fixtures.ThingsSchema, + Absinthe.Fixtures.Things.MacroSchema, variables: %{"input" => %{"__typename" => "foo", "value" => 100}} ) end diff --git a/test/absinthe/integration/validation/invalid_argument_test.exs b/test/absinthe/integration/validation/invalid_argument_test.exs index 6fb0595c89..5673c5fe58 100644 --- a/test/absinthe/integration/validation/invalid_argument_test.exs +++ b/test/absinthe/integration/validation/invalid_argument_test.exs @@ -14,6 +14,6 @@ defmodule Elixir.Absinthe.Integration.Validation.InvalidArgumentTest do locations: [%{column: 16, line: 1}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/invalid_nested_type_test.exs b/test/absinthe/integration/validation/invalid_nested_type_test.exs index ed9cd1fe86..2de5c1ef19 100644 --- a/test/absinthe/integration/validation/invalid_nested_type_test.exs +++ b/test/absinthe/integration/validation/invalid_nested_type_test.exs @@ -20,6 +20,6 @@ defmodule Elixir.Absinthe.Integration.Validation.InvalidNestedTypeTest do locations: [%{column: 33, line: 2}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/missing_selection_set_test.exs b/test/absinthe/integration/validation/missing_selection_set_test.exs index 18ecab9858..116813d9d1 100644 --- a/test/absinthe/integration/validation/missing_selection_set_test.exs +++ b/test/absinthe/integration/validation/missing_selection_set_test.exs @@ -17,6 +17,6 @@ defmodule Elixir.Absinthe.Integration.Validation.MissingSelectionSetTest do locations: [%{column: 3, line: 2}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/required_arguments_test.exs b/test/absinthe/integration/validation/required_arguments_test.exs index 249a8ae78a..accdb95a73 100644 --- a/test/absinthe/integration/validation/required_arguments_test.exs +++ b/test/absinthe/integration/validation/required_arguments_test.exs @@ -14,6 +14,6 @@ defmodule Elixir.Absinthe.Integration.Validation.RequiredArgumentsTest do locations: [%{column: 9, line: 1}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs b/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs index 8364f99c80..7c795eb86e 100644 --- a/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs +++ b/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs @@ -19,6 +19,6 @@ defmodule Elixir.Absinthe.Integration.Validation.UnknownArgForListMemberFieldTes locations: [%{column: 8, line: 3}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/unknown_field_test.exs b/test/absinthe/integration/validation/unknown_field_test.exs index 76cdd91dc4..343a7e76b7 100644 --- a/test/absinthe/integration/validation/unknown_field_test.exs +++ b/test/absinthe/integration/validation/unknown_field_test.exs @@ -19,6 +19,6 @@ defmodule Elixir.Absinthe.Integration.Validation.UnknownFieldTest do locations: [%{column: 5, line: 4}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs b/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs index b99191f915..d10d53d9b5 100644 --- a/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs +++ b/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs @@ -18,6 +18,6 @@ defmodule Elixir.Absinthe.Integration.Validation.Variables.Unused.WithOperationN locations: [%{column: 23, line: 1}, %{column: 1, line: 1}] } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs b/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs index c257985c87..05c2e34cd9 100644 --- a/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs +++ b/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs @@ -15,6 +15,6 @@ defmodule Elixir.Absinthe.Integration.Validation.Variables.Unused.WithoutOperati errors: [ %{message: "Variable \"test\" is never used.", locations: [%{column: 8, line: 1}]} ] - }} == Absinthe.run(@query, Absinthe.Fixtures.ThingsSchema, []) + }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, []) end end diff --git a/test/absinthe/phase/document/variables_test.exs b/test/absinthe/phase/document/variables_test.exs index ae8d3e5cd2..1970c1b061 100644 --- a/test/absinthe/phase/document/variables_test.exs +++ b/test/absinthe/phase/document/variables_test.exs @@ -77,7 +77,7 @@ defmodule Absinthe.Phase.Document.VariablesTest do ] } - assert {:ok, expected} == Absinthe.run(doc, Absinthe.Fixtures.ThingsSchema) + assert {:ok, expected} == Absinthe.run(doc, Absinthe.Fixtures.Things.MacroSchema) end def input(query, values) do diff --git a/test/support/fixtures/things_schema.ex b/test/support/fixtures/things/macro_schema.ex similarity index 98% rename from test/support/fixtures/things_schema.ex rename to test/support/fixtures/things/macro_schema.ex index bcbbe4ef21..ad79b0b1b7 100644 --- a/test/support/fixtures/things_schema.ex +++ b/test/support/fixtures/things/macro_schema.ex @@ -1,4 +1,4 @@ -defmodule Absinthe.Fixtures.ThingsSchema do +defmodule Absinthe.Fixtures.Things.MacroSchema do use Absinthe.Schema @db %{ diff --git a/test/support/fixtures/things/sdl_schema.ex b/test/support/fixtures/things/sdl_schema.ex new file mode 100644 index 0000000000..76c09582cd --- /dev/null +++ b/test/support/fixtures/things/sdl_schema.ex @@ -0,0 +1,102 @@ +defmodule Absinthe.Fixtures.Things.SDLSchema do + use Absinthe.Schema + + import_sdl """ + enum SigilsWork { + FOO + BAR + } + + enum SigilsWorkInside { + FOO + BAR + } + + enum FailureType { + MULTIPLE + WITH_CODE + WITHOUT_MESSAGE + MULTIPLE_WITH_CODE + MULTIPLE_WITHOUT_MESSAGE + } + + type RootMutationType { + updateThing(id: String!, thing: InputThing!): Thing + + failingThing(type: FailureType): Thing + } + + type RootQueryType { + version: String + + badResolution: Thing + + number(val: Int!): String + + thingByContext: Thing + + things: [Thing] + + thing( + "id of the thing" + id: String!, + + "This is a deprecated arg" + deprecatedArg: String @deprecate, + + "This is a non-null deprecated arg" + deprecatedNonNullArg: String! @deprecate, + + "This is a deprecated arg with a reason" + deprecatedArgWithReason: String @deprecate(reason: "reason"), + + "This is a non-null deprecated arg with a reason" + deprecatedNonNullArgWithReason: String! @deprecate(reason: "reason") + ): Thing + + deprecatedThing( + "id of the thing" + id: String! + ): Thing @deprecate + + deprecatedThingWithReason( + "id of the thing" + id: String! + ): Thing @deprecate(reason: "use `thing' instead") + } + + "A thing as input" + input InputThing { + value: Int + deprecatedField: String @deprecate, + deprecatedFieldWithReason: String @deprecate(reason: "reason") + deprecatedNonNullField: String! @deprecate + } + + "A thing" + type Thing { + fail( + "the id we want this field to fail on" + id: ID + ): ID + + "The ID of the thing" + id: String! + + "The name of the thing" + name: String + + "The value of the thing" + value: Int + + otherThing: Thing + } + + schema { + mutation: RootMutationType + query: RootQueryType + } + + """ + +end From b31d100fdedd6ce37b36f8f0b0e93f385ba4889f Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 17 May 2019 23:08:53 -0700 Subject: [PATCH 02/13] Use Absinthe.Case consistently --- test/absinthe/execution/subscription_test.exs | 68 +++++++++---------- .../execution/aliases/alias_test.exs | 2 +- .../execution/aliases/all_caps_alias_test.exs | 2 +- .../aliases/different_selection_sets_test.exs | 2 +- .../aliases/leading_underscore_test.exs | 2 +- .../execution/aliases/weird_test.exs | 2 +- .../execution/aliases/with_errors_test.exs | 2 +- .../integration/execution/context_test.exs | 2 +- .../execution/custom_types/basic_test.exs | 2 +- .../datetime/input_object_test.exs | 2 +- .../fragments/basic_root_type_test.exs | 2 +- .../execution/fragments/basic_test.exs | 2 +- .../fragments/introspection_test.exs | 2 +- .../execution/input_object_test.exs | 2 +- .../input_types/enum/literal_test.exs | 2 +- .../execution/input_types/id/literal_test.exs | 2 +- ...eral_to_element_of_type_list_of_T_test.exs | 2 +- ...lement_of_type_non_null_list_of_T_test.exs | 2 +- ...to_type_T_overrides_default_value_test.exs | 2 +- .../null/literal_to_type_list_of_T_test.exs | 2 +- .../null/literal_to_type_non_null_T_test.exs | 2 +- ...o_type_non_null_list_of_T_element_test.exs | 2 +- ...iteral_to_type_non_null_list_of_T_test.exs | 2 +- ...n_null_list_of_non_null_T_element_test.exs | 2 +- ..._type_non_null_list_of_non_null_T_test.exs | 2 +- ...to_type_T_overrides_default_value_test.exs | 2 +- .../null/variable_to_type_T_test.exs | 2 +- ...ariable_to_type_list_of_T_element_test.exs | 2 +- .../null/variable_to_type_list_of_T_test.exs | 2 +- .../null/variable_to_type_non_null_T_test.exs | 2 +- ...o_type_non_null_list_of_T_element_test.exs | 2 +- ...riable_to_type_non_null_list_of_T_test.exs | 2 +- ...n_null_list_of_non_null_T_element_test.exs | 2 +- ..._type_non_null_list_of_non_null_T_test.exs | 2 +- ...iable_to_variable_type_non_null_T_test.exs | 2 +- ...le_to_variable_with_default_value_test.exs | 2 +- .../introspection/default_value_enum_test.exs | 2 +- .../introspection/directives_test.exs | 2 +- .../execution/introspection/full_test.exs | 2 +- .../interface_typename_alias_test.exs | 2 +- .../introspection/interface_typename_test.exs | 2 +- .../introspection/mutation_type_test.exs | 2 +- .../object_typename_alias_test.exs | 2 +- .../introspection/object_typename_test.exs | 2 +- .../introspection/object_with_list_test.exs | 2 +- .../introspection/query_type_test.exs | 2 +- .../introspection/schema_types_test.exs | 2 +- .../introspection/subscription_type_test.exs | 2 +- .../introspection/type_interface_test.exs | 2 +- .../introspection/union_typename_test.exs | 2 +- .../union_wrapped_typename_test.exs | 2 +- .../execution/nested_objects_test.exs | 2 +- .../execution/operation_by_name_test.exs | 2 +- .../errors_include_path_indices_test.exs | 2 +- .../resolution/exceptions/bad_match_test.exs | 2 +- .../exceptions/missing_error_message_test.exs | 2 +- ...r_message_when_returning_multiple_test.exs | 2 +- .../resolution/extra_error_fields_test.exs | 2 +- .../resolution/multiple_errors_test.exs | 2 +- ...multiple_errors_with_extra_fields_test.exs | 2 +- .../integration/execution/root_value_test.exs | 2 +- .../simple_query_returning_list_test.exs | 2 +- .../execution/simple_query_test.exs | 2 +- .../integration/execution/telemetry_test.exs | 2 +- .../execution/variables/basic_test.exs | 2 +- .../variables/default_value_test.exs | 2 +- .../integration/parsing/basic_error_test.exs | 2 +- .../integration/validation/cycles_test.exs | 2 +- ...ror_result_when_bad_list_argument_test.exs | 2 +- .../validation/extra_arguments_test.exs | 2 +- ...n_fields_ignored_in_input_objects_test.exs | 2 +- .../validation/invalid_argument_test.exs | 2 +- .../validation/invalid_nested_type_test.exs | 2 +- .../validation/missing_operation_test.exs | 2 +- .../validation/missing_selection_set_test.exs | 2 +- .../object_spreads_in_object_scope_test.exs | 2 +- .../validation/required_arguments_test.exs | 2 +- ...unknown_arg_for_list_member_field_test.exs | 2 +- .../validation/unknown_field_test.exs | 2 +- .../unused/with_operation_name_test.exs | 2 +- .../unused/without_operation_name_test.exs | 2 +- test/absinthe/lexer_test.exs | 2 +- .../phase/execution/non_null_test.exs | 2 +- .../phase/schema/inline_functions_test.exs | 2 +- test/absinthe/resolution/projector_test.exs | 2 +- test/absinthe/resolution_test.exs | 2 +- test/absinthe/schema/notation/import_test.exs | 2 +- 87 files changed, 120 insertions(+), 120 deletions(-) diff --git a/test/absinthe/execution/subscription_test.exs b/test/absinthe/execution/subscription_test.exs index 83bdda1637..bf9b9b8286 100644 --- a/test/absinthe/execution/subscription_test.exs +++ b/test/absinthe/execution/subscription_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.Execution.SubscriptionTest do - use ExUnit.Case + use Absinthe.Case import ExUnit.CaptureLog @@ -159,7 +159,7 @@ defmodule Absinthe.Execution.SubscriptionTest do client_id = "abc" assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{"clientId" => client_id}, @@ -186,7 +186,7 @@ defmodule Absinthe.Execution.SubscriptionTest do client_id = "abc" assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{"clientId" => client_id}, @@ -207,7 +207,7 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "schema can provide multiple topics to subscribe to" do assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{}, @@ -240,7 +240,7 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "unsubscription works when multiple topics are provided" do assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{}, @@ -279,7 +279,7 @@ defmodule Absinthe.Execution.SubscriptionTest do } ] } - } == run(@query, Schema, variables: %{"clientId" => "abc"}, context: %{pubsub: PubSub}) + } == run_subscription(@query, Schema, variables: %{"clientId" => "abc"}, context: %{pubsub: PubSub}) end @query """ @@ -291,7 +291,7 @@ defmodule Absinthe.Execution.SubscriptionTest do id = "1" assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{"userId" => id}, @@ -305,7 +305,7 @@ defmodule Absinthe.Execution.SubscriptionTest do """ assert {:ok, %{data: _}} = - run(mutation, Schema, + run_subscription(mutation, Schema, variables: %{"userId" => id}, context: %{pubsub: PubSub} ) @@ -326,7 +326,7 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "can return an error tuple from the topic function" do assert {:ok, %{errors: [%{locations: [%{column: 3, line: 2}], message: "unauthorized"}]}} == - run( + run_subscription( @query, Schema, variables: %{"clientId" => "abc"}, @@ -340,7 +340,7 @@ defmodule Absinthe.Execution.SubscriptionTest do } """ test "topic function receives a document" do - assert {:ok, %{"subscribed" => _topic}} = run(@query, Schema, context: %{pubsub: PubSub}) + assert {:ok, %{"subscribed" => _topic}} = run_subscription(@query, Schema, context: %{pubsub: PubSub}) end @query """ @@ -350,7 +350,7 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "stringifies topics" do assert {:ok, %{"subscribed" => topic}} = - run(@query, Schema, variables: %{"clientId" => "1"}, context: %{pubsub: PubSub}) + run_subscription(@query, Schema, variables: %{"clientId" => "1"}, context: %{pubsub: PubSub}) Absinthe.Subscription.publish(PubSub, "foo", thing: 1) @@ -364,8 +364,8 @@ defmodule Absinthe.Execution.SubscriptionTest do end test "isn't tripped up if one of the subscription docs raises" do - assert {:ok, %{"subscribed" => _}} = run("subscription { raises }", Schema) - assert {:ok, %{"subscribed" => topic}} = run("subscription { thing(clientId: \"*\")}", Schema) + assert {:ok, %{"subscribed" => _}} = run_subscription("subscription { raises }", Schema) + assert {:ok, %{"subscribed" => topic}} = run_subscription("subscription { thing(clientId: \"*\")}", Schema) error_log = capture_log(fn -> @@ -387,11 +387,11 @@ defmodule Absinthe.Execution.SubscriptionTest do opts = [context: %{test_pid: self()}] assert {:ok, %{"subscribed" => doc1}} = - run("subscription { user { group { name } id} }", Schema, opts) + run_subscription("subscription { user { group { name } id} }", Schema, opts) # different docs required for test, otherwise they get deduplicated from the start assert {:ok, %{"subscribed" => doc2}} = - run("subscription { user { group { name } id name} }", Schema, opts) + run_subscription("subscription { user { group { name } id name} }", Schema, opts) user = %{id: "1", name: "Alicia", group: %{name: "Elixir Users"}} @@ -411,12 +411,12 @@ defmodule Absinthe.Execution.SubscriptionTest do ctx1 = %{test_pid: self(), user: 1} assert {:ok, %{"subscribed" => doc1}} = - run("subscription { user { group { name } id} }", Schema, context: ctx1) + run_subscription("subscription { user { group { name } id} }", Schema, context: ctx1) ctx2 = %{test_pid: self(), user: 2} # different docs required for test, otherwise they get deduplicated from the start assert {:ok, %{"subscribed" => doc2}} = - run("subscription { user { group { name } id name} }", Schema, context: ctx2) + run_subscription("subscription { user { group { name } id name} }", Schema, context: ctx2) user = %{id: "1", name: "Alicia", group: %{name: "Elixir Users"}} @@ -440,10 +440,10 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "subscriptions with the same context_id and same source document have the same subscription_id" do assert {:ok, %{"subscribed" => doc1}} = - run(@query, Schema, context: %{context_id: "logged-in"}) + run_subscription(@query, Schema, context: %{context_id: "logged-in"}) assert {:ok, %{"subscribed" => doc2}} = - run(@query, Schema, context: %{context_id: "logged-in"}) + run_subscription(@query, Schema, context: %{context_id: "logged-in"}) assert doc1 == doc2 end @@ -455,22 +455,22 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "subscriptions with different context_id but the same source document have different subscription_ids" do assert {:ok, %{"subscribed" => doc1}} = - run(@query, Schema, context: %{context_id: "logged-in"}) + run_subscription(@query, Schema, context: %{context_id: "logged-in"}) assert {:ok, %{"subscribed" => doc2}} = - run(@query, Schema, context: %{context_id: "not-logged-in"}) + run_subscription(@query, Schema, context: %{context_id: "not-logged-in"}) assert doc1 != doc2 end test "subscriptions with same context_id but different source document have different subscription_ids" do assert {:ok, %{"subscribed" => doc1}} = - run("subscription { otherUser { id name } }", Schema, + run_subscription("subscription { otherUser { id name } }", Schema, context: %{context_id: "logged-in"} ) assert {:ok, %{"subscribed" => doc2}} = - run("subscription { otherUser { id } }", Schema, + run_subscription("subscription { otherUser { id } }", Schema, context: %{context_id: "logged-in"} ) @@ -479,12 +479,12 @@ defmodule Absinthe.Execution.SubscriptionTest do test "subscriptions with different context_id and different source document have different subscription_ids" do assert {:ok, %{"subscribed" => doc1}} = - run("subscription { otherUser { id name } }", Schema, + run_subscription("subscription { otherUser { id name } }", Schema, context: %{context_id: "logged-in"} ) assert {:ok, %{"subscribed" => doc2}} = - run("subscription { otherUser { id } }", Schema, + run_subscription("subscription { otherUser { id } }", Schema, context: %{context_id: "not-logged-in"} ) @@ -496,13 +496,13 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "subscriptions with the same variables & document have the same subscription_ids" do assert {:ok, %{"subscribed" => doc1}} = - run(@query, Schema, + run_subscription(@query, Schema, variables: %{"id" => "123"}, context: %{context_id: "logged-in"} ) assert {:ok, %{"subscribed" => doc2}} = - run(@query, Schema, + run_subscription(@query, Schema, variables: %{"id" => "123"}, context: %{context_id: "logged-in"} ) @@ -515,13 +515,13 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "subscriptions with different variables but same document have different subscription_ids" do assert {:ok, %{"subscribed" => doc1}} = - run(@query, Schema, + run_subscription(@query, Schema, variables: %{"id" => "123"}, context: %{context_id: "logged-in"} ) assert {:ok, %{"subscribed" => doc2}} = - run(@query, Schema, + run_subscription(@query, Schema, variables: %{"id" => "456"}, context: %{context_id: "logged-in"} ) @@ -531,12 +531,12 @@ defmodule Absinthe.Execution.SubscriptionTest do test "document_id can be provided to override the default logic for deriving document_id" do assert {:ok, %{"subscribed" => doc1}} = - run("subscription { otherUser { id name } }", Schema, + run_subscription("subscription { otherUser { id name } }", Schema, context: %{context_id: "logged-in", document_id: "abcdef"} ) assert {:ok, %{"subscribed" => doc2}} = - run("subscription { otherUser { name id } }", Schema, + run_subscription("subscription { otherUser { name id } }", Schema, context: %{context_id: "logged-in", document_id: "abcdef"} ) @@ -567,7 +567,7 @@ defmodule Absinthe.Execution.SubscriptionTest do ) assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{"clientId" => client_id}, @@ -592,10 +592,10 @@ defmodule Absinthe.Execution.SubscriptionTest do :telemetry.detach(context.test) end - defp run(query, schema, opts \\ []) do + defp run_subscription(query, schema, opts \\ []) do opts = Keyword.update(opts, :context, %{pubsub: PubSub}, &Map.put(&1, :pubsub, PubSub)) - case Absinthe.run(query, schema, opts) do + case run(query, schema, opts) do {:ok, %{"subscribed" => topic}} = val -> PubSub.subscribe(topic) val diff --git a/test/absinthe/integration/execution/aliases/alias_test.exs b/test/absinthe/integration/execution/aliases/alias_test.exs index 2b2699e3cb..690010434f 100644 --- a/test/absinthe/integration/execution/aliases/alias_test.exs +++ b/test/absinthe/integration/execution/aliases/alias_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.AliasTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true # LEAVE ME diff --git a/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs b/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs index 68c8cd4618..5f982500ba 100644 --- a/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs +++ b/test/absinthe/integration/execution/aliases/all_caps_alias_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.AllCapsAliasTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs b/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs index d5db92838d..24038c9426 100644 --- a/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs +++ b/test/absinthe/integration/execution/aliases/different_selection_sets_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.DifferentSelectionSetsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/aliases/leading_underscore_test.exs b/test/absinthe/integration/execution/aliases/leading_underscore_test.exs index 4253e6c54d..7034865155 100644 --- a/test/absinthe/integration/execution/aliases/leading_underscore_test.exs +++ b/test/absinthe/integration/execution/aliases/leading_underscore_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.LeadingUnderscoreTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/aliases/weird_test.exs b/test/absinthe/integration/execution/aliases/weird_test.exs index 016868aa16..5ecd7ba435 100644 --- a/test/absinthe/integration/execution/aliases/weird_test.exs +++ b/test/absinthe/integration/execution/aliases/weird_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.WeirdTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/aliases/with_errors_test.exs b/test/absinthe/integration/execution/aliases/with_errors_test.exs index 414c5d1c41..f7f29fe849 100644 --- a/test/absinthe/integration/execution/aliases/with_errors_test.exs +++ b/test/absinthe/integration/execution/aliases/with_errors_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Aliases.WithErrorsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { foo: failingThing(type: WITH_CODE) { name } } diff --git a/test/absinthe/integration/execution/context_test.exs b/test/absinthe/integration/execution/context_test.exs index 3415407eff..62c76c4b6f 100644 --- a/test/absinthe/integration/execution/context_test.exs +++ b/test/absinthe/integration/execution/context_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.ContextTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/custom_types/basic_test.exs b/test/absinthe/integration/execution/custom_types/basic_test.exs index 0319c615a8..6e4bb8a67b 100644 --- a/test/absinthe/integration/execution/custom_types/basic_test.exs +++ b/test/absinthe/integration/execution/custom_types/basic_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.CustomTypes.BasicTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/custom_types/datetime/input_object_test.exs b/test/absinthe/integration/execution/custom_types/datetime/input_object_test.exs index af5ba07f13..a6be085f1f 100644 --- a/test/absinthe/integration/execution/custom_types/datetime/input_object_test.exs +++ b/test/absinthe/integration/execution/custom_types/datetime/input_object_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.CustomTypes.Datetime.InputObjectTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { diff --git a/test/absinthe/integration/execution/fragments/basic_root_type_test.exs b/test/absinthe/integration/execution/fragments/basic_root_type_test.exs index 3c38a7ed65..ea97aaf7cd 100644 --- a/test/absinthe/integration/execution/fragments/basic_root_type_test.exs +++ b/test/absinthe/integration/execution/fragments/basic_root_type_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Fragments.BasicRootTypeTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/fragments/basic_test.exs b/test/absinthe/integration/execution/fragments/basic_test.exs index 38a7e802ae..c749ae589b 100644 --- a/test/absinthe/integration/execution/fragments/basic_test.exs +++ b/test/absinthe/integration/execution/fragments/basic_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Fragments.BasicTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query Q { diff --git a/test/absinthe/integration/execution/fragments/introspection_test.exs b/test/absinthe/integration/execution/fragments/introspection_test.exs index 8e232380fa..2ac96c6f5e 100644 --- a/test/absinthe/integration/execution/fragments/introspection_test.exs +++ b/test/absinthe/integration/execution/fragments/introspection_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Fragments.IntrospectionTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query Q { diff --git a/test/absinthe/integration/execution/input_object_test.exs b/test/absinthe/integration/execution/input_object_test.exs index effbd5f873..f77ffb011d 100644 --- a/test/absinthe/integration/execution/input_object_test.exs +++ b/test/absinthe/integration/execution/input_object_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputObjectTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { diff --git a/test/absinthe/integration/execution/input_types/enum/literal_test.exs b/test/absinthe/integration/execution/input_types/enum/literal_test.exs index c6de7cd3aa..7e5e5201b2 100644 --- a/test/absinthe/integration/execution/input_types/enum/literal_test.exs +++ b/test/absinthe/integration/execution/input_types/enum/literal_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Enum.LiteralTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/id/literal_test.exs b/test/absinthe/integration/execution/input_types/id/literal_test.exs index 8698f5ee6a..5c5580d4d7 100644 --- a/test/absinthe/integration/execution/input_types/id/literal_test.exs +++ b/test/absinthe/integration/execution/input_types/id/literal_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Id.LiteralTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_list_of_T_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_list_of_T_test.exs index dab74a319b..1416a29404 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_list_of_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_list_of_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToElementOfTypeListOf_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_non_null_list_of_T_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_non_null_list_of_T_test.exs index 8da2a4f9f9..7d7d3df7ac 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_non_null_list_of_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_element_of_type_non_null_list_of_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToElementOfTypeNonNullListOf_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_T_overrides_default_value_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_T_overrides_default_value_test.exs index eae744ec8c..ad8a1f3cab 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_T_overrides_default_value_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_T_overrides_default_value_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToType_TOverridesDefaultValueTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_list_of_T_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_list_of_T_test.exs index 40681560a5..ca6f341631 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_list_of_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_list_of_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToTypeListOf_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_T_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_T_test.exs index 837d523698..9c66d551dd 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToTypeNonNull_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_element_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_element_test.exs index dbaf4f973d..c6ab3ed36b 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_element_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_element_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToTypeNonNullListOf_TElementTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_test.exs index 75af6cb877..f381ba57f7 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToTypeNonNullListOf_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_element_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_element_test.exs index 371a86e046..8f9f8289bf 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_element_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_element_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToTypeNonNullListOfNonNull_TElementTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_test.exs b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_test.exs index 051b76c312..12900cb313 100644 --- a/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/literal_to_type_non_null_list_of_non_null_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.LiteralToTypeNonNullListOfNonNull_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_T_overrides_default_value_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_T_overrides_default_value_test.exs index 38ed87b802..d836206b85 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_T_overrides_default_value_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_T_overrides_default_value_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToType_TOverridesDefaultValueTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($multiplier: Int) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_T_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_T_test.exs index 0126cfb528..aaf2f88d4f 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToType_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: Int) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_element_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_element_test.exs index a2da7076e7..4d529e9f86 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_element_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_element_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeListOf_TElementTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: [Int]) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_test.exs index 33f2fe00a0..9b63d6558e 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_list_of_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeListOf_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: [Int]) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_T_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_T_test.exs index 2c19f0ee85..03c9bf87b0 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeNonNull_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: Int!) { times: objTimes(input: {base: $value}) } diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_element_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_element_test.exs index 8bfc4f4f89..22058e908a 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_element_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_element_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeNonNullListOf_TElementTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: [Int!]) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_test.exs index 5e883cbd91..a9505ff521 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeNonNullListOf_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: [Int!]) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_element_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_element_test.exs index 671ea3ebef..d637361cf4 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_element_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_element_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeNonNullListOfNonNull_TElementTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: [Int!]!) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_test.exs index e21d47ebe0..3b7693bbd4 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_type_non_null_list_of_non_null_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToTypeNonNullListOfNonNull_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($value: [Int!]!) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_variable_type_non_null_T_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_variable_type_non_null_T_test.exs index f9655f919a..b23092c6fe 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_variable_type_non_null_T_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_variable_type_non_null_T_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToVariableTypeNonNull_TTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($mult: Int!) { diff --git a/test/absinthe/integration/execution/input_types/null/variable_to_variable_with_default_value_test.exs b/test/absinthe/integration/execution/input_types/null/variable_to_variable_with_default_value_test.exs index 43daf0e5a3..a6131d1c2b 100644 --- a/test/absinthe/integration/execution/input_types/null/variable_to_variable_with_default_value_test.exs +++ b/test/absinthe/integration/execution/input_types/null/variable_to_variable_with_default_value_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.InputTypes.Null.VariableToVariableWithDefaultValueTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($mult: Int = 6) { diff --git a/test/absinthe/integration/execution/introspection/default_value_enum_test.exs b/test/absinthe/integration/execution/introspection/default_value_enum_test.exs index 4c49f7c13d..adbbf09cd7 100644 --- a/test/absinthe/integration/execution/introspection/default_value_enum_test.exs +++ b/test/absinthe/integration/execution/introspection/default_value_enum_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.DefaultValueEnumTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/introspection/directives_test.exs b/test/absinthe/integration/execution/introspection/directives_test.exs index ea733b926e..99541cf42d 100644 --- a/test/absinthe/integration/execution/introspection/directives_test.exs +++ b/test/absinthe/integration/execution/introspection/directives_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.DirectivesTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/introspection/full_test.exs b/test/absinthe/integration/execution/introspection/full_test.exs index 0b58f1fcfd..d56eaedfc6 100644 --- a/test/absinthe/integration/execution/introspection/full_test.exs +++ b/test/absinthe/integration/execution/introspection/full_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.FullTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query IntrospectionQuery { diff --git a/test/absinthe/integration/execution/introspection/interface_typename_alias_test.exs b/test/absinthe/integration/execution/introspection/interface_typename_alias_test.exs index f9b0a329a4..494a937a08 100644 --- a/test/absinthe/integration/execution/introspection/interface_typename_alias_test.exs +++ b/test/absinthe/integration/execution/introspection/interface_typename_alias_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.InterfaceTypenameAliasTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { contact { entity { kind: __typename name } } } diff --git a/test/absinthe/integration/execution/introspection/interface_typename_test.exs b/test/absinthe/integration/execution/introspection/interface_typename_test.exs index 8dc73c5c91..a5d6e3bf9e 100644 --- a/test/absinthe/integration/execution/introspection/interface_typename_test.exs +++ b/test/absinthe/integration/execution/introspection/interface_typename_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.InterfaceTypenameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { contact { entity { __typename name } } } diff --git a/test/absinthe/integration/execution/introspection/mutation_type_test.exs b/test/absinthe/integration/execution/introspection/mutation_type_test.exs index f072ddf7a2..9dbf089d10 100644 --- a/test/absinthe/integration/execution/introspection/mutation_type_test.exs +++ b/test/absinthe/integration/execution/introspection/mutation_type_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.MutationTypeTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { __schema { mutationType { name kind } } } diff --git a/test/absinthe/integration/execution/introspection/object_typename_alias_test.exs b/test/absinthe/integration/execution/introspection/object_typename_alias_test.exs index 54a549001e..be207d5ec3 100644 --- a/test/absinthe/integration/execution/introspection/object_typename_alias_test.exs +++ b/test/absinthe/integration/execution/introspection/object_typename_alias_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.ObjectTypenameAliasTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/introspection/object_typename_test.exs b/test/absinthe/integration/execution/introspection/object_typename_test.exs index c99ad00dcd..43c26bf005 100644 --- a/test/absinthe/integration/execution/introspection/object_typename_test.exs +++ b/test/absinthe/integration/execution/introspection/object_typename_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.ObjectTypenameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/introspection/object_with_list_test.exs b/test/absinthe/integration/execution/introspection/object_with_list_test.exs index 38a3282487..e298274f45 100644 --- a/test/absinthe/integration/execution/introspection/object_with_list_test.exs +++ b/test/absinthe/integration/execution/introspection/object_with_list_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.ObjectWithListTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/introspection/query_type_test.exs b/test/absinthe/integration/execution/introspection/query_type_test.exs index 151ea23fb9..f9d9f5a7fd 100644 --- a/test/absinthe/integration/execution/introspection/query_type_test.exs +++ b/test/absinthe/integration/execution/introspection/query_type_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.QueryTypeTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { __schema { queryType { name kind } } } diff --git a/test/absinthe/integration/execution/introspection/schema_types_test.exs b/test/absinthe/integration/execution/introspection/schema_types_test.exs index 962d2550c7..cb3bc9a8e5 100644 --- a/test/absinthe/integration/execution/introspection/schema_types_test.exs +++ b/test/absinthe/integration/execution/introspection/schema_types_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.SchemaTypesTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { __schema { types { name } } } diff --git a/test/absinthe/integration/execution/introspection/subscription_type_test.exs b/test/absinthe/integration/execution/introspection/subscription_type_test.exs index 970a795b37..c97c3f2371 100644 --- a/test/absinthe/integration/execution/introspection/subscription_type_test.exs +++ b/test/absinthe/integration/execution/introspection/subscription_type_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.SubscriptionTypeTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { __schema { subscriptionType { name kind } } } diff --git a/test/absinthe/integration/execution/introspection/type_interface_test.exs b/test/absinthe/integration/execution/introspection/type_interface_test.exs index 1affad3066..8a59bdea91 100644 --- a/test/absinthe/integration/execution/introspection/type_interface_test.exs +++ b/test/absinthe/integration/execution/introspection/type_interface_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.TypeInterfaceTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/introspection/union_typename_test.exs b/test/absinthe/integration/execution/introspection/union_typename_test.exs index dc02660a04..b929bab632 100644 --- a/test/absinthe/integration/execution/introspection/union_typename_test.exs +++ b/test/absinthe/integration/execution/introspection/union_typename_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.UnionTypenameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { firstSearchResult { __typename } } diff --git a/test/absinthe/integration/execution/introspection/union_wrapped_typename_test.exs b/test/absinthe/integration/execution/introspection/union_wrapped_typename_test.exs index 76eea6c9d6..bd53d2998f 100644 --- a/test/absinthe/integration/execution/introspection/union_wrapped_typename_test.exs +++ b/test/absinthe/integration/execution/introspection/union_wrapped_typename_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Introspection.UnionWrappedTypenameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { searchResults { __typename } } diff --git a/test/absinthe/integration/execution/nested_objects_test.exs b/test/absinthe/integration/execution/nested_objects_test.exs index 7edc895023..d0bf5fc71d 100644 --- a/test/absinthe/integration/execution/nested_objects_test.exs +++ b/test/absinthe/integration/execution/nested_objects_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.NestedObjectsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/operation_by_name_test.exs b/test/absinthe/integration/execution/operation_by_name_test.exs index 52e5f1f31d..3cc7d612ec 100644 --- a/test/absinthe/integration/execution/operation_by_name_test.exs +++ b/test/absinthe/integration/execution/operation_by_name_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.OperationByNameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ThingFoo($id: ID!) { diff --git a/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs b/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs index 6bc1a1065f..bff30282c7 100644 --- a/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs +++ b/test/absinthe/integration/execution/resolution/errors_include_path_indices_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.ErrorsIncludePathIndicesTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs b/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs index ee9218bb9f..4d8261e2ef 100644 --- a/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs +++ b/test/absinthe/integration/execution/resolution/exceptions/bad_match_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.Exceptions.BadMatchTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs index a0f5af5b7d..d84944b65c 100644 --- a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs +++ b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.Exceptions.MissingErrorMessageTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { failingThing(type: WITHOUT_MESSAGE) { name } } diff --git a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs index 52cb3edb66..c9623c79eb 100644 --- a/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs +++ b/test/absinthe/integration/execution/resolution/exceptions/missing_error_message_when_returning_multiple_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.Exceptions.MissingErrorMessageWhenReturningMultipleTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { failingThing(type: MULTIPLE_WITHOUT_MESSAGE) { name } } diff --git a/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs b/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs index 09b3aae844..11da0d00a5 100644 --- a/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs +++ b/test/absinthe/integration/execution/resolution/extra_error_fields_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.ExtraErrorFieldsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { failingThing(type: WITH_CODE) { name } } diff --git a/test/absinthe/integration/execution/resolution/multiple_errors_test.exs b/test/absinthe/integration/execution/resolution/multiple_errors_test.exs index b0996b2487..fe1a1c66b6 100644 --- a/test/absinthe/integration/execution/resolution/multiple_errors_test.exs +++ b/test/absinthe/integration/execution/resolution/multiple_errors_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.MultipleErrorsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { failingThing(type: MULTIPLE) { name } } diff --git a/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs b/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs index c91be03918..bb897a356d 100644 --- a/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs +++ b/test/absinthe/integration/execution/resolution/multiple_errors_with_extra_fields_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Resolution.MultipleErrorsWithExtraFieldsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { failingThing(type: MULTIPLE_WITH_CODE) { name } } diff --git a/test/absinthe/integration/execution/root_value_test.exs b/test/absinthe/integration/execution/root_value_test.exs index 8b4f7c2b80..854f5eb725 100644 --- a/test/absinthe/integration/execution/root_value_test.exs +++ b/test/absinthe/integration/execution/root_value_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.RootValueTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { version } diff --git a/test/absinthe/integration/execution/simple_query_returning_list_test.exs b/test/absinthe/integration/execution/simple_query_returning_list_test.exs index cd1d460799..ffd7fd395e 100644 --- a/test/absinthe/integration/execution/simple_query_returning_list_test.exs +++ b/test/absinthe/integration/execution/simple_query_returning_list_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.SimpleQueryReturningListTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/execution/simple_query_test.exs b/test/absinthe/integration/execution/simple_query_test.exs index a839d56a08..67f801f772 100644 --- a/test/absinthe/integration/execution/simple_query_test.exs +++ b/test/absinthe/integration/execution/simple_query_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.SimpleQueryTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { thing(id: "foo") { name } } diff --git a/test/absinthe/integration/execution/telemetry_test.exs b/test/absinthe/integration/execution/telemetry_test.exs index e356976b3f..9a22357508 100644 --- a/test/absinthe/integration/execution/telemetry_test.exs +++ b/test/absinthe/integration/execution/telemetry_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.TelemetryTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true setup context do :telemetry.attach_many( diff --git a/test/absinthe/integration/execution/variables/basic_test.exs b/test/absinthe/integration/execution/variables/basic_test.exs index 658dcf6832..3dd6bbc83c 100644 --- a/test/absinthe/integration/execution/variables/basic_test.exs +++ b/test/absinthe/integration/execution/variables/basic_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Variables.BasicTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($thingId: String!) { diff --git a/test/absinthe/integration/execution/variables/default_value_test.exs b/test/absinthe/integration/execution/variables/default_value_test.exs index 1e21dbbe9c..a1cb4dd15a 100644 --- a/test/absinthe/integration/execution/variables/default_value_test.exs +++ b/test/absinthe/integration/execution/variables/default_value_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Execution.Variables.DefaultValueTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($mult: Int = 6) { diff --git a/test/absinthe/integration/parsing/basic_error_test.exs b/test/absinthe/integration/parsing/basic_error_test.exs index d48fad560a..5f2b26fc8e 100644 --- a/test/absinthe/integration/parsing/basic_error_test.exs +++ b/test/absinthe/integration/parsing/basic_error_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Parsing.BasicErrorTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ { diff --git a/test/absinthe/integration/validation/cycles_test.exs b/test/absinthe/integration/validation/cycles_test.exs index fd1af6d5ac..f97deccf8f 100644 --- a/test/absinthe/integration/validation/cycles_test.exs +++ b/test/absinthe/integration/validation/cycles_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.CyclesTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query Foo { diff --git a/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs b/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs index c0fd1dbfd4..ff47d2383b 100644 --- a/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs +++ b/test/absinthe/integration/validation/error_result_when_bad_list_argument_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.ErrorResultWhenBadListArgumentTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/validation/extra_arguments_test.exs b/test/absinthe/integration/validation/extra_arguments_test.exs index aff0b3ed7b..7bedcbdf54 100644 --- a/test/absinthe/integration/validation/extra_arguments_test.exs +++ b/test/absinthe/integration/validation/extra_arguments_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.ExtraArgumentsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs b/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs index 031f997916..d2c9e4964f 100644 --- a/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs +++ b/test/absinthe/integration/validation/introspection_fields_ignored_in_input_objects_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.IntrospectionFieldsIgnoredInInputObjectsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation ($input: InputThing) { diff --git a/test/absinthe/integration/validation/invalid_argument_test.exs b/test/absinthe/integration/validation/invalid_argument_test.exs index 5673c5fe58..5c8ee9230c 100644 --- a/test/absinthe/integration/validation/invalid_argument_test.exs +++ b/test/absinthe/integration/validation/invalid_argument_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.InvalidArgumentTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { number(val: "AAA") } diff --git a/test/absinthe/integration/validation/invalid_nested_type_test.exs b/test/absinthe/integration/validation/invalid_nested_type_test.exs index 2de5c1ef19..b74993c237 100644 --- a/test/absinthe/integration/validation/invalid_nested_type_test.exs +++ b/test/absinthe/integration/validation/invalid_nested_type_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.InvalidNestedTypeTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation UpdateThingValueBadly { diff --git a/test/absinthe/integration/validation/missing_operation_test.exs b/test/absinthe/integration/validation/missing_operation_test.exs index 64221f2ca6..ece2fb7067 100644 --- a/test/absinthe/integration/validation/missing_operation_test.exs +++ b/test/absinthe/integration/validation/missing_operation_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.MissingOperationTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ mutation { foo } diff --git a/test/absinthe/integration/validation/missing_selection_set_test.exs b/test/absinthe/integration/validation/missing_selection_set_test.exs index 116813d9d1..9943d65007 100644 --- a/test/absinthe/integration/validation/missing_selection_set_test.exs +++ b/test/absinthe/integration/validation/missing_selection_set_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.MissingSelectionSetTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/validation/object_spreads_in_object_scope_test.exs b/test/absinthe/integration/validation/object_spreads_in_object_scope_test.exs index 487d67e5fb..df31810687 100644 --- a/test/absinthe/integration/validation/object_spreads_in_object_scope_test.exs +++ b/test/absinthe/integration/validation/object_spreads_in_object_scope_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.ObjectSpreadsInObjectScopeTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query Q { diff --git a/test/absinthe/integration/validation/required_arguments_test.exs b/test/absinthe/integration/validation/required_arguments_test.exs index accdb95a73..027ba81887 100644 --- a/test/absinthe/integration/validation/required_arguments_test.exs +++ b/test/absinthe/integration/validation/required_arguments_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.RequiredArgumentsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { thing { name } } diff --git a/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs b/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs index 7c795eb86e..09b4b8da68 100644 --- a/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs +++ b/test/absinthe/integration/validation/unknown_arg_for_list_member_field_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.UnknownArgForListMemberFieldTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query { diff --git a/test/absinthe/integration/validation/unknown_field_test.exs b/test/absinthe/integration/validation/unknown_field_test.exs index 343a7e76b7..44c7858a46 100644 --- a/test/absinthe/integration/validation/unknown_field_test.exs +++ b/test/absinthe/integration/validation/unknown_field_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.UnknownFieldTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ { diff --git a/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs b/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs index d10d53d9b5..ae3923d6b4 100644 --- a/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs +++ b/test/absinthe/integration/validation/variables/unused/with_operation_name_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.Variables.Unused.WithOperationNameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query AnOperationName($test: String) { diff --git a/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs b/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs index 05c2e34cd9..ee828007c5 100644 --- a/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs +++ b/test/absinthe/integration/validation/variables/unused/without_operation_name_test.exs @@ -1,5 +1,5 @@ defmodule Elixir.Absinthe.Integration.Validation.Variables.Unused.WithoutOperationNameTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ query ($test: String) { diff --git a/test/absinthe/lexer_test.exs b/test/absinthe/lexer_test.exs index 0f67d286a1..a38f72f32b 100644 --- a/test/absinthe/lexer_test.exs +++ b/test/absinthe/lexer_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.LexerTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true @query """ { foo } diff --git a/test/absinthe/phase/execution/non_null_test.exs b/test/absinthe/phase/execution/non_null_test.exs index 162954b1b9..306a59c14f 100644 --- a/test/absinthe/phase/execution/non_null_test.exs +++ b/test/absinthe/phase/execution/non_null_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.Phase.Document.Execution.NonNullTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true defmodule Schema do use Absinthe.Schema diff --git a/test/absinthe/phase/schema/inline_functions_test.exs b/test/absinthe/phase/schema/inline_functions_test.exs index 437260b7ea..fee2459eba 100644 --- a/test/absinthe/phase/schema/inline_functions_test.exs +++ b/test/absinthe/phase/schema/inline_functions_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.Phase.Schema.InlineFunctionsTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true defmodule Schema do use Absinthe.Schema.Notation diff --git a/test/absinthe/resolution/projector_test.exs b/test/absinthe/resolution/projector_test.exs index 4b50e4222e..6c7acd956e 100644 --- a/test/absinthe/resolution/projector_test.exs +++ b/test/absinthe/resolution/projector_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.Resolution.ProjectorTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true # describe "merging" do # test "asdf" diff --git a/test/absinthe/resolution_test.exs b/test/absinthe/resolution_test.exs index aa56bc5ccf..d1674f8319 100644 --- a/test/absinthe/resolution_test.exs +++ b/test/absinthe/resolution_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.ResolutionTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true defmodule Schema do use Absinthe.Schema diff --git a/test/absinthe/schema/notation/import_test.exs b/test/absinthe/schema/notation/import_test.exs index 8c40496b46..acf3d4e351 100644 --- a/test/absinthe/schema/notation/import_test.exs +++ b/test/absinthe/schema/notation/import_test.exs @@ -1,5 +1,5 @@ defmodule Absinthe.Schema.Notation.ImportTest do - use ExUnit.Case, async: true + use Absinthe.Case, async: true defp field_list(module, name) do module.__absinthe_type__(name).fields From 337a5d80f9efa0911ab1475ea7eeec7c0fe9b750 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Sat, 18 May 2019 01:00:18 -0700 Subject: [PATCH 03/13] Start work on schema directives --- lib/absinthe/blueprint/directive.ex | 8 +- .../validation/known_directives.ex | 2 +- .../schema/validation/known_directives.ex | 82 +++++++++++++++++++ lib/absinthe/pipeline.ex | 5 +- lib/absinthe/schema/notation/sdl.ex | 17 ++-- .../execution/variables/basic_test.exs | 7 -- .../validation/known_directives_test.exs | 4 +- test/support/case.ex | 1 + .../case/helpers/schema_implemantions.ex | 10 +++ 9 files changed, 116 insertions(+), 20 deletions(-) rename lib/absinthe/phase/{ => document}/validation/known_directives.ex (96%) create mode 100644 lib/absinthe/phase/schema/validation/known_directives.ex rename test/absinthe/phase/{ => document}/validation/known_directives_test.exs (97%) create mode 100644 test/support/case/helpers/schema_implemantions.ex diff --git a/lib/absinthe/blueprint/directive.ex b/lib/absinthe/blueprint/directive.ex index daf8247dd6..0b2de4d08c 100644 --- a/lib/absinthe/blueprint/directive.ex +++ b/lib/absinthe/blueprint/directive.ex @@ -12,7 +12,9 @@ defmodule Absinthe.Blueprint.Directive do # Added by phases schema_node: nil, flags: %{}, - errors: [] + errors: [], + __reference__: nil, + __private__: [] ] @type t :: %__MODULE__{ @@ -21,7 +23,9 @@ defmodule Absinthe.Blueprint.Directive do source_location: nil | Blueprint.SourceLocation.t(), schema_node: nil | Absinthe.Type.Directive.t(), flags: Blueprint.flags_t(), - errors: [Phase.Error.t()] + errors: [Phase.Error.t()], + __reference__: nil, + __private__: [] } @spec expand(t, Blueprint.node_t()) :: {t, map} diff --git a/lib/absinthe/phase/validation/known_directives.ex b/lib/absinthe/phase/document/validation/known_directives.ex similarity index 96% rename from lib/absinthe/phase/validation/known_directives.ex rename to lib/absinthe/phase/document/validation/known_directives.ex index ecbd41fb5e..889038a8f6 100644 --- a/lib/absinthe/phase/validation/known_directives.ex +++ b/lib/absinthe/phase/document/validation/known_directives.ex @@ -1,4 +1,4 @@ -defmodule Absinthe.Phase.Validation.KnownDirectives do +defmodule Absinthe.Phase.Document.Validation.KnownDirectives do @moduledoc false alias Absinthe.{Blueprint, Phase} diff --git a/lib/absinthe/phase/schema/validation/known_directives.ex b/lib/absinthe/phase/schema/validation/known_directives.ex new file mode 100644 index 0000000000..40144a2c74 --- /dev/null +++ b/lib/absinthe/phase/schema/validation/known_directives.ex @@ -0,0 +1,82 @@ +defmodule Absinthe.Phase.Schema.Validation.KnownDirectives do + @moduledoc false + + alias Absinthe.{Blueprint, Phase} + + use Absinthe.Phase + use Absinthe.Phase.Validation + + @doc """ + Run the validation. + """ + @spec run(Blueprint.t(), Keyword.t()) :: Phase.result_t() + def run(input, _options \\ []) do + result = Blueprint.postwalk(input, &handle_node/1) + {:ok, result} + end + + defp handle_node(%Blueprint.Directive{schema_node: nil} = node) do + node + |> put_error(error_unknown(node)) + end + + defp handle_node(%Blueprint.Directive{} = node) do + node + end + + defp handle_node(%{directives: []} = node) do + node + end + + defp handle_node(%{directives: _} = node) do + node + |> check_directives + |> inherit_invalid(node.directives, :bad_directive) + end + + defp handle_node(node) do + node + end + + defp check_directives(node) do + placement = Blueprint.Directive.placement(node) + + directives = + for directive <- node.directives do + if directive.schema_node do + if placement in directive.schema_node.locations do + directive + else + directive + |> put_error(error_misplaced(directive, placement)) + |> flag_invalid(:bad_placement) + end + else + directive + end + end + + %{node | directives: directives} + end + + # Generate the error for the node + @spec error_unknown(Blueprint.node_t()) :: Phase.Error.t() + defp error_unknown(node) do + %Phase.Error{ + phase: __MODULE__, + message: "Unknown directive `#{node.name}'.", + locations: [node.__reference__.location] + } + end + + @spec error_misplaced(Blueprint.node_t(), atom) :: Phase.Error.t() + defp error_misplaced(node, placement) do + placement_name = placement |> to_string |> String.upcase() + + %Phase.Error{ + phase: __MODULE__, + message: "May not be used on #{placement_name}.", + locations: [node.__reference__.location] + } + end +end diff --git a/lib/absinthe/pipeline.ex b/lib/absinthe/pipeline.ex index 13e69bdcd0..fe7af6a280 100644 --- a/lib/absinthe/pipeline.ex +++ b/lib/absinthe/pipeline.ex @@ -83,7 +83,7 @@ defmodule Absinthe.Pipeline do Phase.Document.MissingLiterals, Phase.Document.Arguments.FlagInvalid, # Validate Full Document - Phase.Validation.KnownDirectives, + Phase.Document.Validation.KnownDirectives, Phase.Document.Validation.ScalarLeafs, Phase.Document.Validation.VariablesAreInputTypes, Phase.Document.Validation.ArgumentsOfCorrectType, @@ -128,8 +128,7 @@ defmodule Absinthe.Pipeline do Phase.Schema.Validation.NoCircularFieldImports, Phase.Schema.Validation.Result, Phase.Schema.FieldImports, - # This will be needed eventually to support directives - # {Phase.Schema, [schema: schema]}, + Phase.Schema.Validation.KnownDirectives, Phase.Schema.Validation.DefaultEnumValuePresent, Phase.Schema.Validation.InputOuputTypesCorrectlyPlaced, Phase.Schema.Validation.InterfacesMustResolveTypes, diff --git a/lib/absinthe/schema/notation/sdl.ex b/lib/absinthe/schema/notation/sdl.ex index 2921895d43..c89e53acbb 100644 --- a/lib/absinthe/schema/notation/sdl.ex +++ b/lib/absinthe/schema/notation/sdl.ex @@ -5,6 +5,8 @@ defmodule Absinthe.Schema.Notation.SDL do Parse definitions from SDL source """ + alias Absinthe.Blueprint + @spec parse(sdl :: String.t(), module(), map(), Keyword.t()) :: {:ok, [Absinthe.Blueprint.Schema.type_t()]} | {:error, String.t()} def parse(sdl, module, ref, opts) do @@ -13,6 +15,7 @@ defmodule Absinthe.Schema.Notation.SDL do doc.input.definitions |> Enum.map(&Absinthe.Blueprint.Draft.convert(&1, doc)) |> Enum.map(&put_ref(&1, ref, opts)) + |> IO.inspect |> Enum.map(fn type -> %{type | module: module} end) {:ok, definitions} @@ -35,27 +38,31 @@ defmodule Absinthe.Schema.Notation.SDL do |> do_put_ref(ref, opts) end + defp put_ref(%{arguments: args, directives: directives} = node, ref, opts) do + %{node | arguments: Enum.map(args, &put_ref(&1, ref, opts)), directives: Enum.map(directives, &put_ref(&1, ref, opts))} + |> do_put_ref(ref, opts) + end + defp put_ref(%{arguments: args} = node, ref, opts) do %{node | arguments: Enum.map(args, &put_ref(&1, ref, opts))} |> do_put_ref(ref, opts) end - defp put_ref(%{directives: dirs} = node, ref, opts) do - %{node | directives: Enum.map(dirs, &put_ref(&1, ref, opts))} + defp put_ref(%{directives: directives} = node, ref, opts) do + %{node | directives: Enum.map(directives, &put_ref(&1, ref, opts))} |> do_put_ref(ref, opts) end defp put_ref(node, ref, opts), do: do_put_ref(node, ref, opts) - defp do_put_ref(%_{__reference__: nil} = node, ref, opts) do - + defp do_put_ref(%{__reference__: nil} = node, ref, opts) do ref = case opts[:path] do nil -> ref path -> - put_in(ref.location, %{file: {:unquote, [], [path]}, line: node.source_location.line}) + put_in(ref.location, %{file: {:unquote, [], [path]}, line: node.source_location.line, column: node.source_location.column}) end %{node | __reference__: ref} diff --git a/test/absinthe/integration/execution/variables/basic_test.exs b/test/absinthe/integration/execution/variables/basic_test.exs index 3dd6bbc83c..82664b82dd 100644 --- a/test/absinthe/integration/execution/variables/basic_test.exs +++ b/test/absinthe/integration/execution/variables/basic_test.exs @@ -20,11 +20,4 @@ defmodule Elixir.Absinthe.Integration.Execution.Variables.BasicTest do end end - defp schema_implementations(base) do - [ - Module.safe_concat(base, MacroSchema), - Module.safe_concat(base, SDLSchema) - ] - end - end diff --git a/test/absinthe/phase/validation/known_directives_test.exs b/test/absinthe/phase/document/validation/known_directives_test.exs similarity index 97% rename from test/absinthe/phase/validation/known_directives_test.exs rename to test/absinthe/phase/document/validation/known_directives_test.exs index a5a7f66768..4553680814 100644 --- a/test/absinthe/phase/validation/known_directives_test.exs +++ b/test/absinthe/phase/document/validation/known_directives_test.exs @@ -1,5 +1,5 @@ -defmodule Absinthe.Phase.Validation.KnownDirectivesTest do - @phase Absinthe.Phase.Validation.KnownDirectives +defmodule Absinthe.Phase.Document.Validation.KnownDirectivesTest do + @phase Absinthe.Phase.Document.Validation.KnownDirectives use Absinthe.ValidationPhaseCase, phase: @phase, diff --git a/test/support/case.ex b/test/support/case.ex index 36d02657c9..0d453a39fc 100644 --- a/test/support/case.ex +++ b/test/support/case.ex @@ -2,6 +2,7 @@ defmodule Absinthe.Case do defmacro __using__(opts) do quote do use ExUnit.Case, unquote(opts) + import Absinthe.Case.Helpers.SchemaImplementations import Absinthe.Case.Helpers.Run import Absinthe.Case.Assertions.Result import Absinthe.Case.Assertions.Schema diff --git a/test/support/case/helpers/schema_implemantions.ex b/test/support/case/helpers/schema_implemantions.ex new file mode 100644 index 0000000000..dbac12d2af --- /dev/null +++ b/test/support/case/helpers/schema_implemantions.ex @@ -0,0 +1,10 @@ +defmodule Absinthe.Case.Helpers.SchemaImplementations do + + def schema_implementations(module) do + [ + Module.safe_concat(module, MacroSchema), + Module.safe_concat(module, SDLSchema) + ] + end + +end From d4bc43a422923e887aadc58ebbd39fd428a0e822 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Sun, 19 May 2019 16:39:28 -0700 Subject: [PATCH 04/13] Extensible SDL directives --- lib/absinthe/blueprint/directive.ex | 1 + .../document/validation/known_directives.ex | 4 +- .../phase/schema/attach_directives.ex | 51 +++++++++++++++++++ lib/absinthe/phase/schema/directives.ex | 46 +++++++++++++++++ .../schema/validation/known_directives.ex | 2 +- lib/absinthe/pipeline.ex | 1 + lib/absinthe/schema.ex | 7 ++- lib/absinthe/schema/notation/sdl.ex | 6 ++- .../validation/known_directives_test.exs | 4 +- .../notation/experimental/import_sdl_test.exs | 4 ++ test/support/fixtures/things/sdl_schema.ex | 18 +++---- 11 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 lib/absinthe/phase/schema/attach_directives.ex create mode 100644 lib/absinthe/phase/schema/directives.ex diff --git a/lib/absinthe/blueprint/directive.ex b/lib/absinthe/blueprint/directive.ex index 0b2de4d08c..c9f2d1f84b 100644 --- a/lib/absinthe/blueprint/directive.ex +++ b/lib/absinthe/blueprint/directive.ex @@ -18,6 +18,7 @@ defmodule Absinthe.Blueprint.Directive do ] @type t :: %__MODULE__{ + name: String.t(), arguments: [Blueprint.Input.Argument.t()], source_location: nil | Blueprint.SourceLocation.t(), diff --git a/lib/absinthe/phase/document/validation/known_directives.ex b/lib/absinthe/phase/document/validation/known_directives.ex index 889038a8f6..f1934afc6b 100644 --- a/lib/absinthe/phase/document/validation/known_directives.ex +++ b/lib/absinthe/phase/document/validation/known_directives.ex @@ -64,7 +64,7 @@ defmodule Absinthe.Phase.Document.Validation.KnownDirectives do defp error_unknown(node) do %Phase.Error{ phase: __MODULE__, - message: "Unknown directive.", + message: "Unknown directive `#{node.name}'.", locations: [node.source_location] } end @@ -75,7 +75,7 @@ defmodule Absinthe.Phase.Document.Validation.KnownDirectives do %Phase.Error{ phase: __MODULE__, - message: "May not be used on #{placement_name}.", + message: "Directive `#{node.name}' may not be used on #{placement_name}.", locations: [node.source_location] } end diff --git a/lib/absinthe/phase/schema/attach_directives.ex b/lib/absinthe/phase/schema/attach_directives.ex new file mode 100644 index 0000000000..5a9fd45f69 --- /dev/null +++ b/lib/absinthe/phase/schema/attach_directives.ex @@ -0,0 +1,51 @@ +defmodule Absinthe.Phase.Schema.AttachDirectives do + @moduledoc false + + # Expand all directives in the document. + # + # Note that no validation occurs in this phase. + + use Absinthe.Phase + alias Absinthe.Blueprint + + @spec run(Blueprint.t(), Keyword.t()) :: {:ok, Blueprint.t()} + def run(input, _options \\ []) do + node = Blueprint.prewalk(input, &(handle_node(&1, input.schema))) + {:ok, node} + end + + @spec handle_node(node :: Blueprint.Directive.t(), schema :: Absinthe.Schema.t()) :: Blueprint.Directive.t() + defp handle_node(%Blueprint.Directive{} = node, schema) do + schema_node = + Enum.find(available_directives(schema), &(&1.name == node.name)) + %{node | schema_node: schema_node} + end + + @spec handle_node(node :: Blueprint.node_t(), schema :: Absinthe.Schema.t()) :: Blueprint.node_t() + defp handle_node(node, _schema) do + node + end + + defp available_directives(schema) do + schema.sdl_directives(builtins()) + end + + def builtins do + [ + %Absinthe.Type.Directive{ + name: "deprecated", + locations: [:field_definition, :input_field_definition, :argument_definition], + expand: &expand_deprecate/2 + } + ] + end + + @doc """ + Add a deprecation (with an optional reason) to a node. + """ + @spec expand_deprecate(arguments :: %{optional(:reason) => String.t()}, node :: Blueprint.node_t()) :: Blueprint.node_t() + def expand_deprecate(arguments, node) do + %{node | deprecation: %Absinthe.Type.Deprecation{reason: arguments[:reason]}} + end + +end diff --git a/lib/absinthe/phase/schema/directives.ex b/lib/absinthe/phase/schema/directives.ex new file mode 100644 index 0000000000..b7142becb4 --- /dev/null +++ b/lib/absinthe/phase/schema/directives.ex @@ -0,0 +1,46 @@ +defmodule Absinthe.Phase.Schema.Directives do + @moduledoc false + + # Expand all directives in the document. + # + # Note that no validation occurs in this phase. + + use Absinthe.Phase + alias Absinthe.Blueprint + + @spec run(Blueprint.t(), Keyword.t()) :: {:ok, Blueprint.t()} + def run(input, _options \\ []) do + node = Blueprint.prewalk(input, &handle_node/1) + {:ok, node} + end + + @spec handle_node(Blueprint.node_t()) :: Blueprint.node_t() + defp handle_node(%{directives: directives} = node) do + Enum.reduce(directives, node, fn directive, acc -> + Blueprint.Directive.expand(directive, acc) + end) + end + + defp handle_node(node) do + node + end + + def available_directives do + [ + %Absinthe.Type.Directive{ + name: "deprecated", + locations: [:field_definition, :input_field_definition, :argument_definition], + expand: {:ref, __MODULE__, :expand_deprecate} + } + ] + end + + @doc """ + Add a deprecation (with an optional reason) to a node. + """ + @spec expand_deprecate(arguments :: %{optional(:reason) => String.t()}, node :: Blueprint.node_t()) :: Blueprint.node_t() + def expand_deprecate(arguments, node) do + %{node | deprecation: %Absinthe.Type.Deprecation{reason: arguments[:reason]}} + end + +end diff --git a/lib/absinthe/phase/schema/validation/known_directives.ex b/lib/absinthe/phase/schema/validation/known_directives.ex index 40144a2c74..23a0bb2d5a 100644 --- a/lib/absinthe/phase/schema/validation/known_directives.ex +++ b/lib/absinthe/phase/schema/validation/known_directives.ex @@ -75,7 +75,7 @@ defmodule Absinthe.Phase.Schema.Validation.KnownDirectives do %Phase.Error{ phase: __MODULE__, - message: "May not be used on #{placement_name}.", + message: "Directive `#{node.name}' may not be used on #{placement_name}.", locations: [node.__reference__.location] } end diff --git a/lib/absinthe/pipeline.ex b/lib/absinthe/pipeline.ex index fe7af6a280..2c47e21f64 100644 --- a/lib/absinthe/pipeline.ex +++ b/lib/absinthe/pipeline.ex @@ -128,6 +128,7 @@ defmodule Absinthe.Pipeline do Phase.Schema.Validation.NoCircularFieldImports, Phase.Schema.Validation.Result, Phase.Schema.FieldImports, + Phase.Schema.AttachDirectives, Phase.Schema.Validation.KnownDirectives, Phase.Schema.Validation.DefaultEnumValuePresent, Phase.Schema.Validation.InputOuputTypesCorrectlyPlaced, diff --git a/lib/absinthe/schema.ex b/lib/absinthe/schema.ex index dba438d097..ef90055a31 100644 --- a/lib/absinthe/schema.ex +++ b/lib/absinthe/schema.ex @@ -134,7 +134,12 @@ defmodule Absinthe.Schema do [] end - defoverridable(context: 1, middleware: 3, plugins: 0, decorations: 2) + @doc false + def sdl_directives(directives) do + directives + end + + defoverridable(context: 1, middleware: 3, plugins: 0, decorations: 2, sdl_directives: 1) end end diff --git a/lib/absinthe/schema/notation/sdl.ex b/lib/absinthe/schema/notation/sdl.ex index c89e53acbb..a4961d583f 100644 --- a/lib/absinthe/schema/notation/sdl.ex +++ b/lib/absinthe/schema/notation/sdl.ex @@ -15,7 +15,6 @@ defmodule Absinthe.Schema.Notation.SDL do doc.input.definitions |> Enum.map(&Absinthe.Blueprint.Draft.convert(&1, doc)) |> Enum.map(&put_ref(&1, ref, opts)) - |> IO.inspect |> Enum.map(fn type -> %{type | module: module} end) {:ok, definitions} @@ -33,6 +32,11 @@ defmodule Absinthe.Schema.Notation.SDL do end end + defp put_ref(%{fields: fields, directives: directives} = node, ref, opts) do + %{node | fields: Enum.map(fields, &put_ref(&1, ref, opts)), directives: Enum.map(directives, &put_ref(&1, ref, opts))} + |> do_put_ref(ref, opts) + end + defp put_ref(%{fields: fields} = node, ref, opts) do %{node | fields: Enum.map(fields, &put_ref(&1, ref, opts))} |> do_put_ref(ref, opts) diff --git a/test/absinthe/phase/document/validation/known_directives_test.exs b/test/absinthe/phase/document/validation/known_directives_test.exs index 4553680814..f20ce5782e 100644 --- a/test/absinthe/phase/document/validation/known_directives_test.exs +++ b/test/absinthe/phase/document/validation/known_directives_test.exs @@ -10,7 +10,7 @@ defmodule Absinthe.Phase.Document.Validation.KnownDirectivesTest do def unknown_directive(name, line) do bad_value( Blueprint.Directive, - "Unknown directive.", + "Unknown directive `#{name}'.", line, name: name ) @@ -19,7 +19,7 @@ defmodule Absinthe.Phase.Document.Validation.KnownDirectivesTest do def misplaced_directive(name, placement, line) do bad_value( Blueprint.Directive, - "May not be used on #{placement}.", + "Directive `#{name}' may not be used on #{placement}.", line, name: name ) diff --git a/test/absinthe/schema/notation/experimental/import_sdl_test.exs b/test/absinthe/schema/notation/experimental/import_sdl_test.exs index b63ec3c156..33a75f60f0 100644 --- a/test/absinthe/schema/notation/experimental/import_sdl_test.exs +++ b/test/absinthe/schema/notation/experimental/import_sdl_test.exs @@ -58,6 +58,10 @@ defmodule Absinthe.Schema.Notation.Experimental.ImportSdlTest do import_sdl path: "test/support/fixtures/import_sdl_path_option.graphql" import_sdl path: Path.join("test/support", "fixtures/import_sdl_path_option_fn.graphql") + def sdl_directives(builtins) do + [%Absinthe.Type.Directive{name: "feature", locations: [:interface]} | builtins] + end + def get_posts(_, _, _) do posts = [ %{title: "Foo", body: "A body.", author: %{name: "Bruce"}}, diff --git a/test/support/fixtures/things/sdl_schema.ex b/test/support/fixtures/things/sdl_schema.ex index 76c09582cd..58e1321ab1 100644 --- a/test/support/fixtures/things/sdl_schema.ex +++ b/test/support/fixtures/things/sdl_schema.ex @@ -42,35 +42,35 @@ defmodule Absinthe.Fixtures.Things.SDLSchema do id: String!, "This is a deprecated arg" - deprecatedArg: String @deprecate, + deprecatedArg: String @deprecated, "This is a non-null deprecated arg" - deprecatedNonNullArg: String! @deprecate, + deprecatedNonNullArg: String! @deprecated, "This is a deprecated arg with a reason" - deprecatedArgWithReason: String @deprecate(reason: "reason"), + deprecatedArgWithReason: String @deprecated(reason: "reason"), "This is a non-null deprecated arg with a reason" - deprecatedNonNullArgWithReason: String! @deprecate(reason: "reason") + deprecatedNonNullArgWithReason: String! @deprecated(reason: "reason") ): Thing deprecatedThing( "id of the thing" id: String! - ): Thing @deprecate + ): Thing @deprecated deprecatedThingWithReason( "id of the thing" id: String! - ): Thing @deprecate(reason: "use `thing' instead") + ): Thing @deprecated(reason: "use `thing' instead") } "A thing as input" input InputThing { value: Int - deprecatedField: String @deprecate, - deprecatedFieldWithReason: String @deprecate(reason: "reason") - deprecatedNonNullField: String! @deprecate + deprecatedField: String @deprecated, + deprecatedFieldWithReason: String @deprecated(reason: "reason") + deprecatedNonNullField: String! @deprecated } "A thing" From d21bab4292ff2e2fff5ecde6a65a0bfdbbb993bb Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Mon, 20 May 2019 14:23:44 -0700 Subject: [PATCH 05/13] Expand schema directives --- lib/absinthe/pipeline.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/absinthe/pipeline.ex b/lib/absinthe/pipeline.ex index 2c47e21f64..d65be0b968 100644 --- a/lib/absinthe/pipeline.ex +++ b/lib/absinthe/pipeline.ex @@ -130,6 +130,7 @@ defmodule Absinthe.Pipeline do Phase.Schema.FieldImports, Phase.Schema.AttachDirectives, Phase.Schema.Validation.KnownDirectives, + Phase.Schema.Directives, Phase.Schema.Validation.DefaultEnumValuePresent, Phase.Schema.Validation.InputOuputTypesCorrectlyPlaced, Phase.Schema.Validation.InterfacesMustResolveTypes, From a4abe6c2533aa047a89b55d6b39d4391aba2143c Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Mon, 20 May 2019 14:49:36 -0700 Subject: [PATCH 06/13] Add resolvers to SDL schema --- test/support/fixtures/things/sdl_schema.ex | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/support/fixtures/things/sdl_schema.ex b/test/support/fixtures/things/sdl_schema.ex index 58e1321ab1..4f8cc446c3 100644 --- a/test/support/fixtures/things/sdl_schema.ex +++ b/test/support/fixtures/things/sdl_schema.ex @@ -99,4 +99,88 @@ defmodule Absinthe.Fixtures.Things.SDLSchema do """ + @db %{ + "foo" => %{id: "foo", name: "Foo", value: 4}, + "bar" => %{id: "bar", name: "Bar", value: 5} + } + + def decorations(%Absinthe.Blueprint{}, _) do + %{ + mutation: %{ + failing_thing: [ + resolve: &__MODULE__.resolve_failing_thing/3 + ] + }, + query: %{ + bad_resolution: [ + resolve: &__MODULE__.resolve_bad/3 + ], + number: [ + resolve: &__MODULE__.resolve_number/3 + ], + thing_by_context: [ + resolve: &__MODULE__.resolve_things_by_context/3 + ], + things: [ + resolve: &__MODULE__.resolve_things/3 + ], + thing: [ + resolve: &__MODULE__.resolve_thing/3 + ], + deprecated_thing: [ + resolve: &__MODULE__.resolve_thing/3 + ], + deprecated_thing_with_reason: [ + resolve: &__MODULE__.resolve_thing/3 + ] + } + } + end + + def decorations(_node, _ancestors) do + [] + end + + def resolve_failing_thing(_, %{type: :multiple}, _) do + {:error, ["one", "two"]} + end + + def resolve_failing_thing(_, %{type: :with_code}, _) do + {:error, message: "Custom Error", code: 42} + end + + def resolve_failing_thing(_, %{type: :without_message}, _) do + {:error, code: 42} + end + + def resolve_failing_thing(_, %{type: :multiple_with_code}, _) do + {:error, [%{message: "Custom Error 1", code: 1}, %{message: "Custom Error 2", code: 2}]} + end + + def resolve_failing_thing(_, %{type: :multiple_without_message}, _) do + {:error, [%{message: "Custom Error 1", code: 1}, %{code: 2}]} + end + + def resolve_bad(_, _, _) do + :not_expected + end + + def resolve_number(_, %{val: v}, _), do: {:ok, v |> to_string} + def resolve_number(_, args, _), do: {:error, "got #{inspect(args)}"} + + def resolve_things_by_context(_, _, %{context: %{thing: id}}) do + {:ok, @db |> Map.get(id)} + end + def resolve_things_by_context(_, _, _) do + {:error, "No :id context provided"} + end + + def resolve_things(_, _, _) do + {:ok, @db |> Map.values() |> Enum.sort_by(& &1.id)} + end + + def resolve_thing(_, %{id: id}, _) do + {:ok, @db |> Map.get(id)} + end + end From b8a464d6190cec311ae3e8653b88d2f9e39051d2 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Mon, 20 May 2019 14:55:18 -0700 Subject: [PATCH 07/13] Support no-op directives --- lib/absinthe/blueprint/directive.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/absinthe/blueprint/directive.ex b/lib/absinthe/blueprint/directive.ex index c9f2d1f84b..6f0af2e85d 100644 --- a/lib/absinthe/blueprint/directive.ex +++ b/lib/absinthe/blueprint/directive.ex @@ -36,7 +36,14 @@ defmodule Absinthe.Blueprint.Directive do def expand(%__MODULE__{schema_node: type} = directive, node) do args = Blueprint.Input.Argument.value_map(directive.arguments) - Absinthe.Type.function(type, :expand).(args, node) + case Absinthe.Type.function(type, :expand) do + nil -> + # Directive is a no-op + node + + expansion when is_function(expansion) -> + expansion.(args, node) + end end @doc """ From 9b76d60832a830f2aa7bda057a5867aa1034a81c Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Mon, 20 May 2019 17:59:20 -0700 Subject: [PATCH 08/13] Add directive placement for schema declarations --- lib/absinthe/blueprint/directive.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/absinthe/blueprint/directive.ex b/lib/absinthe/blueprint/directive.ex index 6f0af2e85d..b9c5881085 100644 --- a/lib/absinthe/blueprint/directive.ex +++ b/lib/absinthe/blueprint/directive.ex @@ -57,6 +57,7 @@ defmodule Absinthe.Blueprint.Directive do def placement(%Blueprint.Document.Fragment.Inline{}), do: :inline_fragment def placement(%Blueprint.Document.Operation{}), do: :operation_definition def placement(%Blueprint.Schema.SchemaDefinition{}), do: :schema + def placement(%Blueprint.Schema.SchemaDeclaration{}), do: :schema def placement(%Blueprint.Schema.ScalarTypeDefinition{}), do: :scalar def placement(%Blueprint.Schema.ObjectTypeDefinition{}), do: :object def placement(%Blueprint.Schema.FieldDefinition{}), do: :field_definition From 8a9ded245efd4a12952ed3af2a9336b5f7f3eaa3 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Wed, 29 May 2019 14:53:14 -0700 Subject: [PATCH 09/13] Work on hydrate rename --- lib/absinthe/phase/schema/decorate.ex | 164 ------------------ .../phase/schema/decorate/decorator.ex | 4 - lib/absinthe/phase/schema/hydrate.ex | 164 ++++++++++++++++++ lib/absinthe/pipeline.ex | 2 +- lib/absinthe/schema.ex | 4 +- lib/absinthe/schema/hydrator.ex | 6 + .../notation/experimental/import_sdl_test.exs | 10 +- test/support/fixtures/things/sdl_schema.ex | 4 +- 8 files changed, 180 insertions(+), 178 deletions(-) delete mode 100644 lib/absinthe/phase/schema/decorate.ex delete mode 100644 lib/absinthe/phase/schema/decorate/decorator.ex create mode 100644 lib/absinthe/phase/schema/hydrate.ex create mode 100644 lib/absinthe/schema/hydrator.ex diff --git a/lib/absinthe/phase/schema/decorate.ex b/lib/absinthe/phase/schema/decorate.ex deleted file mode 100644 index 89f6e7b537..0000000000 --- a/lib/absinthe/phase/schema/decorate.ex +++ /dev/null @@ -1,164 +0,0 @@ -defmodule Absinthe.Phase.Schema.Decorate do - @moduledoc false - @behaviour __MODULE__.Decorator - - use Absinthe.Phase - alias Absinthe.Blueprint - - @decorate [ - Blueprint.Schema.DirectiveDefinition, - Blueprint.Schema.EnumTypeDefinition, - Blueprint.Schema.EnumValueDefinition, - Blueprint.Schema.FieldDefinition, - Blueprint.Schema.InputObjectTypeDefinition, - Blueprint.Schema.InputValueDefinition, - Blueprint.Schema.InterfaceTypeDefinition, - Blueprint.Schema.ObjectTypeDefinition, - Blueprint.Schema.ScalarTypeDefinition, - Blueprint.Schema.SchemaDefinition, - Blueprint.Schema.UnionTypeDefinition - ] - - @impl Absinthe.Phase - def run(blueprint, opts \\ []) do - {:ok, schema} = Keyword.fetch(opts, :schema) - decorator = Keyword.get(opts, :decorator, __MODULE__) - blueprint = Blueprint.prewalk(blueprint, &handle_node(&1, [], schema, decorator)) - {:ok, blueprint} - end - - defp handle_node(%Blueprint{} = node, ancestors, schema, decorator) do - node - |> decorate_node(ancestors, schema, decorator) - |> set_children(ancestors, schema, decorator) - end - - defp handle_node(%node_module{} = node, ancestors, schema, decorator) - when node_module in @decorate do - case Absinthe.Type.built_in_module?(node.module) do - true -> - {:halt, node} - - false -> - node - |> decorate_node(ancestors, schema, decorator) - |> set_children(ancestors, schema, decorator) - end - end - - defp handle_node(node, ancestors, schema, decorator) do - set_children(node, ancestors, schema, decorator) - end - - defp set_children(parent, ancestors, schema, decorator) do - Blueprint.prewalk(parent, fn - ^parent -> parent - child -> {:halt, handle_node(child, [parent | ancestors], schema, decorator)} - end) - end - - defp decorate_node(%{} = node, ancestors, schema, decorator) do - decorations = schema.decorations(node, ancestors) - apply_decorations(node, decorations, decorator) - end - - defp decorate_node(node, _ancestors, _schema, _decorator) do - node - end - - defp apply_decorations(node, decorations, decorator) do - decorations - |> List.wrap() - |> Enum.reduce(node, fn decoration, node -> - decorator.apply_decoration(node, decoration) - end) - end - - @impl __MODULE__.Decorator - - def apply_decoration(node, {:description, text}) do - %{node | description: text} - end - - def apply_decoration(node, {:resolve, resolver}) do - %{node | middleware: [{Absinthe.Resolution, resolver}]} - end - - @decoration_level1 [ - Blueprint.Schema.DirectiveDefinition, - Blueprint.Schema.EnumTypeDefinition, - Blueprint.Schema.InputObjectTypeDefinition, - Blueprint.Schema.InterfaceTypeDefinition, - Blueprint.Schema.ObjectTypeDefinition, - Blueprint.Schema.ScalarTypeDefinition, - Blueprint.Schema.UnionTypeDefinition - ] - - @decoration_level2 [ - Blueprint.Schema.FieldDefinition, - Blueprint.Schema.EnumValueDefinition - ] - - @decoration_level3 [ - Blueprint.Schema.InputValueDefinition - ] - - def apply_decoration(%Absinthe.Blueprint{} = root, %{} = sub_decorations) do - {root, _} = - Blueprint.prewalk(root, nil, fn - %module{identifier: ident} = node, nil when module in @decoration_level1 -> - case Map.fetch(sub_decorations, ident) do - :error -> - {node, nil} - - {:ok, type_decorations} -> - {apply_decorations(node, type_decorations, __MODULE__), nil} - end - - node, nil -> - {node, nil} - end) - - root - end - - def apply_decoration(%module{} = root, %{} = sub_decorations) - when module in @decoration_level1 do - {root, _} = - Blueprint.prewalk(root, nil, fn - %module{identifier: ident} = node, nil when module in @decoration_level2 -> - case Map.fetch(sub_decorations, ident) do - :error -> - {node, nil} - - {:ok, type_decorations} -> - {apply_decorations(node, type_decorations, __MODULE__), nil} - end - - node, nil -> - {node, nil} - end) - - root - end - - def apply_decoration(%module{} = root, %{} = sub_decorations) - when module in @decoration_level2 do - {root, _} = - Blueprint.prewalk(root, nil, fn - %module{identifier: ident} = node, nil when module in @decoration_level3 -> - case Map.fetch(sub_decorations, ident) do - :error -> - {node, nil} - - {:ok, type_decorations} -> - {apply_decorations(node, type_decorations, __MODULE__), nil} - end - - node, nil -> - {node, nil} - end) - - root - end -end diff --git a/lib/absinthe/phase/schema/decorate/decorator.ex b/lib/absinthe/phase/schema/decorate/decorator.ex deleted file mode 100644 index a2e9ee53e9..0000000000 --- a/lib/absinthe/phase/schema/decorate/decorator.ex +++ /dev/null @@ -1,4 +0,0 @@ -defmodule Absinthe.Phase.Schema.Decorate.Decorator do - @callback apply_decoration(node :: Absinthe.Blueprint.Schema.t(), decoration :: any) :: - Absinthe.Blueprint.Schema.t() -end diff --git a/lib/absinthe/phase/schema/hydrate.ex b/lib/absinthe/phase/schema/hydrate.ex new file mode 100644 index 0000000000..3b8c1255fd --- /dev/null +++ b/lib/absinthe/phase/schema/hydrate.ex @@ -0,0 +1,164 @@ +defmodule Absinthe.Phase.Schema.Hydrate do + @moduledoc false + @behaviour Absinthe.Schema.Hydrator + + use Absinthe.Phase + alias Absinthe.Blueprint + + @hydrate [ + Blueprint.Schema.DirectiveDefinition, + Blueprint.Schema.EnumTypeDefinition, + Blueprint.Schema.EnumValueDefinition, + Blueprint.Schema.FieldDefinition, + Blueprint.Schema.InputObjectTypeDefinition, + Blueprint.Schema.InputValueDefinition, + Blueprint.Schema.InterfaceTypeDefinition, + Blueprint.Schema.ObjectTypeDefinition, + Blueprint.Schema.ScalarTypeDefinition, + Blueprint.Schema.SchemaDefinition, + Blueprint.Schema.UnionTypeDefinition + ] + + @impl Absinthe.Phase + def run(blueprint, opts \\ []) do + {:ok, schema} = Keyword.fetch(opts, :schema) + hydrator = Keyword.get(opts, :hydrator, __MODULE__) + blueprint = Blueprint.prewalk(blueprint, &handle_node(&1, [], schema, hydrator)) + {:ok, blueprint} + end + + defp handle_node(%Blueprint{} = node, ancestors, schema, hydrator) do + node + |> hydrate_node(ancestors, schema, hydrator) + |> set_children(ancestors, schema, hydrator) + end + + defp handle_node(%node_module{} = node, ancestors, schema, hydrator) + when node_module in @hydrate do + case Absinthe.Type.built_in_module?(node.module) do + true -> + {:halt, node} + + false -> + node + |> hydrate_node(ancestors, schema, hydrator) + |> set_children(ancestors, schema, hydrator) + end + end + + defp handle_node(node, ancestors, schema, hydrator) do + set_children(node, ancestors, schema, hydrator) + end + + defp set_children(parent, ancestors, schema, hydrator) do + Blueprint.prewalk(parent, fn + ^parent -> parent + child -> {:halt, handle_node(child, [parent | ancestors], schema, hydrator)} + end) + end + + defp hydrate_node(%{} = node, ancestors, schema, hydrator) do + hydrations = schema.hydrate(node, ancestors) + apply_hydrations(node, hydrations, hydrator) + end + + defp hydrate_node(node, _ancestors, _schema, _hydrator) do + node + end + + defp apply_hydrations(node, hydrations, hydrator) do + hydrations + |> List.wrap() + |> Enum.reduce(node, fn hydration, node -> + hydrator.apply_hydration(node, hydration) + end) + end + + @impl Absinthe.Schema.Hydrator + + def hydrate(node, {:description, text}) do + %{node | description: text} + end + + def hydrate(node, {:resolve, resolver}) do + %{node | middleware: [{Absinthe.Resolution, resolver}]} + end + + @hydration_level1 [ + Blueprint.Schema.DirectiveDefinition, + Blueprint.Schema.EnumTypeDefinition, + Blueprint.Schema.InputObjectTypeDefinition, + Blueprint.Schema.InterfaceTypeDefinition, + Blueprint.Schema.ObjectTypeDefinition, + Blueprint.Schema.ScalarTypeDefinition, + Blueprint.Schema.UnionTypeDefinition + ] + + @hydration_level2 [ + Blueprint.Schema.FieldDefinition, + Blueprint.Schema.EnumValueDefinition + ] + + @hydration_level3 [ + Blueprint.Schema.InputValueDefinition + ] + + def apply_hydration(%Absinthe.Blueprint{} = root, %{} = sub_hydrations) do + {root, _} = + Blueprint.prewalk(root, nil, fn + %module{identifier: ident} = node, nil when module in @hydration_level1 -> + case Map.fetch(sub_hydrations, ident) do + :error -> + {node, nil} + + {:ok, type_hydrations} -> + {apply_hydrations(node, type_hydrations, __MODULE__), nil} + end + + node, nil -> + {node, nil} + end) + + root + end + + def apply_hydration(%module{} = root, %{} = sub_hydrations) + when module in @hydration_level1 do + {root, _} = + Blueprint.prewalk(root, nil, fn + %module{identifier: ident} = node, nil when module in @hydration_level2 -> + case Map.fetch(sub_hydrations, ident) do + :error -> + {node, nil} + + {:ok, type_hydrations} -> + {apply_hydrations(node, type_hydrations, __MODULE__), nil} + end + + node, nil -> + {node, nil} + end) + + root + end + + def apply_hydration(%module{} = root, %{} = sub_hydrations) + when module in @hydration_level2 do + {root, _} = + Blueprint.prewalk(root, nil, fn + %module{identifier: ident} = node, nil when module in @hydration_level3 -> + case Map.fetch(sub_hydrations, ident) do + :error -> + {node, nil} + + {:ok, type_hydrations} -> + {apply_hydrations(node, type_hydrations, __MODULE__), nil} + end + + node, nil -> + {node, nil} + end) + + root + end +end diff --git a/lib/absinthe/pipeline.ex b/lib/absinthe/pipeline.ex index d65be0b968..262d2f9104 100644 --- a/lib/absinthe/pipeline.ex +++ b/lib/absinthe/pipeline.ex @@ -118,7 +118,7 @@ defmodule Absinthe.Pipeline do Phase.Schema.TypeImports, Phase.Schema.ApplyDeclaration, Phase.Schema.Introspection, - {Phase.Schema.Decorate, [schema: schema]}, + {Phase.Schema.Hydrate, [schema: schema]}, Phase.Schema.NormalizeReferences, Phase.Schema.Validation.TypeNamesAreUnique, Phase.Schema.Validation.TypeReferencesExist, diff --git a/lib/absinthe/schema.ex b/lib/absinthe/schema.ex index ef90055a31..9c4d3936cd 100644 --- a/lib/absinthe/schema.ex +++ b/lib/absinthe/schema.ex @@ -130,7 +130,7 @@ defmodule Absinthe.Schema do end @doc false - def decorations(node, ancestors) do + def hydrate(_node, _ancestors) do [] end @@ -139,7 +139,7 @@ defmodule Absinthe.Schema do directives end - defoverridable(context: 1, middleware: 3, plugins: 0, decorations: 2, sdl_directives: 1) + defoverridable(context: 1, middleware: 3, plugins: 0, hydrate: 2, sdl_directives: 1) end end diff --git a/lib/absinthe/schema/hydrator.ex b/lib/absinthe/schema/hydrator.ex new file mode 100644 index 0000000000..7f6f3473e0 --- /dev/null +++ b/lib/absinthe/schema/hydrator.ex @@ -0,0 +1,6 @@ +defmodule Absinthe.Schema.Hydrator do + + @callback hydrate(node :: Absinthe.Blueprint.Schema.t(), hydration :: any) :: + Absinthe.Blueprint.Schema.t() + +end diff --git a/test/absinthe/schema/notation/experimental/import_sdl_test.exs b/test/absinthe/schema/notation/experimental/import_sdl_test.exs index 33a75f60f0..0f99f1022a 100644 --- a/test/absinthe/schema/notation/experimental/import_sdl_test.exs +++ b/test/absinthe/schema/notation/experimental/import_sdl_test.exs @@ -75,19 +75,19 @@ defmodule Absinthe.Schema.Notation.Experimental.ImportSdlTest do {:ok, Map.get(post, :title) |> String.upcase()} end - def decorations(%{identifier: :admin}, [%{identifier: :query} | _]) do + def hydrate(%{identifier: :admin}, [%{identifier: :query} | _]) do {:description, "The admin"} end - def decorations(%{identifier: :filter}, [%{identifier: :posts} | _]) do + def hydrate(%{identifier: :filter}, [%{identifier: :posts} | _]) do {:description, "A filter argument"} end - def decorations(%{identifier: :posts}, [%{identifier: :query} | _]) do + def hydrate(%{identifier: :posts}, [%{identifier: :query} | _]) do {:resolve, &__MODULE__.get_posts/3} end - def decorations(%Absinthe.Blueprint{}, _) do + def hydrate(%Absinthe.Blueprint{}, _) do %{ query: %{ posts: %{ @@ -103,7 +103,7 @@ defmodule Absinthe.Schema.Notation.Experimental.ImportSdlTest do } end - def decorations(_node, _ancestors) do + def hydrate(_node, _ancestors) do [] end end diff --git a/test/support/fixtures/things/sdl_schema.ex b/test/support/fixtures/things/sdl_schema.ex index 4f8cc446c3..fd3f6024a3 100644 --- a/test/support/fixtures/things/sdl_schema.ex +++ b/test/support/fixtures/things/sdl_schema.ex @@ -104,7 +104,7 @@ defmodule Absinthe.Fixtures.Things.SDLSchema do "bar" => %{id: "bar", name: "Bar", value: 5} } - def decorations(%Absinthe.Blueprint{}, _) do + def hydrate(%Absinthe.Blueprint{}, _) do %{ mutation: %{ failing_thing: [ @@ -137,7 +137,7 @@ defmodule Absinthe.Fixtures.Things.SDLSchema do } end - def decorations(_node, _ancestors) do + def hydrate(_node, _ancestors) do [] end From 05186193b7155bc23fe915329671573a4c21a30c Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 31 May 2019 10:03:52 -0700 Subject: [PATCH 10/13] Fix callback --- lib/absinthe/phase/schema/hydrate.ex | 4 ++-- lib/absinthe/schema/hydrator.ex | 6 ++++-- lib/absinthe/schema/notation/sdl.ex | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/absinthe/phase/schema/hydrate.ex b/lib/absinthe/phase/schema/hydrate.ex index 3b8c1255fd..bcd59a38c2 100644 --- a/lib/absinthe/phase/schema/hydrate.ex +++ b/lib/absinthe/phase/schema/hydrate.ex @@ -76,11 +76,11 @@ defmodule Absinthe.Phase.Schema.Hydrate do @impl Absinthe.Schema.Hydrator - def hydrate(node, {:description, text}) do + def apply_hydration(node, {:description, text}) do %{node | description: text} end - def hydrate(node, {:resolve, resolver}) do + def apply_hydration(node, {:resolve, resolver}) do %{node | middleware: [{Absinthe.Resolution, resolver}]} end diff --git a/lib/absinthe/schema/hydrator.ex b/lib/absinthe/schema/hydrator.ex index 7f6f3473e0..5d82c9338d 100644 --- a/lib/absinthe/schema/hydrator.ex +++ b/lib/absinthe/schema/hydrator.ex @@ -1,6 +1,8 @@ defmodule Absinthe.Schema.Hydrator do - @callback hydrate(node :: Absinthe.Blueprint.Schema.t(), hydration :: any) :: - Absinthe.Blueprint.Schema.t() + @callback apply_hydration( + node :: Absinthe.Blueprint.Schema.t(), + hydration :: any + ) :: Absinthe.Blueprint.Schema.t() end diff --git a/lib/absinthe/schema/notation/sdl.ex b/lib/absinthe/schema/notation/sdl.ex index a4961d583f..e11ba5e014 100644 --- a/lib/absinthe/schema/notation/sdl.ex +++ b/lib/absinthe/schema/notation/sdl.ex @@ -5,8 +5,6 @@ defmodule Absinthe.Schema.Notation.SDL do Parse definitions from SDL source """ - alias Absinthe.Blueprint - @spec parse(sdl :: String.t(), module(), map(), Keyword.t()) :: {:ok, [Absinthe.Blueprint.Schema.type_t()]} | {:error, String.t()} def parse(sdl, module, ref, opts) do From 61e4fbba122ad51f5e3f4d58894ab80d1b074968 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 31 May 2019 11:12:39 -0700 Subject: [PATCH 11/13] Typos! --- lib/absinthe/phase/schema/apply_declaration.ex | 2 +- .../{schema_implemantions.ex => schema_implementations.ex} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/support/case/helpers/{schema_implemantions.ex => schema_implementations.ex} (100%) diff --git a/lib/absinthe/phase/schema/apply_declaration.ex b/lib/absinthe/phase/schema/apply_declaration.ex index c057051788..0682896b6d 100644 --- a/lib/absinthe/phase/schema/apply_declaration.ex +++ b/lib/absinthe/phase/schema/apply_declaration.ex @@ -19,7 +19,7 @@ defmodule Absinthe.Phase.Schema.ApplyDeclaration do %{blueprint | schema_definitions: Enum.map(blueprint.schema_definitions, &process_schema_definition/1)} end - # Strip the schema declaration out of the schema's type definitions and apply ita + # Strip the schema declaration out of the schema's type definitions and apply it @spec process_schema_definition(schema_definition :: Blueprint.Schema.SchemaDefinition.t()) :: Blueprint.Schema.SchemaDefinition.t() defp process_schema_definition(schema_definition) do {declarations, type_defs} = diff --git a/test/support/case/helpers/schema_implemantions.ex b/test/support/case/helpers/schema_implementations.ex similarity index 100% rename from test/support/case/helpers/schema_implemantions.ex rename to test/support/case/helpers/schema_implementations.ex From 0391f6c151342af6fb2a1b416297b70318823d23 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 31 May 2019 11:26:43 -0700 Subject: [PATCH 12/13] Formatting --- lib/absinthe/blueprint/directive.ex | 2 +- .../phase/schema/apply_declaration.ex | 43 ++++++++++++++----- .../phase/schema/attach_directives.ex | 17 +++++--- lib/absinthe/phase/schema/directives.ex | 6 ++- .../validation/type_names_are_unique.ex | 12 +++--- lib/absinthe/schema/hydrator.ex | 8 ++-- lib/absinthe/schema/notation/sdl.ex | 18 ++++++-- test/absinthe/execution/subscription_test.exs | 22 +++++++--- .../execution/operation_by_name_test.exs | 3 +- .../integration/execution/root_value_test.exs | 4 +- .../execution/variables/basic_test.exs | 11 +++-- .../case/helpers/schema_implementations.ex | 2 - test/support/fixtures/things/sdl_schema.ex | 4 +- 13 files changed, 102 insertions(+), 50 deletions(-) diff --git a/lib/absinthe/blueprint/directive.ex b/lib/absinthe/blueprint/directive.ex index b9c5881085..21322fd978 100644 --- a/lib/absinthe/blueprint/directive.ex +++ b/lib/absinthe/blueprint/directive.ex @@ -18,7 +18,6 @@ defmodule Absinthe.Blueprint.Directive do ] @type t :: %__MODULE__{ - name: String.t(), arguments: [Blueprint.Input.Argument.t()], source_location: nil | Blueprint.SourceLocation.t(), @@ -36,6 +35,7 @@ defmodule Absinthe.Blueprint.Directive do def expand(%__MODULE__{schema_node: type} = directive, node) do args = Blueprint.Input.Argument.value_map(directive.arguments) + case Absinthe.Type.function(type, :expand) do nil -> # Directive is a no-op diff --git a/lib/absinthe/phase/schema/apply_declaration.ex b/lib/absinthe/phase/schema/apply_declaration.ex index 0682896b6d..eeba3cddef 100644 --- a/lib/absinthe/phase/schema/apply_declaration.ex +++ b/lib/absinthe/phase/schema/apply_declaration.ex @@ -16,22 +16,36 @@ defmodule Absinthe.Phase.Schema.ApplyDeclaration do # Apply schema declaration to each schema definition @spec process(blueprint :: Blueprint.t()) :: Blueprint.t() defp process(blueprint = %Blueprint{}) do - %{blueprint | schema_definitions: Enum.map(blueprint.schema_definitions, &process_schema_definition/1)} + %{ + blueprint + | schema_definitions: Enum.map(blueprint.schema_definitions, &process_schema_definition/1) + } end # Strip the schema declaration out of the schema's type definitions and apply it - @spec process_schema_definition(schema_definition :: Blueprint.Schema.SchemaDefinition.t()) :: Blueprint.Schema.SchemaDefinition.t() + @spec process_schema_definition(schema_definition :: Blueprint.Schema.SchemaDefinition.t()) :: + Blueprint.Schema.SchemaDefinition.t() defp process_schema_definition(schema_definition) do {declarations, type_defs} = - Enum.split_with(schema_definition.type_definitions, &match?(%Blueprint.Schema.SchemaDeclaration{}, &1)) + Enum.split_with( + schema_definition.type_definitions, + &match?(%Blueprint.Schema.SchemaDeclaration{}, &1) + ) + # Remove declaration schema_definition = %{schema_definition | type_definitions: type_defs} + case declarations do [declaration] -> root_mappings = declaration |> extract_root_mappings - %{schema_definition | type_definitions: Enum.map(schema_definition.type_definitions, &maybe_mark_root(&1, root_mappings))} + + %{ + schema_definition + | type_definitions: + Enum.map(schema_definition.type_definitions, &maybe_mark_root(&1, root_mappings)) + } [] -> schema_definition @@ -49,22 +63,27 @@ defmodule Absinthe.Phase.Schema.ApplyDeclaration do @spec error(declaration :: Blueprint.Schema.SchemaDeclaration.t()) :: Absinthe.Phase.Error.t() defp error(declaration) do %Absinthe.Phase.Error{ - message: "More than one schema declaration found. Only one instance of `schema' should be present in SDL.", + message: + "More than one schema declaration found. Only one instance of `schema' should be present in SDL.", locations: [declaration.__reference__.location], phase: __MODULE__ } end # Extract the declared root type names - @spec extract_root_mappings(declaration :: Blueprint.Schema.SchemaDeclaration.t()) :: root_mappings() + @spec extract_root_mappings(declaration :: Blueprint.Schema.SchemaDeclaration.t()) :: + root_mappings() defp extract_root_mappings(declaration) do - for field_def <- declaration.field_definitions, field_def.identifier in ~w(query mutation subscription)a, into: %{} do + for field_def <- declaration.field_definitions, + field_def.identifier in ~w(query mutation subscription)a, + into: %{} do {field_def.identifier, field_def.type} end end # If the type definition is declared as a root type, set the identifier appropriately - @spec maybe_mark_root(type_def :: Blueprint.Schema.node_t(), root_mappings :: root_mappings()) :: Blueprint.Schema.node_t() + @spec maybe_mark_root(type_def :: Blueprint.Schema.node_t(), root_mappings :: root_mappings()) :: + Blueprint.Schema.node_t() defp maybe_mark_root(%Blueprint.Schema.ObjectTypeDefinition{} = type_def, root_mappings) do case operation_root_identifier(type_def, root_mappings) do nil -> @@ -74,12 +93,17 @@ defmodule Absinthe.Phase.Schema.ApplyDeclaration do %{type_def | identifier: identifier} end end + defp maybe_mark_root(type_def, _root_mappings), do: type_def # Determine which, if any, root identifier should be applied to an object type definitiona - @spec operation_root_identifier(type_def :: Blueprint.Schema.ObjectTypeDefinition.t(), root_mappings :: root_mappings()) :: nil | operation() + @spec operation_root_identifier( + type_def :: Blueprint.Schema.ObjectTypeDefinition.t(), + root_mappings :: root_mappings() + ) :: nil | operation() defp operation_root_identifier(type_def, root_mappings) do match_name = type_def.name + Enum.find_value(root_mappings, fn {ident, %{name: ^match_name}} -> ident @@ -88,5 +112,4 @@ defmodule Absinthe.Phase.Schema.ApplyDeclaration do false end) end - end diff --git a/lib/absinthe/phase/schema/attach_directives.ex b/lib/absinthe/phase/schema/attach_directives.ex index 5a9fd45f69..a5052c576e 100644 --- a/lib/absinthe/phase/schema/attach_directives.ex +++ b/lib/absinthe/phase/schema/attach_directives.ex @@ -10,18 +10,19 @@ defmodule Absinthe.Phase.Schema.AttachDirectives do @spec run(Blueprint.t(), Keyword.t()) :: {:ok, Blueprint.t()} def run(input, _options \\ []) do - node = Blueprint.prewalk(input, &(handle_node(&1, input.schema))) + node = Blueprint.prewalk(input, &handle_node(&1, input.schema)) {:ok, node} end - @spec handle_node(node :: Blueprint.Directive.t(), schema :: Absinthe.Schema.t()) :: Blueprint.Directive.t() + @spec handle_node(node :: Blueprint.Directive.t(), schema :: Absinthe.Schema.t()) :: + Blueprint.Directive.t() defp handle_node(%Blueprint.Directive{} = node, schema) do - schema_node = - Enum.find(available_directives(schema), &(&1.name == node.name)) + schema_node = Enum.find(available_directives(schema), &(&1.name == node.name)) %{node | schema_node: schema_node} end - @spec handle_node(node :: Blueprint.node_t(), schema :: Absinthe.Schema.t()) :: Blueprint.node_t() + @spec handle_node(node :: Blueprint.node_t(), schema :: Absinthe.Schema.t()) :: + Blueprint.node_t() defp handle_node(node, _schema) do node end @@ -43,9 +44,11 @@ defmodule Absinthe.Phase.Schema.AttachDirectives do @doc """ Add a deprecation (with an optional reason) to a node. """ - @spec expand_deprecate(arguments :: %{optional(:reason) => String.t()}, node :: Blueprint.node_t()) :: Blueprint.node_t() + @spec expand_deprecate( + arguments :: %{optional(:reason) => String.t()}, + node :: Blueprint.node_t() + ) :: Blueprint.node_t() def expand_deprecate(arguments, node) do %{node | deprecation: %Absinthe.Type.Deprecation{reason: arguments[:reason]}} end - end diff --git a/lib/absinthe/phase/schema/directives.ex b/lib/absinthe/phase/schema/directives.ex index b7142becb4..9d8bbd0e97 100644 --- a/lib/absinthe/phase/schema/directives.ex +++ b/lib/absinthe/phase/schema/directives.ex @@ -38,9 +38,11 @@ defmodule Absinthe.Phase.Schema.Directives do @doc """ Add a deprecation (with an optional reason) to a node. """ - @spec expand_deprecate(arguments :: %{optional(:reason) => String.t()}, node :: Blueprint.node_t()) :: Blueprint.node_t() + @spec expand_deprecate( + arguments :: %{optional(:reason) => String.t()}, + node :: Blueprint.node_t() + ) :: Blueprint.node_t() def expand_deprecate(arguments, node) do %{node | deprecation: %Absinthe.Type.Deprecation{reason: arguments[:reason]}} end - end diff --git a/lib/absinthe/phase/schema/validation/type_names_are_unique.ex b/lib/absinthe/phase/schema/validation/type_names_are_unique.ex index bc36151873..827537c629 100644 --- a/lib/absinthe/phase/schema/validation/type_names_are_unique.ex +++ b/lib/absinthe/phase/schema/validation/type_names_are_unique.ex @@ -13,13 +13,15 @@ defmodule Absinthe.Phase.Schema.Validation.TypeNamesAreUnique do defp handle_schemas(%Blueprint.Schema.SchemaDefinition{} = schema, key) do if Enum.any?(schema.type_definitions, fn - %Blueprint.Schema.SchemaDefinition{} -> - true - _ -> - false - end) do + %Blueprint.Schema.SchemaDefinition{} -> + true + + _ -> + false + end) do raise "SchemaDefinition Inside Schema Definition" end + types = Enum.group_by(schema.type_definitions, &Map.fetch!(&1, key)) directives = Enum.group_by(schema.directive_definitions, &Map.fetch!(&1, key)) diff --git a/lib/absinthe/schema/hydrator.ex b/lib/absinthe/schema/hydrator.ex index 5d82c9338d..a0388cd945 100644 --- a/lib/absinthe/schema/hydrator.ex +++ b/lib/absinthe/schema/hydrator.ex @@ -1,8 +1,6 @@ defmodule Absinthe.Schema.Hydrator do - @callback apply_hydration( - node :: Absinthe.Blueprint.Schema.t(), - hydration :: any - ) :: Absinthe.Blueprint.Schema.t() - + node :: Absinthe.Blueprint.Schema.t(), + hydration :: any + ) :: Absinthe.Blueprint.Schema.t() end diff --git a/lib/absinthe/schema/notation/sdl.ex b/lib/absinthe/schema/notation/sdl.ex index e11ba5e014..48d9dd379f 100644 --- a/lib/absinthe/schema/notation/sdl.ex +++ b/lib/absinthe/schema/notation/sdl.ex @@ -31,7 +31,11 @@ defmodule Absinthe.Schema.Notation.SDL do end defp put_ref(%{fields: fields, directives: directives} = node, ref, opts) do - %{node | fields: Enum.map(fields, &put_ref(&1, ref, opts)), directives: Enum.map(directives, &put_ref(&1, ref, opts))} + %{ + node + | fields: Enum.map(fields, &put_ref(&1, ref, opts)), + directives: Enum.map(directives, &put_ref(&1, ref, opts)) + } |> do_put_ref(ref, opts) end @@ -41,7 +45,11 @@ defmodule Absinthe.Schema.Notation.SDL do end defp put_ref(%{arguments: args, directives: directives} = node, ref, opts) do - %{node | arguments: Enum.map(args, &put_ref(&1, ref, opts)), directives: Enum.map(directives, &put_ref(&1, ref, opts))} + %{ + node + | arguments: Enum.map(args, &put_ref(&1, ref, opts)), + directives: Enum.map(directives, &put_ref(&1, ref, opts)) + } |> do_put_ref(ref, opts) end @@ -64,7 +72,11 @@ defmodule Absinthe.Schema.Notation.SDL do ref path -> - put_in(ref.location, %{file: {:unquote, [], [path]}, line: node.source_location.line, column: node.source_location.column}) + put_in(ref.location, %{ + file: {:unquote, [], [path]}, + line: node.source_location.line, + column: node.source_location.column + }) end %{node | __reference__: ref} diff --git a/test/absinthe/execution/subscription_test.exs b/test/absinthe/execution/subscription_test.exs index bf9b9b8286..9543a9f7c7 100644 --- a/test/absinthe/execution/subscription_test.exs +++ b/test/absinthe/execution/subscription_test.exs @@ -279,7 +279,11 @@ defmodule Absinthe.Execution.SubscriptionTest do } ] } - } == run_subscription(@query, Schema, variables: %{"clientId" => "abc"}, context: %{pubsub: PubSub}) + } == + run_subscription(@query, Schema, + variables: %{"clientId" => "abc"}, + context: %{pubsub: PubSub} + ) end @query """ @@ -340,7 +344,8 @@ defmodule Absinthe.Execution.SubscriptionTest do } """ test "topic function receives a document" do - assert {:ok, %{"subscribed" => _topic}} = run_subscription(@query, Schema, context: %{pubsub: PubSub}) + assert {:ok, %{"subscribed" => _topic}} = + run_subscription(@query, Schema, context: %{pubsub: PubSub}) end @query """ @@ -350,7 +355,10 @@ defmodule Absinthe.Execution.SubscriptionTest do """ test "stringifies topics" do assert {:ok, %{"subscribed" => topic}} = - run_subscription(@query, Schema, variables: %{"clientId" => "1"}, context: %{pubsub: PubSub}) + run_subscription(@query, Schema, + variables: %{"clientId" => "1"}, + context: %{pubsub: PubSub} + ) Absinthe.Subscription.publish(PubSub, "foo", thing: 1) @@ -365,7 +373,9 @@ defmodule Absinthe.Execution.SubscriptionTest do test "isn't tripped up if one of the subscription docs raises" do assert {:ok, %{"subscribed" => _}} = run_subscription("subscription { raises }", Schema) - assert {:ok, %{"subscribed" => topic}} = run_subscription("subscription { thing(clientId: \"*\")}", Schema) + + assert {:ok, %{"subscribed" => topic}} = + run_subscription("subscription { thing(clientId: \"*\")}", Schema) error_log = capture_log(fn -> @@ -416,7 +426,9 @@ defmodule Absinthe.Execution.SubscriptionTest do ctx2 = %{test_pid: self(), user: 2} # different docs required for test, otherwise they get deduplicated from the start assert {:ok, %{"subscribed" => doc2}} = - run_subscription("subscription { user { group { name } id name} }", Schema, context: ctx2) + run_subscription("subscription { user { group { name } id name} }", Schema, + context: ctx2 + ) user = %{id: "1", name: "Alicia", group: %{name: "Elixir Users"}} diff --git a/test/absinthe/integration/execution/operation_by_name_test.exs b/test/absinthe/integration/execution/operation_by_name_test.exs index 3cc7d612ec..98e3d05980 100644 --- a/test/absinthe/integration/execution/operation_by_name_test.exs +++ b/test/absinthe/integration/execution/operation_by_name_test.exs @@ -43,7 +43,8 @@ defmodule Elixir.Absinthe.Integration.Execution.OperationByNameTest do "Must provide a valid operation name if query contains multiple operations." } ] - }} == Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, operation_name: "invalid") + }} == + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, operation_name: "invalid") end test "scenario #4" do diff --git a/test/absinthe/integration/execution/root_value_test.exs b/test/absinthe/integration/execution/root_value_test.exs index 854f5eb725..dc5ccaa2df 100644 --- a/test/absinthe/integration/execution/root_value_test.exs +++ b/test/absinthe/integration/execution/root_value_test.exs @@ -7,6 +7,8 @@ defmodule Elixir.Absinthe.Integration.Execution.RootValueTest do test "scenario #1" do assert {:ok, %{data: %{"version" => "0.0.1"}}} == - Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, root_value: %{version: "0.0.1"}) + Absinthe.run(@query, Absinthe.Fixtures.Things.MacroSchema, + root_value: %{version: "0.0.1"} + ) end end diff --git a/test/absinthe/integration/execution/variables/basic_test.exs b/test/absinthe/integration/execution/variables/basic_test.exs index 82664b82dd..07c4b0f85e 100644 --- a/test/absinthe/integration/execution/variables/basic_test.exs +++ b/test/absinthe/integration/execution/variables/basic_test.exs @@ -12,12 +12,11 @@ defmodule Elixir.Absinthe.Integration.Execution.Variables.BasicTest do test "scenario #1" do for schema <- schema_implementations(Absinthe.Fixtures.Things) do assert {:ok, %{data: %{"thing" => %{"name" => "Bar"}}}} == - Absinthe.run( - @query, - schema, - variables: %{"thingId" => "bar"} - ) + Absinthe.run( + @query, + schema, + variables: %{"thingId" => "bar"} + ) end end - end diff --git a/test/support/case/helpers/schema_implementations.ex b/test/support/case/helpers/schema_implementations.ex index dbac12d2af..d05980141e 100644 --- a/test/support/case/helpers/schema_implementations.ex +++ b/test/support/case/helpers/schema_implementations.ex @@ -1,10 +1,8 @@ defmodule Absinthe.Case.Helpers.SchemaImplementations do - def schema_implementations(module) do [ Module.safe_concat(module, MacroSchema), Module.safe_concat(module, SDLSchema) ] end - end diff --git a/test/support/fixtures/things/sdl_schema.ex b/test/support/fixtures/things/sdl_schema.ex index fd3f6024a3..400f45b8e2 100644 --- a/test/support/fixtures/things/sdl_schema.ex +++ b/test/support/fixtures/things/sdl_schema.ex @@ -171,8 +171,9 @@ defmodule Absinthe.Fixtures.Things.SDLSchema do def resolve_things_by_context(_, _, %{context: %{thing: id}}) do {:ok, @db |> Map.get(id)} end + def resolve_things_by_context(_, _, _) do - {:error, "No :id context provided"} + {:error, "No :id context provided"} end def resolve_things(_, _, _) do @@ -182,5 +183,4 @@ defmodule Absinthe.Fixtures.Things.SDLSchema do def resolve_thing(_, %{id: id}, _) do {:ok, @db |> Map.get(id)} end - end From 18e45773766b8b7eb63ce458018627cce88ef491 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Fri, 31 May 2019 11:27:49 -0700 Subject: [PATCH 13/13] Update travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 23940d18e4..57681cf545 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,13 @@ elixir: - 1.8.0 notifications: recipients: + - vincefoley@gmail.com - brwcodes@gmail.com - ben.wilson@cargosense.com otp_release: - 20.0 - 21.0 + - 22.0 script: - mix format --check-formatted - MIX_ENV=test mix local.hex --force && MIX_ENV=test mix do deps.get, test