Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dataloader + Absinthe to their latest versions #87

Merged
merged 17 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ jobs:
include:
- elixir: "1.14"
otp: "25"
- elixir: "1.11"
- elixir: "1.12"
otp: "23"
- elixir: "1.10"
otp: "22"

steps:
- name: Checkout
Expand Down
65 changes: 24 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,68 +126,51 @@ end

### Federation v2

You can import Apollo Federation v2 directives using the `@link` directive on your top-level schema.
You can import Apollo Federation v2 directives by extending your top-level schema with the `@link` directive.

```elixir
defmodule MyApp.MySchema do
use Absinthe.Schema
use Absinthe.Federation.Schema

+ link(
+ url: "https://specs.apollo.dev/federation/v2.0",
+ import: [
+ "@key",
+ "@shareable",
+ "@provides",
+ "@external",
+ "@tag",
+ "@extends",
+ "@override",
+ "@inaccessible"
+ ]
+ )
+ extend schema do
+ directive(:link,
+ url: "https://specs.apollo.dev/federation/v2.0",
+ import: [
+ "@key",
+ "@shareable",
+ "@provides",
+ "@external",
+ "@tag",
+ "@extends",
+ "@override",
+ "@inaccessible"
+ ]
+ )
+ end

query do
...
end
end
```

### Using `@link` with custom query and mutation types

If your root query and mutations have custom type names, you can indicate it in the `@link`.

```elixir
defmodule MyApp.MySchema do
use Absinthe.Schema
use Absinthe.Federation.Schema

+ link(url: "https://specs.apollo.dev/federation/v2.0",
+ import: ["@key"],
+ query_type_name: "MyCustomQueryType",
+ mutation_type_name: "MyCustomMutationType"
+ )

query name: "MyCustomQueryType" do
...
end

query name: "MyCustomMutationType" do
...
end
end
```

### Namespacing and directive renaming with `@link`

`@link` directive supports namespacing and directive renaming according to the specs.
`@link` directive supports namespacing and directive renaming (only on **Absinthe >= 1.7.2**) according to the specs.

