Skip to content

Support to define TypeResolver and DataFetcher for federation entities? #345

Closed as not planned

Description

@melo0187

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 class EntityDefinition<T : Any>(
    val graphQlTypeName: String,
    val typeClass: KClass<T>,
    val fetchByIdCallable: KFunction<T?>,
    val fetcherInstance: 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!

Activity

  1. azunke commented on Apr 7, 2020

    @azunke

    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

  2. oryan-block commented on Oct 3, 2026

    @oryan-block
    Collaborator

    graphql-java-tools has no federation-specific API; the hooks are federation-jvm's fetchEntities and resolveEntityType:

    Federation.transform(schema)
        .fetchEntities { env -> /* load each representation */ }
        .resolveEntityType { env -> env.schema.getObjectType(env.getObject<Any>().javaClass.simpleName) }
        .build()

    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:

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions