Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
eocantu committed Jun 20, 2024
1 parent 690cb26 commit f3e1ae6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies {
api(libs.graphql.java) {
exclude(group = "com.graphql-java", module = "java-dataloader")
}
testImplementation(projects.graphqlKotlinServer)
testImplementation(libs.reactor.core)
testImplementation(libs.reactor.extensions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import com.expediagroup.graphql.dataloader.instrumentation.fixture.domain.Missio
import com.expediagroup.graphql.dataloader.instrumentation.fixture.domain.Planet
import com.expediagroup.graphql.dataloader.instrumentation.fixture.extensions.toListOfNullables
import com.expediagroup.graphql.dataloader.instrumentation.fixture.repository.AstronautRepository
import com.expediagroup.graphql.server.exception.MissingDataLoaderException
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
import com.expediagroup.graphql.server.extensions.getValuesFromDataLoader
import graphql.GraphQLContext
import graphql.schema.DataFetchingEnvironment
import org.dataloader.DataLoader
Expand Down Expand Up @@ -60,7 +57,9 @@ class AstronautService {
request: AstronautServiceRequest,
environment: DataFetchingEnvironment
): CompletableFuture<Astronaut> =
environment.getValueFromDataLoader("AstronautDataLoader", request)
environment
.getDataLoader<AstronautServiceRequest, Astronaut>("AstronautDataLoader")
?.load(request) ?: throw IllegalArgumentException("No data loader called AstronautDataLoader was found")

fun createAstronaut(
request: CreateAstronautServiceRequest
Expand All @@ -72,7 +71,9 @@ class AstronautService {
environment: DataFetchingEnvironment
): CompletableFuture<List<Astronaut?>> = when {
requests.isNotEmpty() -> {
environment.getValuesFromDataLoader("AstronautDataLoader", requests)
environment
.getDataLoader<AstronautServiceRequest, Astronaut>("AstronautDataLoader")
?.loadMany(requests) ?: throw IllegalArgumentException("No data loader called AstronautDataLoader was found")
}
else -> {
AstronautRepository
Expand All @@ -88,9 +89,9 @@ class AstronautService {
environment: DataFetchingEnvironment
): CompletableFuture<List<Planet>> {
val missionsByAstronautDataLoader = environment.getDataLoader<MissionServiceRequest, List<Mission>>("MissionsByAstronautDataLoader")
?: throw MissingDataLoaderException("MissionsByAstronautDataLoader")
?: throw IllegalArgumentException("No data loader called MissionsByAstronautDataLoader was found")
val planetsByMissionDataLoader = environment.getDataLoader<PlanetServiceRequest, List<Planet>>("PlanetsByMissionDataLoader")
?: throw MissingDataLoaderException("PlanetsByMissionDataLoader")
?: throw IllegalArgumentException("No data loader called PlanetsByMissionDataLoader was found")
return missionsByAstronautDataLoader
.load(MissionServiceRequest(0, astronautId = request.id))
.thenCompose { missions ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import com.expediagroup.graphql.dataloader.KotlinDataLoader
import com.expediagroup.graphql.dataloader.instrumentation.fixture.domain.Mission
import com.expediagroup.graphql.dataloader.instrumentation.fixture.extensions.toListOfNullables
import com.expediagroup.graphql.dataloader.instrumentation.fixture.repository.MissionRepository
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
import com.expediagroup.graphql.server.extensions.getValuesFromDataLoader
import graphql.GraphQLContext
import graphql.schema.DataFetchingEnvironment
import org.dataloader.DataLoader
Expand Down Expand Up @@ -66,14 +64,18 @@ class MissionService {
request: MissionServiceRequest,
environment: DataFetchingEnvironment
): CompletableFuture<Mission> =
environment.getValueFromDataLoader("MissionDataLoader", request)
environment
.getDataLoader<MissionServiceRequest, Mission>("MissionDataLoader")
?.load(request) ?: throw IllegalArgumentException("No data loader called MissionDataLoader was found")

fun getMissions(
requests: List<MissionServiceRequest>,
environment: DataFetchingEnvironment
): CompletableFuture<List<Mission?>> = when {
requests.isNotEmpty() -> {
environment.getValuesFromDataLoader("MissionDataLoader", requests)
environment
.getDataLoader<MissionServiceRequest, Mission>("MissionDataLoader")
?.loadMany(requests) ?: throw IllegalArgumentException("No data loader called MissionDataLoader was found")
}
else -> {
MissionRepository
Expand All @@ -88,5 +90,7 @@ class MissionService {
request: MissionServiceRequest,
environment: DataFetchingEnvironment
): CompletableFuture<List<Mission>> =
environment.getValueFromDataLoader("MissionsByAstronautDataLoader", request)
environment
.getDataLoader<MissionServiceRequest, List<Mission>>("MissionsByAstronautDataLoader")
?.load(request) ?: throw IllegalArgumentException("No data loader called MissionsByAstronautDataLoader was found")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.expediagroup.graphql.dataloader.instrumentation.fixture.datafetcher
import com.expediagroup.graphql.dataloader.KotlinDataLoader
import com.expediagroup.graphql.dataloader.instrumentation.fixture.domain.Planet
import com.expediagroup.graphql.dataloader.instrumentation.fixture.repository.PlanetRepository
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
import graphql.GraphQLContext
import graphql.schema.DataFetchingEnvironment
import org.dataloader.DataLoader
Expand Down Expand Up @@ -49,5 +48,7 @@ class PlanetService {
request: PlanetServiceRequest,
environment: DataFetchingEnvironment
): CompletableFuture<List<Planet>> =
environment.getValueFromDataLoader("PlanetsByMissionDataLoader", request)
environment
.getDataLoader<PlanetServiceRequest, List<Planet>>("PlanetsByMissionDataLoader")
?.load(request) ?: throw IllegalStateException("No data loader called PlanetsByMissionDataLoader was found")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.expediagroup.graphql.dataloader.KotlinDataLoader
import com.expediagroup.graphql.dataloader.instrumentation.fixture.domain.Product
import com.expediagroup.graphql.dataloader.instrumentation.fixture.extensions.toListOfNullables
import com.expediagroup.graphql.dataloader.instrumentation.fixture.repository.ProductRepository
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
import graphql.GraphQLContext
import graphql.schema.DataFetchingEnvironment
import org.dataloader.DataLoader
Expand Down Expand Up @@ -52,5 +51,7 @@ class ProductService {
request: ProductServiceRequest,
environment: DataFetchingEnvironment
): CompletableFuture<Product> =
environment.getValueFromDataLoader("ProductDataLoader", request)
environment
.getDataLoader<ProductServiceRequest, Product>("ProductDataLoader")
?.load(request) ?: throw IllegalStateException("No data loader called ProductDataLoader was found")
}

0 comments on commit f3e1ae6

Please sign in to comment.