In traditional (i.e. non-federated) GraphQL servers, each one of the output types is accessible through a traversal of the GraphQL schema from a corresponding query, mutation or subscription root type. Since federated GraphQL types might be accessed outside of the query path we need a mechanism to access them in a consistent manner.
A federated GraphQL server provides a custom
_entities query that allows retrieving any of the federated extended types.
_entities query accept list of "representation" objects that provide all required fields to resolve the type and
_Entity union type of all supported federated types. Representation objects are just a map of all the fields
@key directives as well as the target
__typename information. If federated query type fragments also
reference fields with
@provides directives, then those referenced fields should also be specified in
the target representation object.
_entities queries are automatically generated by the federated gateway and their usage is transparent for the gateway clients.
In order to simplify the integrations,
graphql-kotlin-federation provides a default
_entities query resolver that
that is used to resolve the specified
FederatedTypeResolver.typeName specifies the GraphQL type name that should match up to the
__typename field in the
FederatedTypeResolver.resolve accepts a list of representations of the target types which should be resolved in the same order
as they were specified in the list of representations. Each passed in representation should either be resolved to a
target entity or
NULL if entity cannot be resolved.