`link` does not support having no root mutation type
kzlsakal opened this issue · 4 comments
Root Cause
The link
macro adds the directive with root query and mutation types specified.
schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: ["@key"]) {
query: RootQueryType
mutation: RootMutationType
}
If the schema does not define one of these types, the subgraph SDL becomes invalid. There is no validation to detect this compile-time.
Steps to reproduce
- Have a schema that does not have a root mutation field, such as:
defmodule InventoryWeb.Schema do
use Absinthe.Schema
use Absinthe.Federation.Schema
link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@extends", "@external"])
query do
extends()
end
object :product do
key_fields("upc")
extends()
field :upc, non_null(:string) do
external()
end
field(:in_stock, :boolean) do
resolve(&resolve_in_stock_for_product/3)
end
end
defp resolve_in_stock_for_product(%{upc: _upc} = _product, _args, _ctx), do: {:ok, true}
end
- Start the subgraph and the federated gateway.
Expected result
The gateway starts successfully
Actual result
The gateway returns the following error:
Loading gateway...
Error: A valid schema couldn't be composed. The following composition errors were found:
[inventory] Cannot set schema mutation root to unknown type RootMutationType
Note that extend schema
introduced by absinthe 1.7.1 which was released a couple of days ago eliminates this issue.
extend schema do
directive :link,
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@extends", "@external"]
end
However, because it's macro-based, it won't support renaming individual directives like this:
extend schema do
directive :link,
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", %{name: "@override", as: "@replace"}]
end
That is because the map is converted to AST and not parsed in that macro.
Related: absinthe-graphql/absinthe#1225
@kzlsakal I'm trying to get this working, and I get Unknown directive
link'.when I add the directive call to my
extend schema` block. I'm using absinthe 1.7.6 and absinthe_federation 0.3.2. Any idea why that might be?
@cschiewek can you double-check to ensure you have use Absinthe.Federation.Schema
? If it's there, would you be able to post your schema file?