```elixir
defmodule MyApp.MySchema do
use Absinthe.Schema
use Absinthe.Federation.Schema

+ link(url: "https://specs.apollo.dev/federation/v2.0", import: [%{name: "@key", as: "@primaryKey"}], as: "federation")
+ extend schema do
+ directive(:link,
+ url: "https://specs.apollo.dev/federation/v2.0",
+ import: [%{"name" => "@key", "as" => "@primaryKey"}], # directive renaming
+ as: "federation" # namespacing
+ )
+ end

query do
...
Expand Down
2 changes: 1 addition & 1 deletion federation_compatibility/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Products.MixProject do
[
app: :products,
version: "0.1.0",
elixir: "~> 1.10",
elixir: "~> 1.12",
elixirc_paths: ["lib"],
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/federation/schema/entities_field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ defmodule Absinthe.Federation.Schema.EntitiesField do
case res do
{:ok, data} -> {arg, data}
{:error, _} = e -> {arg, e}
nil -> {arg, nil}
data -> {arg, data}
end
end)
end
Expand Down
7 changes: 3 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Absinthe.Federation.MixProject do
[
app: :absinthe_federation,
version: @version,
elixir: "~> 1.10",
elixir: "~> 1.12",
elixirc_paths: elixirc_paths(Mix.env()),
elixirc_options: [warnings_as_errors: true],
build_embedded: Mix.env() == :prod,
Expand Down Expand Up @@ -62,9 +62,8 @@ defmodule Absinthe.Federation.MixProject do

defp deps do
[
{:absinthe, "~> 1.6.5 or ~> 1.7.0 or ~> 1.7.1"},
{:dataloader, "~> 1.0.9 or ~> 1.0.10"},

{:absinthe, "~> 1.7"},
{:dataloader, "~> 1.0.9 or ~> 1.0.10 or ~> 2.0"},
# Dev
{:dialyxir, ">= 1.0.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.29", only: :dev, runtime: false}
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"absinthe": {:hex, :absinthe, "1.6.5", "b7bdb507824412c447806e08d80c8f231d51a1b40b1400e5d01bd7faf77ffda1", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a4f4ed3808467f1795baadbba24f1355e287b64e6b41ec0cfeb0713575ecb7a9"},
"dataloader": {:hex, :dataloader, "1.0.9", "8fb981e327fa692f741ab283ed93790203a6f6d412800f0f4f1531372e1dbf15", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6f8b7566c8dda46f53bdb336fd02f03f00bf58aeb6cc0f139ccdfd6f99d265a7"},
"absinthe": {:hex, :absinthe, "1.7.6", "0b897365f98d068cfcb4533c0200a8e58825a4aeeae6ec33633ebed6de11773b", [:mix], [{:dataloader, "~> 1.0.0 or ~> 2.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:opentelemetry_process_propagator, "~> 0.2.1", [hex: :opentelemetry_process_propagator, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e7626951ca5eec627da960615b51009f3a774765406ff02722b1d818f17e5778"},
"dataloader": {:hex, :dataloader, "2.0.0", "49b42d60b9bb06d761a71d7b034c4b34787957e713d4fae15387a25fcd639112", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:opentelemetry_process_propagator, "~> 0.2.1", [hex: :opentelemetry_process_propagator, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "09d61781b76ce216e395cdbc883ff00d00f46a503e215c22722dba82507dfef0"},
"dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
"earmark_parser": {:hex, :earmark_parser, "1.4.30", "0b938aa5b9bafd455056440cdaa2a79197ca5e693830b4a982beada840513c5f", [:mix], [], "hexpm", "3b5385c2d36b0473d0b206927b841343d25adb14f95f0110062506b300cd5a1b"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
Expand All @@ -9,5 +9,5 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
}
36 changes: 24 additions & 12 deletions test/absinthe/federation/notation_test.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
defmodule Absinthe.Federation.NotationTest do
use Absinthe.Federation.Case, async: true

# With Absinthe 1.7, the @link macro is not needed anymore. The way forward is to use `extend`
# See https://github.com/DivvyPayHQ/absinthe_federation#federation-v2

describe "macro schema" do
defmodule MacroSchema do
use Absinthe.Schema
use Absinthe.Federation.Schema

link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@tag"])
extend schema do
directive(:link,
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@tag"]
)
end

import_sdl("scalar RandomNumber")

Expand Down Expand Up @@ -48,11 +56,13 @@ defmodule Absinthe.Federation.NotationTest do
use Absinthe.Schema
use Absinthe.Federation.Schema

link(
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@tag"],
as: "federation"
)
extend schema do
directive(:link,
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@tag"],
as: "federation"
)
end

query do
field :hello, :string
Expand All @@ -70,11 +80,13 @@ defmodule Absinthe.Federation.NotationTest do
use Absinthe.Schema
use Absinthe.Federation.Schema

link(
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@tag", %{name: "@override", as: "@replace"}],
as: "federation"
)
extend schema do
directive(:link,
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@tag", %{"name" => "@override", "as" => "@replace"}],
as: "federation"
)
end

query do
field :hello, :string
Expand All @@ -84,7 +96,7 @@ defmodule Absinthe.Federation.NotationTest do
sdl = Absinthe.Schema.to_sdl(MacroSchemaWithRenamedDirectives)

assert sdl =~
~s(schema @link(url: "https:\\/\\/specs.apollo.dev\\/federation\\/v2.0", import: ["@key", "@tag", {name: "@override", as: "@replace"}], as: "federation"\))
~s(schema @link(url: "https:\\/\\/specs.apollo.dev\\/federation\\/v2.0", import: ["@key", "@tag", {as: "@replace", name: "@override"}], as: "federation"\))
end
end
end
1 change: 1 addition & 0 deletions test/absinthe/federation/schema/entity_union_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Absinthe.Federation.Schema.EntityUnionTest do
use Absinthe.Schema

query do
field :me, :string
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/absinthe/federation/schema/resolve_reference_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule Absinthe.Federation.Schema.ResolveReferenceTest do
describe "_resolve_reference" do
test "resolves entity fields correctly" do
query = """
query GetHousePlantEntities($representations: [_Any]) {
query GetHousePlantEntities($representations: [_Any!]!) {
_entities(representations: $representations) {
... on HousePlant {
id
Expand Down
1 change: 1 addition & 0 deletions test/support/a_source_with_nonmap_batches_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ASourceWithNonmapBatchesKey do
def run(source), do: source
def fetch(_source, _batch_key, _item_key), do: {:ok, nil}
def pending_batches?(_source), do: false
def async?(_source), do: false
def put(source, _batch_key, _item_key, _item), do: source
def timeout(_source), do: 1000
end
Expand Down
1 change: 1 addition & 0 deletions test/support/a_source_without_batches_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ASourceWithoutBatchesKey do
def run(source), do: source
def fetch(_source, _batch_key, _item_key), do: {:ok, nil}
def pending_batches?(_source), do: false
def async?(_source), do: false
def put(source, _batch_key, _item_key, _item), do: source
def timeout(_source), do: 1000
end
Expand Down
Loading