https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
m

Maria Sharkina

10/06/2021, 10:46 PM
Hello everyone, we would appreciate some help with the problem below. I am using expedia graphql-kotlin library and dataloaders approach in particular to resolve types, but I am stack on the mutation implementation. I want to use already defined data loader for returning the result type( i want to be able to return full object, not just the part which changed) , but I need to chain the mutation call to happen before resolving the type. Soomething like
Copy code
class ConsumerMutation(
    private val mutateDefaultConsumerAddressUseCase: MutateDefaultConsumerAddress
) : Mutation {

    @GraphQLDescription("Updates default consumer address.")
    fun setDefaultConsumerAddress(env: DataFetchingEnvironment, addressId: String): CompletableFuture<Consumer> 
        return mutateDefaultConsumerAddressUseCase.setDefaultConsumerAddress(env.getContext(), addressId).flatMap {
            //want to reuse ConsumerDataLoader for result fetching
            env.getValueFromMonoDataLoaderWithContext(ConsumerDataLoader::class, addressId).toMono()
        }.toFuture()
    }
}
Do you have any suggestions on how to use dataLoaders inside mutations or is it even a right pattern?
l

Lenny Burdette

10/07/2021, 5:29 AM
i’ve hit this before, and this is how i solved it https://gist.github.com/lennyburdette/f3fe6ae7a498698774cc95d1bfc956b4
m

Maria Sharkina

10/14/2021, 4:33 PM
Thank you @Lenny Burdette. Your answer helped me find a workaround for us.
l

Lenny Burdette

10/14/2021, 4:35 PM
great! glad to hear it
8 Views