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 diff --git a/lib/absinthe/blueprint/directive.ex b/lib/absinthe/blueprint/directive.ex index daf8247dd6..21322fd978 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} @@ -31,7 +35,15 @@ 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 """ @@ -45,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 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/validation/known_directives.ex b/lib/absinthe/phase/document/validation/known_directives.ex similarity index 90% rename from lib/absinthe/phase/validation/known_directives.ex rename to lib/absinthe/phase/document/validation/known_directives.ex index ecbd41fb5e..f1934afc6b 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} @@ -64,7 +64,7 @@ defmodule Absinthe.Phase.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.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/apply_declaration.ex b/lib/absinthe/phase/schema/apply_declaration.ex new file mode 100644 index 0000000000..eeba3cddef --- /dev/null +++ b/lib/absinthe/phase/schema/apply_declaration.ex @@ -0,0 +1,115 @@ +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 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} = + 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/attach_directives.ex b/lib/absinthe/phase/schema/attach_directives.ex new file mode 100644 index 0000000000..a5052c576e --- /dev/null +++ b/lib/absinthe/phase/schema/attach_directives.ex @@ -0,0 +1,54 @@ +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/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/directives.ex b/lib/absinthe/phase/schema/directives.ex new file mode 100644 index 0000000000..9d8bbd0e97 --- /dev/null +++ b/lib/absinthe/phase/schema/directives.ex @@ -0,0 +1,48 @@ +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/hydrate.ex b/lib/absinthe/phase/schema/hydrate.ex new file mode 100644 index 0000000000..bcd59a38c2 --- /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 apply_hydration(node, {:description, text}) do + %{node | description: text} + end + + def apply_hydration(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/phase/schema/validation/known_directives.ex b/lib/absinthe/phase/schema/validation/known_directives.ex new file mode 100644 index 0000000000..23a0bb2d5a --- /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: "Directive `#{node.name}' may not be used on #{placement_name}.", + locations: [node.__reference__.location] + } + 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..827537c629 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,16 @@ 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..262d2f9104 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, @@ -116,8 +116,9 @@ 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.Hydrate, [schema: schema]}, Phase.Schema.NormalizeReferences, Phase.Schema.Validation.TypeNamesAreUnique, Phase.Schema.Validation.TypeReferencesExist, @@ -127,8 +128,9 @@ 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.AttachDirectives, + Phase.Schema.Validation.KnownDirectives, + Phase.Schema.Directives, Phase.Schema.Validation.DefaultEnumValuePresent, Phase.Schema.Validation.InputOuputTypesCorrectlyPlaced, Phase.Schema.Validation.InterfacesMustResolveTypes, diff --git a/lib/absinthe/schema.ex b/lib/absinthe/schema.ex index dba438d097..9c4d3936cd 100644 --- a/lib/absinthe/schema.ex +++ b/lib/absinthe/schema.ex @@ -130,11 +130,16 @@ defmodule Absinthe.Schema do end @doc false - def decorations(node, ancestors) do + def hydrate(_node, _ancestors) 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, 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..a0388cd945 --- /dev/null +++ b/lib/absinthe/schema/hydrator.ex @@ -0,0 +1,6 @@ +defmodule Absinthe.Schema.Hydrator do + @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 e466f06aa9..48d9dd379f 100644 --- a/lib/absinthe/schema/notation/sdl.ex +++ b/lib/absinthe/schema/notation/sdl.ex @@ -30,53 +30,56 @@ 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) 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) - # @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 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, 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/execution/subscription_test.exs b/test/absinthe/execution/subscription_test.exs index 83bdda1637..9543a9f7c7 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,11 @@ 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 +295,7 @@ defmodule Absinthe.Execution.SubscriptionTest do id = "1" assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{"userId" => id}, @@ -305,7 +309,7 @@ defmodule Absinthe.Execution.SubscriptionTest do """ assert {:ok, %{data: _}} = - run(mutation, Schema, + run_subscription(mutation, Schema, variables: %{"userId" => id}, context: %{pubsub: PubSub} ) @@ -326,7 +330,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 +344,8 @@ 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 +355,10 @@ 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 +372,10 @@ 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 +397,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 +421,14 @@ 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 +452,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 +467,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 +491,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 +508,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 +527,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 +543,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 +579,7 @@ defmodule Absinthe.Execution.SubscriptionTest do ) assert {:ok, %{"subscribed" => topic}} = - run( + run_subscription( @query, Schema, variables: %{"clientId" => client_id}, @@ -592,10 +604,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 5bed8f6f79..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 @@ -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..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 { @@ -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..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 { @@ -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..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 { @@ -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..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 { @@ -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..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 } } @@ -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..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 { @@ -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/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 f66b2c851e..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 { @@ -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/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 c865fdcce2..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 { @@ -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/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 b67bd46bbb..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 { @@ -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..98e3d05980 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!) { @@ -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,13 @@ 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 +83,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..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 { @@ -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..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 { @@ -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..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 } } @@ -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..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 } } @@ -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..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 } } @@ -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..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 } } @@ -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..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 } } @@ -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..dc5ccaa2df 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 } @@ -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.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..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 { @@ -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..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 } } @@ -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/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 316feafd9a..07c4b0f85e 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!) { @@ -10,11 +10,13 @@ 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 end 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 002f6eb015..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 """ { @@ -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..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 { @@ -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..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 { @@ -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..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 { @@ -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..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) { @@ -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..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") } @@ -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..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 { @@ -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_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 18ecab9858..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 { @@ -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/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 249a8ae78a..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 } } @@ -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..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 { @@ -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..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 """ { @@ -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..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) { @@ -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..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) { @@ -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/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/validation/known_directives_test.exs b/test/absinthe/phase/document/validation/known_directives_test.exs similarity index 95% rename from test/absinthe/phase/validation/known_directives_test.exs rename to test/absinthe/phase/document/validation/known_directives_test.exs index a5a7f66768..f20ce5782e 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, @@ -10,7 +10,7 @@ defmodule Absinthe.Phase.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.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/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/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/experimental/import_sdl_test.exs b/test/absinthe/schema/notation/experimental/import_sdl_test.exs index b63ec3c156..0f99f1022a 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"}}, @@ -71,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: %{ @@ -99,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/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 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_implementations.ex b/test/support/case/helpers/schema_implementations.ex new file mode 100644 index 0000000000..d05980141e --- /dev/null +++ b/test/support/case/helpers/schema_implementations.ex @@ -0,0 +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_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..400f45b8e2 --- /dev/null +++ b/test/support/fixtures/things/sdl_schema.ex @@ -0,0 +1,186 @@ +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 @deprecated, + + "This is a non-null deprecated arg" + deprecatedNonNullArg: String! @deprecated, + + "This is a deprecated arg with a reason" + deprecatedArgWithReason: String @deprecated(reason: "reason"), + + "This is a non-null deprecated arg with a reason" + deprecatedNonNullArgWithReason: String! @deprecated(reason: "reason") + ): Thing + + deprecatedThing( + "id of the thing" + id: String! + ): Thing @deprecated + + deprecatedThingWithReason( + "id of the thing" + id: String! + ): Thing @deprecated(reason: "use `thing' instead") + } + + "A thing as input" + input InputThing { + value: Int + deprecatedField: String @deprecated, + deprecatedFieldWithReason: String @deprecated(reason: "reason") + deprecatedNonNullField: String! @deprecated + } + + "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 + } + + """ + + @db %{ + "foo" => %{id: "foo", name: "Foo", value: 4}, + "bar" => %{id: "bar", name: "Bar", value: 5} + } + + def hydrate(%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 hydrate(_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