From d810318c7ac742080b9565513d09de6d9d584574 Mon Sep 17 00:00:00 2001 From: Franklin Wang Date: Wed, 8 Nov 2023 11:32:21 +1300 Subject: [PATCH] Merge execution hooks --- lib/src/main/java/graphql/nadel/Nadel.kt | 10 ++--- .../main/java/graphql/nadel/NextgenEngine.kt | 8 ++-- .../nadel/engine/NadelExecutionContext.kt | 4 +- .../hydration/NadelHydrationFieldsBuilder.kt | 4 +- .../hydration/NadelHydrationTransform.kt | 29 ++++-------- .../batch/NadelBatchHydrationInputBuilder.kt | 12 ++--- .../hydration/batch/NadelBatchHydrator.kt | 7 --- .../query/DynamicServiceResolution.kt | 6 +-- .../NadelExecutionHooks.kt} | 45 +++++++++++++++++-- .../nadel/hooks/ServiceExecutionHooks.kt | 40 ----------------- ...tching-of-hydration-list-with-partition.kt | 6 +-- .../hooks/dynamic-service-resolution-hooks.kt | 20 ++++----- ...rphic-hydration-hook-using-alias-helper.kt | 11 +++-- .../hooks/polymorphic-hydration-hooks.kt | 24 +++++----- .../nadel/tests/hooks/remove-fields.kt | 42 ++++++++--------- .../hooks/service-context-is-being-set.kt | 4 +- 16 files changed, 122 insertions(+), 150 deletions(-) rename lib/src/main/java/graphql/nadel/{engine/NadelEngineExecutionHooks.kt => hooks/NadelExecutionHooks.kt} (55%) delete mode 100644 lib/src/main/java/graphql/nadel/hooks/ServiceExecutionHooks.kt diff --git a/lib/src/main/java/graphql/nadel/Nadel.kt b/lib/src/main/java/graphql/nadel/Nadel.kt index c4175572e..a5bf23ced 100644 --- a/lib/src/main/java/graphql/nadel/Nadel.kt +++ b/lib/src/main/java/graphql/nadel/Nadel.kt @@ -16,7 +16,7 @@ import graphql.language.Document import graphql.nadel.engine.blueprint.NadelDefaultIntrospectionRunner import graphql.nadel.engine.blueprint.NadelIntrospectionRunnerFactory import graphql.nadel.engine.transform.NadelTransform -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.instrumentation.NadelInstrumentation import graphql.nadel.instrumentation.parameters.NadelInstrumentationCreateStateParameters import graphql.nadel.instrumentation.parameters.NadelInstrumentationQueryExecutionParameters @@ -227,7 +227,7 @@ class Nadel private constructor( class Builder { private var instrumentation: NadelInstrumentation = object : NadelInstrumentation {} - private var serviceExecutionHooks: ServiceExecutionHooks = object : ServiceExecutionHooks {} + private var executionHooks: NadelExecutionHooks = object : NadelExecutionHooks {} private var preparsedDocumentProvider: PreparsedDocumentProvider = NoOpPreparsedDocumentProvider.INSTANCE private var executionIdProvider = ExecutionIdProvider.DEFAULT_EXECUTION_ID_PROVIDER private var transforms = emptyList>() @@ -327,8 +327,8 @@ class Nadel private constructor( return this } - fun serviceExecutionHooks(serviceExecutionHooks: ServiceExecutionHooks): Builder { - this.serviceExecutionHooks = serviceExecutionHooks + fun executionHooks(executionHooks: NadelExecutionHooks): Builder { + this.executionHooks = executionHooks return this } @@ -357,7 +357,7 @@ class Nadel private constructor( engineSchema = engineSchema, querySchema = querySchema, instrumentation = instrumentation, - serviceExecutionHooks = serviceExecutionHooks, + executionHooks = executionHooks, executionIdProvider = executionIdProvider, services = services, transforms = transforms, diff --git a/lib/src/main/java/graphql/nadel/NextgenEngine.kt b/lib/src/main/java/graphql/nadel/NextgenEngine.kt index 8f77d1d7b..98103dff3 100644 --- a/lib/src/main/java/graphql/nadel/NextgenEngine.kt +++ b/lib/src/main/java/graphql/nadel/NextgenEngine.kt @@ -31,7 +31,7 @@ import graphql.nadel.engine.util.newServiceExecutionResult import graphql.nadel.engine.util.provide import graphql.nadel.engine.util.singleOfType import graphql.nadel.engine.util.strictAssociateBy -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.instrumentation.NadelInstrumentation import graphql.nadel.instrumentation.parameters.ErrorData import graphql.nadel.instrumentation.parameters.ErrorType.ServiceExecutionError @@ -63,7 +63,7 @@ internal class NextgenEngine( private val engineSchema: GraphQLSchema, private val querySchema: GraphQLSchema, private val instrumentation: NadelInstrumentation, - private val serviceExecutionHooks: ServiceExecutionHooks, + private val executionHooks: NadelExecutionHooks, private val executionIdProvider: ExecutionIdProvider, maxQueryDepth: Int, services: List, @@ -84,7 +84,7 @@ internal class NextgenEngine( private val resultTransformer = NadelResultTransformer(overallExecutionBlueprint) private val dynamicServiceResolution = DynamicServiceResolution( engineSchema = engineSchema, - serviceExecutionHooks = serviceExecutionHooks, + executionHooks = executionHooks, services = services, ) private val fieldToService = NadelFieldToService( @@ -149,7 +149,7 @@ internal class NextgenEngine( val executionContext = NadelExecutionContext( executionInput, query, - serviceExecutionHooks, + executionHooks, executionHints, instrumentationState, timer, diff --git a/lib/src/main/java/graphql/nadel/engine/NadelExecutionContext.kt b/lib/src/main/java/graphql/nadel/engine/NadelExecutionContext.kt index 3364fda3a..73c12c4b3 100644 --- a/lib/src/main/java/graphql/nadel/engine/NadelExecutionContext.kt +++ b/lib/src/main/java/graphql/nadel/engine/NadelExecutionContext.kt @@ -7,7 +7,7 @@ import graphql.nadel.NadelExecutionHints import graphql.nadel.Service import graphql.nadel.engine.instrumentation.NadelInstrumentationTimer import graphql.nadel.hooks.CreateServiceContextParams -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.normalized.ExecutableNormalizedOperation import java.util.concurrent.CompletableFuture import java.util.concurrent.ConcurrentHashMap @@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap data class NadelExecutionContext internal constructor( val executionInput: ExecutionInput, val query: ExecutableNormalizedOperation, - internal val hooks: ServiceExecutionHooks, + internal val hooks: NadelExecutionHooks, val hints: NadelExecutionHints, val instrumentationState: InstrumentationState?, internal val timer: NadelInstrumentationTimer, diff --git a/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationFieldsBuilder.kt b/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationFieldsBuilder.kt index 1e52fe474..a93ead019 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationFieldsBuilder.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationFieldsBuilder.kt @@ -16,7 +16,7 @@ import graphql.nadel.engine.util.deepClone import graphql.nadel.engine.util.resolveObjectTypes import graphql.nadel.engine.util.toBuilder import graphql.nadel.engine.util.unwrapAll -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.normalized.ExecutableNormalizedField import graphql.normalized.NormalizedInputValue @@ -49,7 +49,7 @@ internal object NadelHydrationFieldsBuilder { aliasHelper: NadelAliasHelper, hydratedField: ExecutableNormalizedField, parentNodes: List, - hooks: ServiceExecutionHooks, + hooks: NadelExecutionHooks, userContext: Any?, ): List { val argBatches = NadelBatchHydrationInputBuilder.getInputValueBatches( diff --git a/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationTransform.kt b/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationTransform.kt index 5c7f68d95..399e4c0d5 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationTransform.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/hydration/NadelHydrationTransform.kt @@ -4,7 +4,6 @@ import graphql.nadel.NextgenEngine import graphql.nadel.Service import graphql.nadel.ServiceExecutionHydrationDetails import graphql.nadel.ServiceExecutionResult -import graphql.nadel.engine.NadelEngineExecutionHooks import graphql.nadel.engine.NadelExecutionContext import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction import graphql.nadel.engine.blueprint.NadelHydrationFieldInstruction @@ -29,7 +28,7 @@ import graphql.nadel.engine.transform.result.json.JsonNodes import graphql.nadel.engine.util.emptyOrSingle import graphql.nadel.engine.util.queryPath import graphql.nadel.engine.util.toBuilder -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.normalized.ExecutableNormalizedField import graphql.schema.FieldCoordinates import kotlinx.coroutines.Deferred @@ -277,26 +276,14 @@ internal class NadelHydrationTransform( private fun getHydrationFieldInstruction( state: State, instructions: List, - hooks: ServiceExecutionHooks, + hooks: NadelExecutionHooks, parentNode: JsonNode, ): NadelHydrationFieldInstruction? { - return when (instructions.size) { - 1 -> instructions.single() - else -> { - if (hooks is NadelEngineExecutionHooks) { - hooks.getHydrationInstruction( - instructions, - parentNode, - state.aliasHelper, - state.executionContext.userContext - ) - } else { - error( - "Cannot decide which hydration instruction should be used. Provided ServiceExecutionHooks has " + - "to be of type NadelEngineExecutionHooks" - ) - } - } - } + return hooks.getHydrationInstruction( + instructions, + parentNode, + state.aliasHelper, + state.executionContext.userContext + ) } } diff --git a/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrationInputBuilder.kt b/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrationInputBuilder.kt index a535e339f..3ece854ed 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrationInputBuilder.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrationInputBuilder.kt @@ -1,6 +1,5 @@ package graphql.nadel.engine.transform.hydration.batch -import graphql.nadel.engine.NadelEngineExecutionHooks import graphql.nadel.engine.blueprint.NadelBatchHydrationFieldInstruction import graphql.nadel.engine.blueprint.hydration.NadelBatchHydrationMatchStrategy import graphql.nadel.engine.blueprint.hydration.NadelHydrationActorInputDef @@ -12,7 +11,7 @@ import graphql.nadel.engine.util.flatten import graphql.nadel.engine.util.javaValueToAstValue import graphql.nadel.engine.util.makeNormalizedInputValue import graphql.nadel.engine.util.mapFrom -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.normalized.ExecutableNormalizedField import graphql.normalized.NormalizedInputValue import graphql.schema.GraphQLTypeUtil @@ -29,7 +28,7 @@ internal object NadelBatchHydrationInputBuilder { instruction: NadelBatchHydrationFieldInstruction, hydrationField: ExecutableNormalizedField, parentNodes: List, - hooks: ServiceExecutionHooks, + hooks: NadelExecutionHooks, userContext: Any?, ): List> { val nonBatchArgs = getNonBatchInputValues(instruction, hydrationField) @@ -73,7 +72,7 @@ internal object NadelBatchHydrationInputBuilder { instruction: NadelBatchHydrationFieldInstruction, parentNodes: List, aliasHelper: NadelAliasHelper, - hooks: ServiceExecutionHooks, + hooks: NadelExecutionHooks, userContext: Any?, ): List> { val batchSize = instruction.batchSize @@ -83,10 +82,7 @@ internal object NadelBatchHydrationInputBuilder { val args = getFieldResultValues(batchInputValueSource, parentNodes, aliasHelper) - val partitionArgumentList = when (hooks) { - is NadelEngineExecutionHooks -> hooks.partitionBatchHydrationArgumentList(args, instruction, userContext) - else -> listOf(args) - } + val partitionArgumentList = hooks.partitionBatchHydrationArgumentList(args, instruction, userContext) return partitionArgumentList.flatMap { it.chunked(size = batchSize) } .map { chunk -> diff --git a/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrator.kt b/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrator.kt index 9bc84cdab..6dcf7903d 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrator.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/hydration/batch/NadelBatchHydrator.kt @@ -3,7 +3,6 @@ package graphql.nadel.engine.transform.hydration.batch import graphql.nadel.NextgenEngine import graphql.nadel.ServiceExecutionHydrationDetails import graphql.nadel.ServiceExecutionResult -import graphql.nadel.engine.NadelEngineExecutionHooks import graphql.nadel.engine.blueprint.NadelBatchHydrationFieldInstruction import graphql.nadel.engine.blueprint.NadelOverallExecutionBlueprint import graphql.nadel.engine.blueprint.hydration.NadelBatchHydrationMatchStrategy @@ -166,12 +165,6 @@ internal class NadelBatchHydrator( instructions: List, parentNode: JsonNode, ): NadelBatchHydrationFieldInstruction? { - if (state.executionContext.hooks !is NadelEngineExecutionHooks) { - error( - "Cannot decide which hydration instruction should be used. " + - "Provided ServiceExecutionHooks has to be of type NadelEngineExecutionHooks" - ) - } return state.executionContext.hooks.getHydrationInstruction( instructions, parentNode, diff --git a/lib/src/main/java/graphql/nadel/engine/transform/query/DynamicServiceResolution.kt b/lib/src/main/java/graphql/nadel/engine/transform/query/DynamicServiceResolution.kt index bb927274b..b24f7a6be 100644 --- a/lib/src/main/java/graphql/nadel/engine/transform/query/DynamicServiceResolution.kt +++ b/lib/src/main/java/graphql/nadel/engine/transform/query/DynamicServiceResolution.kt @@ -5,7 +5,7 @@ import graphql.nadel.Service import graphql.nadel.engine.util.queryPath import graphql.nadel.engine.util.toGraphQLErrorException import graphql.nadel.engine.util.unwrapNonNull -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.schema.NadelDirectives.dynamicServiceDirectiveDefinition import graphql.normalized.ExecutableNormalizedField import graphql.schema.GraphQLInterfaceType @@ -13,7 +13,7 @@ import graphql.schema.GraphQLSchema internal class DynamicServiceResolution( private val engineSchema: GraphQLSchema, - private val serviceExecutionHooks: ServiceExecutionHooks, + private val executionHooks: NadelExecutionHooks, private val services: List, ) { @@ -39,7 +39,7 @@ internal class DynamicServiceResolution( * Resolves the service for a field */ fun resolveServiceForField(field: ExecutableNormalizedField): Service { - val serviceOrError = serviceExecutionHooks.resolveServiceForField(services, field) + val serviceOrError = executionHooks.resolveServiceForField(services, field) ?: throw GraphqlErrorException.newErrorException() .message("Could not resolve service for field '${field.name}'") .path(field.queryPath.segments) diff --git a/lib/src/main/java/graphql/nadel/engine/NadelEngineExecutionHooks.kt b/lib/src/main/java/graphql/nadel/hooks/NadelExecutionHooks.kt similarity index 55% rename from lib/src/main/java/graphql/nadel/engine/NadelEngineExecutionHooks.kt rename to lib/src/main/java/graphql/nadel/hooks/NadelExecutionHooks.kt index 37fc36d92..b7a6e495c 100644 --- a/lib/src/main/java/graphql/nadel/engine/NadelEngineExecutionHooks.kt +++ b/lib/src/main/java/graphql/nadel/hooks/NadelExecutionHooks.kt @@ -1,18 +1,55 @@ -package graphql.nadel.engine +package graphql.nadel.hooks +import graphql.nadel.Service import graphql.nadel.engine.blueprint.NadelBatchHydrationFieldInstruction import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction import graphql.nadel.engine.transform.artificial.NadelAliasHelper import graphql.nadel.engine.transform.result.json.JsonNode -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.normalized.ExecutableNormalizedField +import java.util.concurrent.CompletableFuture + +/** + * These hooks allow you to change the way service execution happens + */ +interface NadelExecutionHooks { + /** + * Called per top level field for a service. This allows you to create a "context" object that will be passed into further calls. + * + * @param params the parameters to this call + * @return an async context object of your choosing + */ + fun createServiceContext(params: CreateServiceContextParams): CompletableFuture { + return CompletableFuture.completedFuture(null) + } + + /** + * Called to resolve the service that should be used to fetch data for a field that uses dynamic service resolution. + * + * + * There are 2 versions of this method. One passing an [ExecutionStepInfo], which is used by the CurrentGen + * engine, and another passing [ExecutableNormalizedField], used by the NextGen engine. During the transition + * between Current and NextGen, implementations of [NadelExecutionHooks] will have to implement both + * versions of this method. + * + * @param services a collection of all services registered on Nadel + * @param executableNormalizedField object containing data about the field being executed + * @return the Service that should be used to fetch data for that field or an error that was raised when trying to resolve the service. + */ + fun resolveServiceForField( + services: List, + executableNormalizedField: ExecutableNormalizedField, + ): ServiceOrError? { + return null + } -interface NadelEngineExecutionHooks : ServiceExecutionHooks { fun getHydrationInstruction( instructions: List, parentNode: JsonNode, aliasHelper: NadelAliasHelper, userContext: Any?, - ): T? + ): T? { + return instructions.single() + } /** * This method should be used when the list of hydration arguments needs to be split in batches. The batches will be diff --git a/lib/src/main/java/graphql/nadel/hooks/ServiceExecutionHooks.kt b/lib/src/main/java/graphql/nadel/hooks/ServiceExecutionHooks.kt deleted file mode 100644 index 032f4ea2b..000000000 --- a/lib/src/main/java/graphql/nadel/hooks/ServiceExecutionHooks.kt +++ /dev/null @@ -1,40 +0,0 @@ -package graphql.nadel.hooks - -import graphql.nadel.Service -import graphql.normalized.ExecutableNormalizedField -import java.util.concurrent.CompletableFuture - -/** - * These hooks allow you to change the way service execution happens - */ -interface ServiceExecutionHooks { - /** - * Called per top level field for a service. This allows you to create a "context" object that will be passed into further calls. - * - * @param params the parameters to this call - * @return an async context object of your choosing - */ - fun createServiceContext(params: CreateServiceContextParams): CompletableFuture { - return CompletableFuture.completedFuture(null) - } - - /** - * Called to resolve the service that should be used to fetch data for a field that uses dynamic service resolution. - * - * - * There are 2 versions of this method. One passing an [ExecutionStepInfo], which is used by the CurrentGen - * engine, and another passing [ExecutableNormalizedField], used by the NextGen engine. During the transition - * between Current and NextGen, implementations of [ServiceExecutionHooks] will have to implement both - * versions of this method. - * - * @param services a collection of all services registered on Nadel - * @param executableNormalizedField object containing data about the field being executed - * @return the Service that should be used to fetch data for that field or an error that was raised when trying to resolve the service. - */ - fun resolveServiceForField( - services: List, - executableNormalizedField: ExecutableNormalizedField, - ): ServiceOrError? { - return null - } -} diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/batching-of-hydration-list-with-partition.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/batching-of-hydration-list-with-partition.kt index bd3cccb57..1e690ddfa 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/batching-of-hydration-list-with-partition.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/batching-of-hydration-list-with-partition.kt @@ -1,15 +1,15 @@ package graphql.nadel.tests.hooks import graphql.nadel.Nadel -import graphql.nadel.engine.NadelEngineExecutionHooks import graphql.nadel.engine.blueprint.NadelBatchHydrationFieldInstruction import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction import graphql.nadel.engine.transform.artificial.NadelAliasHelper import graphql.nadel.engine.transform.result.json.JsonNode +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook -private class BatchHydrationHooks : NadelEngineExecutionHooks { +private class BatchHydrationHooks : NadelExecutionHooks { override fun getHydrationInstruction( instructions: List, parentNode: JsonNode, @@ -33,6 +33,6 @@ private class BatchHydrationHooks : NadelEngineExecutionHooks { @UseHook class `batching-of-hydration-list-with-partition` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(BatchHydrationHooks()) + return builder.executionHooks(BatchHydrationHooks()) } } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/dynamic-service-resolution-hooks.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/dynamic-service-resolution-hooks.kt index ecc8bdfb0..d0ebd11fd 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/dynamic-service-resolution-hooks.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/dynamic-service-resolution-hooks.kt @@ -5,13 +5,13 @@ import graphql.GraphqlErrorBuilder import graphql.execution.ResultPath import graphql.nadel.Nadel import graphql.nadel.Service -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.hooks.ServiceOrError import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook import graphql.normalized.ExecutableNormalizedField -class Hooks : ServiceExecutionHooks { +class Hooks : NadelExecutionHooks { private fun resolveServiceGeneric( services: Collection, @@ -58,55 +58,55 @@ class Hooks : ServiceExecutionHooks { @UseHook class `dynamic-service-resolution-multiple-services` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `dynamic-service-resolution-simple-success-case` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `dynamic-service-resolution-multiple-services-with-one-unmapped-node-lookup` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `dynamic-service-resolution-handles-inline-fragments-from-multiple-services` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `dynamic-service-resolution-handles-complex-fragments` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `dynamic-service-resolution-with-no-fragments` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `dynamic-service-resolution-directive-not-in-interface` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } @UseHook class `typename-is-passed-on-queries-using-dynamic-resolved-services` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(Hooks()) + return builder.executionHooks(Hooks()) } } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hook-using-alias-helper.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hook-using-alias-helper.kt index f37dd52d1..54332fcc5 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hook-using-alias-helper.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hook-using-alias-helper.kt @@ -1,22 +1,21 @@ package graphql.nadel.tests.hooks import graphql.nadel.Nadel -import graphql.nadel.engine.NadelEngineExecutionHooks import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction import graphql.nadel.engine.blueprint.hydration.NadelHydrationActorInputDef import graphql.nadel.engine.transform.artificial.NadelAliasHelper import graphql.nadel.engine.transform.result.json.JsonNode import graphql.nadel.engine.util.JsonMap +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook -private class PolymorphicHydrationHookUsingAliasHelper : NadelEngineExecutionHooks { - +private class PolymorphicHydrationHookUsingAliasHelper : NadelExecutionHooks { override fun getHydrationInstruction( instructions: List, parentNode: JsonNode, aliasHelper: NadelAliasHelper, - userContext: Any? + userContext: Any?, ): T? { return instructions.firstOrNull { val (_, _, valueSource) = it.actorInputValueDefs.single() @@ -32,7 +31,7 @@ private class PolymorphicHydrationHookUsingAliasHelper : NadelEngineExecutionHoo private fun hydrationInstructionMatchesArgumentValue( instruction: T, - hydrationArgumentValue: String + hydrationArgumentValue: String, ): Boolean { return instruction.actorFieldDef.name.contains("pet") && hydrationArgumentValue.startsWith( "pet", ignoreCase = true @@ -45,7 +44,7 @@ private class PolymorphicHydrationHookUsingAliasHelper : NadelEngineExecutionHoo open class PolymorphicHydrationWithAliasTestHook : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(PolymorphicHydrationHookUsingAliasHelper()) + return builder.executionHooks(PolymorphicHydrationHookUsingAliasHelper()) } } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hooks.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hooks.kt index 11c2c6ea9..8351e3bca 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hooks.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/polymorphic-hydration-hooks.kt @@ -1,16 +1,16 @@ package graphql.nadel.tests.hooks import graphql.nadel.Nadel -import graphql.nadel.engine.NadelEngineExecutionHooks import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction import graphql.nadel.engine.blueprint.NadelHydrationFieldInstruction import graphql.nadel.engine.transform.artificial.NadelAliasHelper import graphql.nadel.engine.transform.result.json.JsonNode import graphql.nadel.engine.util.JsonMap +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook -private class PolymorphicHydrationHooks : NadelEngineExecutionHooks { +private class PolymorphicHydrationHooks : NadelExecutionHooks { override fun getHydrationInstruction( instructions: List, parentNode: JsonNode, @@ -33,33 +33,33 @@ private class PolymorphicHydrationHooks : NadelEngineExecutionHooks { open class PolymorphicHydrationTestHook : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder.serviceExecutionHooks(PolymorphicHydrationHooks()) + return builder.executionHooks(PolymorphicHydrationHooks()) } } @UseHook -class `solitary-polymorphic-hydration` : PolymorphicHydrationTestHook() {} +class `solitary-polymorphic-hydration` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-with-interfaces` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-with-interfaces` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-with-unions` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-with-unions` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-with-rename` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-with-rename` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-where-only-one-type-is-queried` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-where-only-one-type-is-queried` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-when-hook-returns-null` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-when-hook-returns-null` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-when-hook-returns-null-1` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-when-hook-returns-null-1` : PolymorphicHydrationTestHook() @UseHook -class `solitary-polymorphic-hydration-when-hook-returns-null` : PolymorphicHydrationTestHook() {} +class `solitary-polymorphic-hydration-when-hook-returns-null` : PolymorphicHydrationTestHook() @UseHook -class `batch-polymorphic-hydration-with-lots-of-renames` : PolymorphicHydrationTestHook() {} +class `batch-polymorphic-hydration-with-lots-of-renames` : PolymorphicHydrationTestHook() diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/remove-fields.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/remove-fields.kt index ce8e52abd..670c5a0ae 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/remove-fields.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/remove-fields.kt @@ -3,11 +3,11 @@ package graphql.nadel.tests.hooks import graphql.ErrorClassification import graphql.GraphQLError import graphql.nadel.Nadel -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.tests.EngineTestHook import graphql.GraphqlErrorException as GraphQLErrorException -private class RejectField(private val fieldNames: List) : ServiceExecutionHooks { +private class RejectField(private val fieldNames: List) : NadelExecutionHooks { constructor(vararg fieldNames: String) : this(fieldNames.toList()) // override fun isFieldForbidden( @@ -48,7 +48,7 @@ private class RejectField(private val fieldNames: List) : ServiceExecuti class `hydrated-field-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("author")) + .executionHooks(RejectField("author")) } } @@ -56,7 +56,7 @@ class `hydrated-field-is-removed` : EngineTestHook { class `nested-hydrated-field-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("author")) + .executionHooks(RejectField("author")) } } @@ -64,7 +64,7 @@ class `nested-hydrated-field-is-removed` : EngineTestHook { class `field-is-removed-from-nested-hydrated-field` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("userId")) + .executionHooks(RejectField("userId")) } } @@ -72,7 +72,7 @@ class `field-is-removed-from-nested-hydrated-field` : EngineTestHook { class `all-fields-in-a-selection-set-are-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("title", "description")) + .executionHooks(RejectField("title", "description")) } } @@ -80,7 +80,7 @@ class `all-fields-in-a-selection-set-are-removed` : EngineTestHook { class `field-in-a-selection-set-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("title")) + .executionHooks(RejectField("title")) } } @@ -88,7 +88,7 @@ class `field-in-a-selection-set-is-removed` : EngineTestHook { class `one-of-top-level-fields-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("commentById")) + .executionHooks(RejectField("commentById")) } } @@ -96,7 +96,7 @@ class `one-of-top-level-fields-is-removed` : EngineTestHook { class `top-level-field-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("commentById")) + .executionHooks(RejectField("commentById")) } } @@ -104,7 +104,7 @@ class `top-level-field-is-removed` : EngineTestHook { class `top-level-field-in-batched-query-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("comments")) + .executionHooks(RejectField("comments")) } } @@ -112,7 +112,7 @@ class `top-level-field-in-batched-query-is-removed` : EngineTestHook { class `all-fields-are-removed-from-hydrated-field` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("userId", "displayName")) + .executionHooks(RejectField("userId", "displayName")) } } @@ -120,7 +120,7 @@ class `all-fields-are-removed-from-hydrated-field` : EngineTestHook { class `field-is-removed-from-hydrated-field` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("userId")) + .executionHooks(RejectField("userId")) } } @@ -128,7 +128,7 @@ class `field-is-removed-from-hydrated-field` : EngineTestHook { class `all-non-hydrated-fields-in-query-are-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("id", "created", "commentText")) + .executionHooks(RejectField("id", "created", "commentText")) } } @@ -136,7 +136,7 @@ class `all-non-hydrated-fields-in-query-are-removed` : EngineTestHook { class `field-with-selections-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("epic")) + .executionHooks(RejectField("epic")) } } @@ -144,7 +144,7 @@ class `field-with-selections-is-removed` : EngineTestHook { class `the-only-field-in-a-selection-set-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("title")) + .executionHooks(RejectField("title")) } } @@ -152,7 +152,7 @@ class `the-only-field-in-a-selection-set-is-removed` : EngineTestHook { class `field-in-non-hydrated-query-is-removed` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("created")) + .executionHooks(RejectField("created")) } } @@ -160,7 +160,7 @@ class `field-in-non-hydrated-query-is-removed` : EngineTestHook { class `restricted-field-inside-hydration-via-fragments-used-twice` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("restricted")) + .executionHooks(RejectField("restricted")) } } @@ -168,7 +168,7 @@ class `restricted-field-inside-hydration-via-fragments-used-twice` : EngineTestH class `restricted-field-via-fragments-used-twice` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("restricted")) + .executionHooks(RejectField("restricted")) } } @@ -176,7 +176,7 @@ class `restricted-field-via-fragments-used-twice` : EngineTestHook { class `inserts-one-error-for-a-forbidden-field-in-a-list` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(RejectField("restricted")) + .executionHooks(RejectField("restricted")) } } @@ -184,7 +184,7 @@ class `inserts-one-error-for-a-forbidden-field-in-a-list` : EngineTestHook { class `restricted-single-field-inside-hydration-via-fragments-used-twice` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(object : ServiceExecutionHooks { + .executionHooks(object : NadelExecutionHooks { // override fun isFieldForbidden( // normalizedField: NormalizedQueryField, // hydrationArguments: HydrationArguments, @@ -210,7 +210,7 @@ class `restricted-single-field-inside-hydration-via-fragments-used-twice` : Engi class `restricted-single-field-via-fragments-used-twice` : EngineTestHook { override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionHooks(object : ServiceExecutionHooks { + .executionHooks(object : NadelExecutionHooks { // override fun isFieldForbidden( // normalizedField: NormalizedQueryField, // hydrationArguments: HydrationArguments, diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/service-context-is-being-set.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/service-context-is-being-set.kt index dc43435b9..25a100e9f 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/service-context-is-being-set.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/service-context-is-being-set.kt @@ -4,7 +4,7 @@ import graphql.nadel.Nadel import graphql.nadel.ServiceExecution import graphql.nadel.ServiceExecutionFactory import graphql.nadel.hooks.CreateServiceContextParams -import graphql.nadel.hooks.ServiceExecutionHooks +import graphql.nadel.hooks.NadelExecutionHooks import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook import graphql.nadel.tests.util.serviceExecutionFactory @@ -16,7 +16,7 @@ class `service-context-is-being-set` : EngineTestHook { val serviceExecutionFactory = builder.serviceExecutionFactory return builder - .serviceExecutionHooks(object : ServiceExecutionHooks { + .executionHooks(object : NadelExecutionHooks { override fun createServiceContext(params: CreateServiceContextParams): CompletableFuture { return CompletableFuture.completedFuture("Context for ${params.service.name}") }