Skip to content

Commit

Permalink
Maintenance fixes (absinthe-graphql#1016)
Browse files Browse the repository at this point in the history
* Rename test file so its executed by the test runner

* Fix unused returned values

* Remove unused files

* Remove unused requires

* Add assertions checking import_types options

* Add import_types/2 to locals_without_parens

* Add documentation for :only/:except on import_types

* Fix formatting

Co-authored-by: Vince Foley <39946+binaryseed@users.noreply.github.com>
  • Loading branch information
maartenvanvliet and binaryseed authored Jan 2, 2021
1 parent 4392bfa commit 17f72bb
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 94 deletions.
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ locals_without_parens = [
import_fields: 2,
import_fields: 1,
import_types: 1,
import_types: 2,
import_sdl: 1,
import_sdl: 2,
input_object: 3,
Expand Down
2 changes: 0 additions & 2 deletions lib/absinthe/language/document.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule Absinthe.Language.Document do
@moduledoc false

require Logger

alias Absinthe.{Blueprint, Language}

defstruct definitions: [],
Expand Down
2 changes: 0 additions & 2 deletions lib/absinthe/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ defmodule Absinthe.Pipeline do

alias Absinthe.Phase

require Logger

@type data_t :: any

@type phase_config_t :: Phase.t() | {Phase.t(), Keyword.t()}
Expand Down
20 changes: 0 additions & 20 deletions lib/absinthe/pipeline/error_result.ex

This file was deleted.

8 changes: 7 additions & 1 deletion lib/absinthe/schema/notation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,9 @@ defmodule Absinthe.Schema.Notation do
Very frequently your schema module will simply have the `query` and `mutation`
blocks, and you'll want to break out your other types into other modules. This
macro imports those types for use the current module
macro imports those types for use the current module.
To selectively import types you can use the `:only` and `:except` opts.
## Placement
Expand All @@ -1242,6 +1244,10 @@ defmodule Absinthe.Schema.Notation do
import_types MyApp.Schema.Types
import_types MyApp.Schema.Types.{TypesA, TypesB}
import_types MyApp.Schema.Types, only: [:foo]
import_types MyApp.Schema.Types, except: [:bar]
```
"""
defmacro import_types(type_module_ast, opts \\ []) do
Expand Down
11 changes: 0 additions & 11 deletions lib/absinthe/schema/notation/definition.ex

This file was deleted.

40 changes: 0 additions & 40 deletions lib/absinthe/schema/rule.ex

This file was deleted.

1 change: 0 additions & 1 deletion lib/absinthe/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ defmodule Absinthe.Subscription do
- More user control over back pressure / async balance.
"""

require Logger
alias __MODULE__

@doc """
Expand Down
1 change: 0 additions & 1 deletion lib/mix/tasks/absinthe.schema.sdl.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Mix.Tasks.Absinthe.Schema.Sdl do
require Logger
use Mix.Task
import Mix.Generator

Expand Down
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ defmodule Absinthe.Mixfile do
Absinthe.Pipeline,
Absinthe.Phase,
Absinthe.Phase.Document.Context,
Absinthe.Phase.Telemetry,
Absinthe.Pipeline.ErrorResult
Absinthe.Phase.Telemetry
],
"Document Adapters": [
Absinthe.Adapter,
Expand Down
1 change: 0 additions & 1 deletion test/absinthe/schema/manipulation_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Absinthe.Schema.ManipulationTest do
use Absinthe.Case, async: true
require IEx

alias Absinthe.Phase.Schema.Validation.TypeNamesAreReserved

Expand Down
27 changes: 24 additions & 3 deletions test/absinthe/schema/notation/experimental/import_types_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,55 @@ defmodule Absinthe.Schema.Notation.Experimental.ImportTypesTest do
end

defmodule WithoutOptions do
use Absinthe.Schema.Notation
use Absinthe.Schema

query do
end

import_types Source
end

defmodule UsingOnlyOption do
use Absinthe.Schema.Notation
use Absinthe.Schema

query do
end

import_types(Source, only: [:one, :two])
end

defmodule UsingExceptOption do
use Absinthe.Schema.Notation
use Absinthe.Schema

query do
end

import_types(Source, except: [:one, :two])
end

describe "import_types" do
test "without options" do
assert [{Source, []}] == imports(WithoutOptions)

assert WithoutOptions.__absinthe_type__(:one)
assert WithoutOptions.__absinthe_type__(:two)
assert WithoutOptions.__absinthe_type__(:three)
end

test "with :only" do
assert [{Source, only: [:one, :two]}] == imports(UsingOnlyOption)

assert UsingOnlyOption.__absinthe_type__(:one)
assert UsingOnlyOption.__absinthe_type__(:two)
refute UsingOnlyOption.__absinthe_type__(:three)
end

test "with :except" do
assert [{Source, except: [:one, :two]}] == imports(UsingExceptOption)

refute UsingExceptOption.__absinthe_type__(:one)
refute UsingExceptOption.__absinthe_type__(:two)
assert UsingExceptOption.__absinthe_type__(:three)
end
end

Expand Down
21 changes: 11 additions & 10 deletions test/support/case/assertions/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ defmodule Absinthe.Case.Assertions.Schema do
load_schema(schema_name)
end

patterns
|> Enum.filter(fn pattern ->
assert Enum.find(err.phase_errors, fn error ->
keys = Map.keys(pattern)
Map.take(error, keys) |> handle_path == pattern |> handle_path
end),
"Could not find error detail pattern #{inspect(pattern)}\n\nin\n\n#{
inspect(err.phase_errors)
}"
end)
patterns =
patterns
|> Enum.filter(fn pattern ->
assert Enum.find(err.phase_errors, fn error ->
keys = Map.keys(pattern)
Map.take(error, keys) |> handle_path == pattern |> handle_path
end),
"Could not find error detail pattern #{inspect(pattern)}\n\nin\n\n#{
inspect(err.phase_errors)
}"
end)

assert length(patterns) == length(err.phase_errors)
end
Expand Down

0 comments on commit 17f72bb

Please sign in to comment.