graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Support to define TypeResolver and DataFetcher for federation entities?

Open melo0187 opened this issue 5 years ago • 1 comments

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!

melo0187 avatar Dec 18 '19 09:12 melo0187

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

azunke avatar Apr 07 '20 17:04 azunke