Skip to content

Commit 1aa2909

Browse files
committed
Upgrade absinthe_federation to support new fed2 directives
1 parent 0ca0c4b commit 1aa2909

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

implementations/absinthe-federation/lib/products_web/schema.ex

+36-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@ defmodule ProductsWeb.Schema do
1010
defstruct [:email, :name, :total_products_created]
1111
end
1212

13+
import_sdl """
14+
schema @link(url: "https://specs.apollo.dev/federation/v2.0",
15+
import: [
16+
"@key",
17+
"@shareable",
18+
"@provides",
19+
"@external",
20+
"@tag",
21+
"@extends",
22+
"@override",
23+
"@inaccessible"
24+
]) {
25+
query: Query
26+
mutation: Mutation
27+
}
28+
"""
29+
1330
@desc """
1431
extend type User @key(fields: "email") {
1532
email: ID! @external
33+
name: String @shareable @override(from: "users")
1634
totalProductsCreated: Int @external
1735
}
1836
"""
@@ -24,6 +42,11 @@ defmodule ProductsWeb.Schema do
2442
external()
2543
end
2644

45+
field(:name, :string) do
46+
shareable()
47+
override_from("users")
48+
end
49+
2750
field :total_products_created, :integer do
2851
external()
2952
end
@@ -34,14 +57,19 @@ defmodule ProductsWeb.Schema do
3457
end
3558

3659
@desc """
37-
type ProductDimension {
60+
type ProductDimension @shareable {
3861
size: String
3962
weight: Float
63+
unit: String @inaccessible
4064
}
4165
"""
4266
object :product_dimension do
67+
shareable()
4368
field(:size, :string)
4469
field(:weight, :float)
70+
field(:unit, :string) do
71+
inaccessible()
72+
end
4573
end
4674

4775
@desc """
@@ -61,6 +89,7 @@ defmodule ProductsWeb.Schema do
6189
variation: ProductVariation
6290
dimensions: ProductDimension
6391
createdBy: User @provides(fields: "totalProductsCreated")
92+
notes: String @tag(name: "internal")
6493
}
6594
"""
6695
object :product do
@@ -79,6 +108,10 @@ defmodule ProductsWeb.Schema do
79108
resolve(&resolve_product_created_by/3)
80109
end
81110

111+
field(:notes, :string) do
112+
tag("internal")
113+
end
114+
82115
field :_resolve_reference, :product do
83116
resolve(&resolve_product_reference/2)
84117
end
@@ -107,7 +140,7 @@ defmodule ProductsWeb.Schema do
107140
end
108141

109142
defp resolve_product_dimensions(_product, _, _ctx) do
110-
{:ok, %{size: "small", weight: 1}}
143+
{:ok, %{size: "small", weight: 1, unit: "kg"}}
111144
end
112145

113146
defp resolve_product_reference(%{id: id}, _ctx) do
@@ -146,7 +179,7 @@ defmodule ProductsWeb.Schema do
146179
do: [
147180
%User{
148181
149-
name: "Apollo Studio Support",
182+
name: "Jane Smith",
150183
total_products_created: 1337
151184
}
152185
]

implementations/absinthe-federation/mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Products.MixProject do
3535
defp deps do
3636
[
3737
{:absinthe, "~> 1.7.0"},
38-
{:absinthe_federation, "~> 0.2.51"},
38+
{:absinthe_federation, "~> 0.2.52"},
3939
{:absinthe_plug, "~> 1.5"},
4040
{:phoenix, "~> 1.6.10"},
4141
{:gettext, "~> 0.19"},

implementations/absinthe-federation/mix.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%{
22
"absinthe": {:hex, :absinthe, "1.7.0", "36819e7b1fd5046c9c734f27fe7e564aed3bda59f0354c37cd2df88fd32dd014", [: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, "~> 1.0 or ~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "566a5b5519afc9b29c4d367f0c6768162de3ec03e9bf9916f9dc2bcbe7c09643"},
3-
"absinthe_federation": {:hex, :absinthe_federation, "0.2.51", "3d852204807ec1818934fbcfb21339ae67977614fb093b11fea98aafec7b94c6", [:mix], [{:absinthe, "~> 1.6.5 or ~> 1.7.0", [hex: :absinthe, repo: "hexpm", optional: false]}, {:dataloader, "~> 1.0.9", [hex: :dataloader, repo: "hexpm", optional: false]}], "hexpm", "ce191b336af060000060c22b460a4a76870b76de070de61cd5fc476136353c4a"},
3+
"absinthe_federation": {:hex, :absinthe_federation, "0.2.52", "22f6d62d0d301a253155716972e5787fd4e7f3cf3d614dfb6278118132c9a03d", [:mix], [{:absinthe, "~> 1.6.5 or ~> 1.7.0", [hex: :absinthe, repo: "hexpm", optional: false]}, {:dataloader, "~> 1.0.9", [hex: :dataloader, repo: "hexpm", optional: false]}], "hexpm", "f3e685e8c918641e14a881e5b0a5c17b93b6acd974a7c18e6363a476492126b3"},
44
"absinthe_plug": {:hex, :absinthe_plug, "1.5.8", "38d230641ba9dca8f72f1fed2dfc8abd53b3907d1996363da32434ab6ee5d6ab", [:mix], [{:absinthe, "~> 1.5", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bbb04176647b735828861e7b2705465e53e2cf54ccf5a73ddd1ebd855f996e5a"},
55
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
66
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},

0 commit comments

Comments
 (0)