Absinthe.Federation.Notation.requires_fields
You're seeing just the macro
requires_fields
, go back to Absinthe.Federation.Notation module for more information.
Adds the @requires
directive which is used to annotate the required input fieldset from a base type for a resolver.
It is used to develop a query plan where the required fields may not be needed by the client,
but the service may need additional information from other services.
Example
object :user do
extends()
key_fields("id")
field :id, non_null(:id) do
external()
end
field :email, :string do
external()
end
field :reviews, list_of(:review) do
requires_fields("email")
end
end
SDL Output
# extended from the Users service
type User @key(fields: "id") @extends {
id: ID! @external
email: String @external
reviews: [Review] @requires(fields: "email")
}
In this case, the Reviews service adds new capabilities to the User
type by providing
a list of reviews
related to a User
. In order to fetch these reviews
, the Reviews service needs
to know the email
of the User
from the Users service in order to look up the reviews
.
This means the reviews
field / resolver requires the email
field from the base User
type.