You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support to define TypeResolver and DataFetcher for federation entities? #345
My team and I are using graphql-java-kickstart for our kotlin server and want to start using federation.
We succeeded in removing duplicates from the executable schema to pass it into Federation's SchemaTransformer, as will be fixed by the release of this PR provided by @mkaulig.
Now we want to define our entities and their keys in the schema, as described in Apollo's Federation Core Concepts.
When doing so, Federation's SchemaTransformer requires us to provide a TypeResolver for _Entity and DataFetcher for _entities as described here and there is a very basic example here.
I wasn't able to find any support within graphql-java-tools to define the required TypeResolver and DataFetcher. Am I missing something? Is there any support for that in the library?
What I ended up doing for now was to build my own federationEntitiesDictionary as a list of my own EntityDefinition data class:
data classEntityDefinition<T:Any>(
valgraphQlTypeName:String,
valtypeClass:KClass<T>,
valfetchByIdCallable:KFunction<T?>,
valfetcherInstance:Any
)
I populate this dictionary with EntityDefinition objects for every @key annotated type in the schema and use it in the required implementations of the TypeResolver and DataFetcher interfaces.
It is working, but I'm not too fond of my low level approach.
Any feedback if this can be done with graphql-java-tools and how is much appreciated!
Thanks @melo0187 for raising this issue. I am too wondering about documentation with a similar issue. I started working with graphql-java-tools library and really enjoyed working with it. Writing differnt QueryResolvers and Mutations. Then we planned to have Federation support. We added the library with basic functionality _service node. It works absolutely fine with GraphQLSchema generated from graphql-java-tools library and then transformed using Federation api. The problem comes when we want to support Federation schema components like extends, @keys etc. The generated graphql-java-tools schema completely ignores those nodes and hence even after federation transformation, we don't get the _entities type nodes
Verified on master with federation-jvm 6.2.1: a tools-built schema with type Product @key(fields: "upc") keeps @key, and _entities(representations: [{__typename: "Product", upc: "42"}]) resolves. Use includeUnusedTypes(true) so entity types that aren't reachable from Query are kept.
The extend type / @key problem described above is tracked separately:
Activity
azunke commentedon Apr 7, 2020
Thanks @melo0187 for raising this issue. I am too wondering about documentation with a similar issue. I started working with graphql-java-tools library and really enjoyed working with it. Writing differnt QueryResolvers and Mutations. Then we planned to have Federation support. We added the library with basic functionality _service node. It works absolutely fine with GraphQLSchema generated from graphql-java-tools library and then transformed using Federation api. The problem comes when we want to support Federation schema components like extends, @keys etc. The generated graphql-java-tools schema completely ignores those nodes and hence even after federation transformation, we don't get the _entities type nodes
oryan-block commentedon Oct 3, 2026
graphql-java-tools has no federation-specific API; the hooks are federation-jvm's
fetchEntitiesandresolveEntityType:Verified on master with federation-jvm 6.2.1: a tools-built schema with
type Product @key(fields: "upc")keeps@key, and_entities(representations: [{__typename: "Product", upc: "42"}])resolves. UseincludeUnusedTypes(true)so entity types that aren't reachable from Query are kept.The
extend type/@keyproblem described above is tracked separately:extend type X @key(...)are dropped: Type extensions aren't merged: union/enum/interface/scalar extensions replace the base type, directives on object/input extensions are dropped #552. Until that's fixed, declare entities astype X @key(...)(or Fed1type X @key(...) @extends).extend schema @link(...)isn't carried into the schema: Support schema directives #717.Closing.