graphql-kotlin
graphql-kotlin copied to clipboard
feat: support returning CompletableFuture FederatedTypeResolver
:pencil: Description
With the idea of proving support for returning a CompletableFuture
in FederatedTypeResolver
a new sealed interface is added
sealed interface TypeResolver {
val typeName: String
}
this will be the basic interface of 2 interfaces
- The currently supported
FederatedTypeResolver
, with support of suspendable function to be executed in a coroutine
interface FederatedTypeResolver<out T> : TypeResolver {
override val typeName: String
suspend fun resolve(
environment: DataFetchingEnvironment,
representations: List<Map<String, Any>>
): List<T?>
}
- A new interface called
FederatedTypePromiseResolver
that will provide support to return aCompletableFuture
allowing compatibility with aDataLoader
interface FederatedTypePromiseResolver<T> : TypeResolver {
fun resolve(
environment: DataFetchingEnvironment,
representations: List<Map<String, Any>>
): CompletableFuture<List<T?>>
}
Clients will have the freedom to decided which interface to use for their resolvers and graphql-kotlin
will be smart enough to decide how to execute them.
The execution logic will be capable of executing suspend resolvers or promise resolvers concurrently, specially useful if you have support for data loaders in only certain entity
example representations for multiple types, request to _entities
field
UserResolver
implementing FederatedTypeResolver
PromiseResolver
implementing FederatedTypePromiseResolver
[
{ "__typename": "User", "userId": 123 },
{ "__typename": "User", "userId": 456 },
{ "__typename": "Author", "authorId": 1 },
{ "__typename": "Author", "authorId": 2 },
]
This might not be a breaking change after all, given that we will keep supporting the FederatedTypeResolver
and we are just modifying the execution logic of resolvers of that interface and the new interface FederatedTypePromiseResolver
:link: Related Issues
https://github.com/ExpediaGroup/graphql-kotlin/issues/1506