Skip to content

Commit

Permalink
additional renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily Dobervich committed Feb 26, 2024
1 parent 0e0c6c4 commit 5383236
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ open class DgsAutoConfiguration(
matchIfMissing = true
)
@Order(0)
open fun dgsWrapWithContextDataLoaderScanningInterceptor(): DgsWrapWithContextDataLoaderCustomizer {
open fun dgsWrapWithContextDataLoaderCustomizer(): DgsWrapWithContextDataLoaderCustomizer {
return DgsWrapWithContextDataLoaderCustomizer()
}

@Bean
@Order(100)
open fun dgsSimpleDataLoaderInstrumentationDataLoaderScanningInterceptor(
instrumentations: List<DgsDataLoaderInstrumentation<*>>
): DgsSimpleDataLoaderInstrumentationDataLoaderCustomizer {
return DgsSimpleDataLoaderInstrumentationDataLoaderCustomizer(instrumentations)
open fun dgsDataLoaderInstrumentationDataLoaderCustomizer(
instrumentations: List<DgsDataLoaderInstrumentation>
): DgsDataLoaderInstrumentationDataLoaderCustomizer {
return DgsDataLoaderInstrumentationDataLoaderCustomizer(instrumentations)
}

@Bean
Expand All @@ -194,7 +194,7 @@ open class DgsAutoConfiguration(
dataloaderOptionProvider: DgsDataLoaderOptionsProvider,
@Qualifier("dgsScheduledExecutorService") dgsScheduledExecutorService: ScheduledExecutorService,
extensionProviders: List<DataLoaderInstrumentationExtensionProvider>,
scanningInterceptors: List<DgsDataLoaderCustomizer>
customizers: List<DgsDataLoaderCustomizer>
): DgsDataLoaderProvider {
return DgsDataLoaderProvider(
applicationContext = applicationContext,
Expand All @@ -203,7 +203,7 @@ open class DgsAutoConfiguration(
scheduledExecutorService = dgsScheduledExecutorService,
scheduleDuration = dataloaderConfigProps.scheduleDuration,
enableTickerMode = dataloaderConfigProps.tickerModeEnabled,
scanningInterceptors = scanningInterceptors
customizers = customizers
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package com.netflix.graphql.dgs.exceptions

class DgsSimpleDataLoaderInstrumentationException(name: String) : RuntimeException("data loader `$name` is not a MappedBatchLoaderWithContext or BatchLoaderWithContext. Is dgs.graphql.convertAllDataLoadersToWithContext.enabled set to false?")
class DgsDataLoaderInstrumentationException(name: String) : RuntimeException("data loader `$name` is not a MappedBatchLoaderWithContext or BatchLoaderWithContext. Is dgs.graphql.convertAllDataLoadersToWithContext.enabled set to false?")
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ package com.netflix.graphql.dgs.internal

import com.netflix.graphql.dgs.DgsDataLoaderCustomizer
import com.netflix.graphql.dgs.DgsDataLoaderInstrumentation
import com.netflix.graphql.dgs.exceptions.DgsSimpleDataLoaderInstrumentationException
import com.netflix.graphql.dgs.exceptions.DgsDataLoaderInstrumentationException
import org.dataloader.BatchLoader
import org.dataloader.BatchLoaderEnvironment
import org.dataloader.BatchLoaderWithContext
import org.dataloader.MappedBatchLoader
import org.dataloader.MappedBatchLoaderWithContext
import java.util.concurrent.CompletionStage

class DgsSimpleDataLoaderInstrumentationDataLoaderCustomizer(
class DgsDataLoaderInstrumentationDataLoaderCustomizer(
private val instrumentations: List<DgsDataLoaderInstrumentation>
) : DgsDataLoaderCustomizer {
override fun provide(original: BatchLoader<*, *>, name: String): Any {
throw DgsSimpleDataLoaderInstrumentationException(name)
throw DgsDataLoaderInstrumentationException(name)
}

override fun provide(original: BatchLoaderWithContext<*, *>, name: String): Any {
return BatchLoaderWithContextSimpleInstrumentationDriver(original, name, instrumentations)
return BatchLoaderWithContextInstrumentationDriver(original, name, instrumentations)
}

override fun provide(original: MappedBatchLoader<*, *>, name: String): Any {
throw DgsSimpleDataLoaderInstrumentationException(name)
throw DgsDataLoaderInstrumentationException(name)
}

override fun provide(original: MappedBatchLoaderWithContext<*, *>, name: String): Any {
return MappedBatchLoaderWithContextSimpleInstrumentationDriver(original, name, instrumentations)
return MappedBatchLoaderWithContextInstrumentationDriver(original, name, instrumentations)
}
}

internal class BatchLoaderWithContextSimpleInstrumentationDriver<K : Any, V>(
internal class BatchLoaderWithContextInstrumentationDriver<K : Any, V>(
private val original: BatchLoaderWithContext<K, V>,
private val name: String,
private val instrumentations: List<DgsDataLoaderInstrumentation>
Expand All @@ -66,7 +66,7 @@ internal class BatchLoaderWithContextSimpleInstrumentationDriver<K : Any, V>(
}
}

internal class MappedBatchLoaderWithContextSimpleInstrumentationDriver<K : Any, V>(
internal class MappedBatchLoaderWithContextInstrumentationDriver<K : Any, V>(
private val original: MappedBatchLoaderWithContext<K, V>,
private val name: String,
private val instrumentations: List<DgsDataLoaderInstrumentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import kotlin.system.measureTimeMillis
class DgsDataLoaderProvider(
private val applicationContext: ApplicationContext,
private val extensionProviders: List<DataLoaderInstrumentationExtensionProvider> = listOf(),
private val scanningInterceptors: List<DgsDataLoaderCustomizer> = listOf(),
private val customizers: List<DgsDataLoaderCustomizer> = listOf(),
private val dataLoaderOptionsProvider: DgsDataLoaderOptionsProvider = DefaultDataLoaderOptionsProvider(),
private val scheduledExecutorService: ScheduledExecutorService = Executors.newSingleThreadScheduledExecutor(),
private val scheduleDuration: Duration = Duration.ofMillis(10),
Expand Down Expand Up @@ -108,7 +108,7 @@ class DgsDataLoaderProvider(
}

fun <T : Any> createHolder(t: T): LoaderHolder<T> = LoaderHolder(t, annotation, annotation.name)
when (val dataLoader = runScanningInterceptors(field.get(dgsComponent), annotation.name, dgsComponent::class.java)) {
when (val dataLoader = runCustomizers(field.get(dgsComponent), annotation.name, dgsComponent::class.java)) {
is BatchLoader<*, *> -> batchLoaders.add(createHolder(dataLoader))
is BatchLoaderWithContext<*, *> -> batchLoadersWithContext.add(createHolder(dataLoader))
is MappedBatchLoader<*, *> -> mappedBatchLoaders.add(createHolder(dataLoader))
Expand Down Expand Up @@ -142,7 +142,7 @@ class DgsDataLoaderProvider(
fun <T : Any> createHolder(t: T): LoaderHolder<T> =
LoaderHolder(t, annotation, DataLoaderNameUtil.getDataLoaderName(targetClass, annotation), dispatchPredicate)

when (val dataLoader = runScanningInterceptors(dgsComponent, name, dgsComponent::class.java)) {
when (val dataLoader = runCustomizers(dgsComponent, name, dgsComponent::class.java)) {
is BatchLoader<*, *> -> batchLoaders.add(createHolder(dataLoader))
is BatchLoaderWithContext<*, *> -> batchLoadersWithContext.add(createHolder(dataLoader))
is MappedBatchLoader<*, *> -> mappedBatchLoaders.add(createHolder(dataLoader))
Expand All @@ -151,10 +151,10 @@ class DgsDataLoaderProvider(
}
}

private fun runScanningInterceptors(originalDataLoader: Any, name: String, dgsComponentClass: Class<*>): Any {
private fun runCustomizers(originalDataLoader: Any, name: String, dgsComponentClass: Class<*>): Any {
var dataLoader = originalDataLoader

scanningInterceptors.forEach {
customizers.forEach {
dataLoader = when (dataLoader) {
is BatchLoader<*, *> -> it.provide(dataLoader as BatchLoader<*, *>, name)
is BatchLoaderWithContext<*, *> -> it.provide(dataLoader as BatchLoaderWithContext<*, *>, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.netflix.graphql.dgs

import com.netflix.graphql.dgs.internal.DgsDataLoaderProvider
import com.netflix.graphql.dgs.internal.DgsSimpleDataLoaderInstrumentationDataLoaderCustomizer
import com.netflix.graphql.dgs.internal.DgsDataLoaderInstrumentationDataLoaderCustomizer
import com.netflix.graphql.dgs.internal.DgsWrapWithContextDataLoaderCustomizer
import org.assertj.core.api.Assertions.assertThat
import org.dataloader.BatchLoaderEnvironment
Expand Down Expand Up @@ -53,7 +53,7 @@ class DgsDataLoaderInstrumentationTest {

applicationContextRunner.withBean(ExampleBatchLoaderWithoutName::class.java)
.withBean(DgsWrapWithContextDataLoaderCustomizer::class.java)
.withBean(DgsSimpleDataLoaderInstrumentationDataLoaderCustomizer::class.java)
.withBean(DgsDataLoaderInstrumentationDataLoaderCustomizer::class.java)
.withBean(TestDataLoaderInstrumentation::class.java, beforeCounter, afterCounter, exceptionCounter).run { context ->
val provider = context.getBean(DgsDataLoaderProvider::class.java)
val dataLoaderRegistry = provider.buildRegistry()
Expand All @@ -75,7 +75,7 @@ class DgsDataLoaderInstrumentationTest {

applicationContextRunner.withBean(ExampleBatchLoaderThatThrows::class.java)
.withBean(DgsWrapWithContextDataLoaderCustomizer::class.java)
.withBean(DgsSimpleDataLoaderInstrumentationDataLoaderCustomizer::class.java)
.withBean(DgsDataLoaderInstrumentationDataLoaderCustomizer::class.java)
.withBean(TestDataLoaderInstrumentation::class.java, beforeCounter, afterCounter, exceptionCounter).run { context ->
val provider = context.getBean(DgsDataLoaderProvider::class.java)
val dataLoaderRegistry = provider.buildRegistry()
Expand Down

0 comments on commit 5383236

Please sign in to comment.