diff --git a/lib/src/main/java/graphql/nadel/engine/util/NadelPseudoSealedType.kt b/lib/src/main/java/graphql/nadel/engine/util/NadelPseudoSealedType.kt index 38ee69db7..68e62a24f 100644 --- a/lib/src/main/java/graphql/nadel/engine/util/NadelPseudoSealedType.kt +++ b/lib/src/main/java/graphql/nadel/engine/util/NadelPseudoSealedType.kt @@ -10,13 +10,17 @@ import graphql.schema.GraphQLFieldsContainer import graphql.schema.GraphQLInputObjectType import graphql.schema.GraphQLInputType import graphql.schema.GraphQLInterfaceType +import graphql.schema.GraphQLList import graphql.schema.GraphQLNamedType +import graphql.schema.GraphQLNonNull import graphql.schema.GraphQLObjectType import graphql.schema.GraphQLOutputType import graphql.schema.GraphQLScalarType +import graphql.schema.GraphQLType import graphql.schema.GraphQLUnionType +import graphql.schema.GraphQLUnmodifiedType -internal inline fun GraphQLFieldsContainer.whenType( +inline fun GraphQLFieldsContainer.whenType( interfaceType: (GraphQLInterfaceType) -> T, objectType: (GraphQLObjectType) -> T, ): T { @@ -27,7 +31,7 @@ internal inline fun GraphQLFieldsContainer.whenType( } } -internal inline fun GraphQLNamedType.whenType( +inline fun GraphQLNamedType.whenType( enumType: (GraphQLEnumType) -> T, inputObjectType: (GraphQLInputObjectType) -> T, interfaceType: (GraphQLInterfaceType) -> T, @@ -46,7 +50,7 @@ internal inline fun GraphQLNamedType.whenType( } } -internal inline fun GraphQLOutputType.whenUnmodifiedType( +inline fun GraphQLOutputType.whenUnmodifiedType( enumType: (GraphQLEnumType) -> T, interfaceType: (GraphQLInterfaceType) -> T, objectType: (GraphQLObjectType) -> T, @@ -63,7 +67,7 @@ internal inline fun GraphQLOutputType.whenUnmodifiedType( } } -internal inline fun GraphQLInputType.whenUnmodifiedType( +inline fun GraphQLInputType.whenUnmodifiedType( enumType: (GraphQLEnumType) -> T, inputObjectType: (GraphQLInputObjectType) -> T, scalarType: (GraphQLScalarType) -> T, @@ -76,3 +80,15 @@ internal inline fun GraphQLInputType.whenUnmodifiedType( } } +inline fun GraphQLType.whenType( + listType: (GraphQLList) -> T, + nonNull: (GraphQLNonNull) -> T, + unmodifiedType: (GraphQLUnmodifiedType) -> T, +): T { + return when (this) { + is GraphQLList -> listType(this) + is GraphQLNonNull -> nonNull(this) + is GraphQLUnmodifiedType -> unmodifiedType(this) + else -> throw IllegalStateException("Should never happen") + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/EngineTestHook.kt b/test/src/test/kotlin/graphql/nadel/tests/EngineTestHook.kt index bd727ae09..e5d40cd3c 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/EngineTestHook.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/EngineTestHook.kt @@ -66,7 +66,7 @@ interface EngineTestHook { /** * Allows you to wrap the base test service execution call, so you can do things before or after it */ - fun wrapServiceExecution(baseTestServiceExecution: ServiceExecution): ServiceExecution { + fun wrapServiceExecution(serviceName: String, baseTestServiceExecution: ServiceExecution): ServiceExecution { return baseTestServiceExecution } } @@ -78,9 +78,13 @@ private val hooksPackage: String = join( ) internal fun getTestHook(fixture: TestFixture): EngineTestHook? { + return getTestHook(fixture.name) +} + +internal fun getTestHook(name: String): EngineTestHook? { require(Util.validated) { "Tests hooks are not valid" } - val className = when (val name = fixture.name) { + val className = when (name) { "new transformer on hydration fields", "new can generate legacy operation name on batch hydration for specific service", "new can generate legacy operation name on batch hydration", diff --git a/test/src/test/kotlin/graphql/nadel/tests/EngineTests.kt b/test/src/test/kotlin/graphql/nadel/tests/EngineTests.kt index 8e7a05b56..fa855da31 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/EngineTests.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/EngineTests.kt @@ -218,7 +218,7 @@ private suspend fun execute( fail("Unable to invoke service '$serviceName'", e) } } - return testHook.wrapServiceExecution(serviceExecution) + return testHook.wrapServiceExecution(serviceName, serviceExecution) } private fun transformIncrementalExecutionResult(serviceCall: ServiceCall): CompletableFuture { diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/HydrationDetailsHook.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/HydrationDetailsHook.kt index df253b837..1e381aafe 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/HydrationDetailsHook.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/HydrationDetailsHook.kt @@ -8,7 +8,7 @@ import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook abstract class HydrationDetailsHook : EngineTestHook { - override fun wrapServiceExecution(baseTestServiceExecution: ServiceExecution): ServiceExecution { + override fun wrapServiceExecution(serviceName: String, baseTestServiceExecution: ServiceExecution): ServiceExecution { return ServiceExecution { params -> if (params.hydrationDetails != null) { assertHydrationDetails(params.hydrationDetails!!) diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/abort-within-instrumentation-will-still-call-enhancing-instrumentation-functions.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/abort-within-instrumentation-will-still-call-enhancing-instrumentation-functions.kt index 696125e35..87dcdffe3 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/abort-within-instrumentation-will-still-call-enhancing-instrumentation-functions.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/abort-within-instrumentation-will-still-call-enhancing-instrumentation-functions.kt @@ -35,7 +35,7 @@ class `abort-begin-execute-within-instrumentation-still-calls-enhancing-instrume ExecutionResultImpl .newExecutionResult() .from(executionResult) - .data("enhanced beginExecute") + .data(mapOf("step" to "beginExecute")) .build(), ) } @@ -65,7 +65,7 @@ class `abort-begin-execute-in-cf-within-instrumentation-still-calls-enhancing-in ExecutionResultImpl .newExecutionResult() .from(executionResult) - .data("enhanced beginExecute") + .data(mapOf("step" to "beginExecute")) .build(), ) } @@ -93,7 +93,7 @@ class `abort-begin-query-execution-within-instrumentation-still-calls-enhancing- ExecutionResultImpl .newExecutionResult() .from(executionResult) - .data("enhanced beginQueryExecution") + .data(mapOf("step" to "beginQueryExecution")) .build(), ) } @@ -121,7 +121,7 @@ class `abort-begin-validation-within-instrumentation-still-calls-enhancing-instr ExecutionResultImpl .newExecutionResult() .from(executionResult) - .data("enhanced beginValidation") + .data(mapOf("step" to "beginValidation")) .build(), ) } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/can-delete-fields-and-types.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/can-delete-fields-and-types.kt index 543c29e13..332320ef6 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/can-delete-fields-and-types.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/can-delete-fields-and-types.kt @@ -1,12 +1,8 @@ package graphql.nadel.tests.hooks -import graphql.ExecutionResult -import graphql.nadel.engine.util.AnyList import graphql.nadel.schema.SchemaTransformationHook import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook -import graphql.nadel.tests.assertJsonKeys -import graphql.nadel.tests.util.data import graphql.schema.GraphQLFieldDefinition import graphql.schema.GraphQLObjectType import graphql.schema.GraphQLSchemaElement @@ -14,13 +10,6 @@ import graphql.schema.GraphQLTypeVisitorStub import graphql.schema.SchemaTransformer.transformSchema import graphql.util.TraversalControl import graphql.util.TraverserContext -import strikt.api.expectThat -import strikt.assertions.get -import strikt.assertions.isA -import strikt.assertions.isEqualTo -import strikt.assertions.isNotNull -import strikt.assertions.none -import strikt.assertions.one @UseHook class `can-delete-fields-and-types` : EngineTestHook { @@ -47,23 +36,4 @@ class `can-delete-fields-and-types` : EngineTestHook { } }) } - - override fun assertResult(result: ExecutionResult) { - expectThat(result) - .data - .isNotNull() - .assertJsonKeys()["__schema"] - .isNotNull() - .isAJsonMap()["types"] - .isA() - .none { - isNotNull().isAJsonMap()["name"].isEqualTo("Foo") - } - .one { - isNotNull().isAJsonMap()["name"].isEqualTo("String") - } - .one { - isNotNull().isAJsonMap()["name"].isEqualTo("Query") - } - } } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/enable-defer-support.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/enable-defer-support.kt deleted file mode 100644 index a74619525..000000000 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/enable-defer-support.kt +++ /dev/null @@ -1,25 +0,0 @@ -package graphql.nadel.tests.hooks - -import graphql.nadel.NadelExecutionInput -import graphql.nadel.tests.EngineTestHook -import graphql.nadel.tests.UseHook - -private interface DeferHook : EngineTestHook { - override fun makeExecutionInput(builder: NadelExecutionInput.Builder): NadelExecutionInput.Builder { - return super.makeExecutionInput(builder) - .transformExecutionHints { - it - .deferSupport { true } - } - } -} - -@UseHook -class `defer-with-label` : DeferHook - -@UseHook -class `defer-no-label` : DeferHook - -@UseHook -class `defer-on-hydrated-field` : DeferHook - diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-hydration-call-that-fail-with-errors-are-reflected-in-the-result.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-hydration-call-that-fail-with-errors-are-reflected-in-the-result.kt index d3eeab869..06c23a6ad 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-hydration-call-that-fail-with-errors-are-reflected-in-the-result.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-hydration-call-that-fail-with-errors-are-reflected-in-the-result.kt @@ -1,9 +1,9 @@ package graphql.nadel.tests.hooks import graphql.ExecutionResult -import graphql.nadel.Nadel +import graphql.execution.ExecutionId +import graphql.nadel.NadelExecutionInput import graphql.nadel.ServiceExecution -import graphql.nadel.ServiceExecutionFactory import graphql.nadel.engine.util.AnyMap import graphql.nadel.engine.util.JsonMap import graphql.nadel.tests.EngineTestHook @@ -12,8 +12,6 @@ import graphql.nadel.tests.assertJsonKeys import graphql.nadel.tests.util.data import graphql.nadel.tests.util.errors import graphql.nadel.tests.util.message -import graphql.nadel.tests.util.serviceExecutionFactory -import graphql.schema.idl.TypeDefinitionRegistry import strikt.api.Assertion import strikt.api.expectThat import strikt.assertions.contains @@ -25,21 +23,19 @@ import strikt.assertions.single @UseHook class `exceptions-in-hydration-call-that-fail-with-errors-are-reflected-in-the-result` : EngineTestHook { - override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - val serviceExecutionFactory = builder.serviceExecutionFactory + override fun wrapServiceExecution(serviceName: String, baseTestServiceExecution: ServiceExecution): ServiceExecution { + return when (serviceName) { + // This is the hydration service, we die on hydration + "Bar" -> ServiceExecution { + throw RuntimeException("Pop goes the weasel") + } + else -> baseTestServiceExecution + } + } - return builder - .serviceExecutionFactory(object : ServiceExecutionFactory { - override fun getServiceExecution(serviceName: String): ServiceExecution { - return when (serviceName) { - // This is the hydration service, we die on hydration - "Bar" -> ServiceExecution { - throw RuntimeException("Pop goes the weasel") - } - else -> serviceExecutionFactory.getServiceExecution(serviceName) - } - } - }) + override fun makeExecutionInput(builder: NadelExecutionInput.Builder): NadelExecutionInput.Builder { + return super.makeExecutionInput(builder) + .executionId(ExecutionId.from("test")) } override fun assertResult(result: ExecutionResult) { diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-call-result-in-graphql-errors-and-call-onerror-instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-call-result-in-graphql-errors-and-call-onerror-instrumentation.kt index d77608b8d..240d1921c 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-call-result-in-graphql-errors-and-call-onerror-instrumentation.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-call-result-in-graphql-errors-and-call-onerror-instrumentation.kt @@ -1,9 +1,10 @@ package graphql.nadel.tests.hooks import graphql.ExecutionResult +import graphql.execution.ExecutionId import graphql.nadel.Nadel +import graphql.nadel.NadelExecutionInput import graphql.nadel.ServiceExecution -import graphql.nadel.ServiceExecutionFactory import graphql.nadel.instrumentation.NadelInstrumentation import graphql.nadel.instrumentation.parameters.ErrorData import graphql.nadel.instrumentation.parameters.NadelInstrumentationOnErrorParameters @@ -28,13 +29,6 @@ class `exceptions-in-service-execution-call-result-in-graphql-errors-and-call-on var errorMessage: String? = null override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { return builder - .serviceExecutionFactory(object : ServiceExecutionFactory { - override fun getServiceExecution(serviceName: String): ServiceExecution { - return ServiceExecution { - throw RuntimeException("Pop goes the weasel") - } - } - }) .instrumentation(object : NadelInstrumentation { override fun onError(parameters: NadelInstrumentationOnErrorParameters) { serviceName = (parameters.errorData as ErrorData.ServiceExecutionErrorData).serviceName @@ -43,6 +37,20 @@ class `exceptions-in-service-execution-call-result-in-graphql-errors-and-call-on }) } + override fun makeExecutionInput(builder: NadelExecutionInput.Builder): NadelExecutionInput.Builder { + return super.makeExecutionInput(builder) + .executionId(ExecutionId.from("test")) + } + + override fun wrapServiceExecution( + serviceName: String, + baseTestServiceExecution: ServiceExecution, + ): ServiceExecution { + return ServiceExecution { + throw RuntimeException("Pop goes the weasel") + } + } + override fun assertResult(result: ExecutionResult) { expectThat(result).data .isNotNull() diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-result-completable-future-in-graphql-errors.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-result-completable-future-in-graphql-errors.kt index bcb7cc937..0bfb7cdb1 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-result-completable-future-in-graphql-errors.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/exceptions-in-service-execution-result-completable-future-in-graphql-errors.kt @@ -1,16 +1,15 @@ package graphql.nadel.tests.hooks import graphql.ExecutionResult -import graphql.nadel.Nadel +import graphql.execution.ExecutionId +import graphql.nadel.NadelExecutionInput import graphql.nadel.ServiceExecution -import graphql.nadel.ServiceExecutionFactory import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook import graphql.nadel.tests.assertJsonKeys import graphql.nadel.tests.util.data import graphql.nadel.tests.util.errors import graphql.nadel.tests.util.message -import graphql.nadel.tests.util.serviceExecutionFactory import strikt.api.expectThat import strikt.assertions.contains import strikt.assertions.get @@ -21,18 +20,18 @@ import java.util.concurrent.CompletableFuture @UseHook class `exceptions-in-service-execution-result-completable-future-in-graphql-errors` : EngineTestHook { - override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return builder - .serviceExecutionFactory(object : ServiceExecutionFactory { - override fun getServiceExecution(serviceName: String): ServiceExecution { - return ServiceExecution { - CompletableFuture.completedFuture(null) - .thenCompose { - throw RuntimeException("Pop goes the weasel") - } - } + override fun makeExecutionInput(builder: NadelExecutionInput.Builder): NadelExecutionInput.Builder { + return super.makeExecutionInput(builder) + .executionId(ExecutionId.from("test")) + } + + override fun wrapServiceExecution(serviceName: String, baseTestServiceExecution: ServiceExecution): ServiceExecution { + return ServiceExecution { + CompletableFuture.completedFuture(null) + .thenCompose { + throw RuntimeException("Pop goes the weasel") } - }) + } } override fun assertResult(result: ExecutionResult) { diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-input.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-input.kt index 60c170ee3..ad3251120 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-input.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-input.kt @@ -2,37 +2,16 @@ package graphql.nadel.tests.hooks import graphql.ExecutionResult import graphql.execution.ExecutionId -import graphql.nadel.Nadel import graphql.nadel.NadelExecutionInput import graphql.nadel.ServiceExecution -import graphql.nadel.ServiceExecutionFactory import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook -import graphql.nadel.tests.util.serviceExecutionFactory -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isGreaterThan +import kotlin.test.assertTrue @UseHook class `execution-id-is-transferred-from-input` : EngineTestHook { private var calls = 0 - override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - val serviceExecutionFactory = builder.serviceExecutionFactory - - return builder - .serviceExecutionFactory(object : ServiceExecutionFactory by serviceExecutionFactory { - override fun getServiceExecution(serviceName: String): ServiceExecution { - val serviceExecution = serviceExecutionFactory.getServiceExecution(serviceName) - return ServiceExecution { params -> - calls++ - expectThat(params.executionId).isEqualTo(ExecutionId.from("from-input")) - serviceExecution.execute(params) - } - } - }) - } - override fun makeExecutionInput( builder: NadelExecutionInput.Builder, ): NadelExecutionInput.Builder { @@ -40,8 +19,19 @@ class `execution-id-is-transferred-from-input` : EngineTestHook { .executionId(ExecutionId.from("from-input")) } + override fun wrapServiceExecution( + serviceName: String, + baseTestServiceExecution: ServiceExecution, + ): ServiceExecution { + return ServiceExecution { params -> + calls++ + assertTrue(params.executionId == ExecutionId.from("from-input")) + baseTestServiceExecution.execute(params) + } + } + override fun assertResult(result: ExecutionResult) { - expectThat(calls).isGreaterThan(0) + assertTrue(calls > 0) } } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-provider-if-missing-in-input.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-provider-if-missing-in-input.kt index 063559179..1bcca5df0 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-provider-if-missing-in-input.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/execution-id-is-transferred-from-provider-if-missing-in-input.kt @@ -4,38 +4,33 @@ import graphql.ExecutionResult import graphql.execution.ExecutionId import graphql.nadel.Nadel import graphql.nadel.ServiceExecution -import graphql.nadel.ServiceExecutionFactory import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.UseHook -import graphql.nadel.tests.util.serviceExecutionFactory -import strikt.api.expectThat -import strikt.assertions.isEqualTo -import strikt.assertions.isGreaterThan +import kotlin.test.assertTrue @UseHook class `execution-id-is-transferred-from-provider-if-missing-in-input` : EngineTestHook { private var calls = 0 override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - val serviceExecutionFactory = builder.serviceExecutionFactory - return builder - .serviceExecutionFactory(object : ServiceExecutionFactory by serviceExecutionFactory { - override fun getServiceExecution(serviceName: String): ServiceExecution { - val serviceExecution = serviceExecutionFactory.getServiceExecution(serviceName) - return ServiceExecution { params -> - calls++ - expectThat(params.executionId).isEqualTo(ExecutionId.from("from-provider")) - serviceExecution.execute(params) - } - } - }) .executionIdProvider { _, _, _ -> ExecutionId.from("from-provider") } } + override fun wrapServiceExecution( + serviceName: String, + baseTestServiceExecution: ServiceExecution, + ): ServiceExecution { + return ServiceExecution { params -> + calls++ + assertTrue(params.executionId == ExecutionId.from("from-provider")) + baseTestServiceExecution.execute(params) + } + } + override fun assertResult(result: ExecutionResult) { - expectThat(calls).isGreaterThan(0) + assertTrue(calls > 0) } } diff --git a/test/src/test/kotlin/graphql/nadel/tests/hooks/scalar-transforms.kt b/test/src/test/kotlin/graphql/nadel/tests/hooks/scalar-transforms.kt index 914793c44..48a7e486c 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/hooks/scalar-transforms.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/hooks/scalar-transforms.kt @@ -1,17 +1,14 @@ package graphql.nadel.tests.hooks -import graphql.nadel.Nadel import graphql.nadel.tests.EngineTestHook import graphql.nadel.tests.GatewaySchemaWiringFactory import graphql.nadel.tests.UseHook +import graphql.schema.idl.WiringFactory import java.io.File interface GatewayScalarEngineHook : EngineTestHook { - override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { - return super.makeNadel(builder) - .overallWiringFactory(GatewaySchemaWiringFactory()) - .underlyingWiringFactory(GatewaySchemaWiringFactory()) - } + override val wiringFactory: WiringFactory + get() = GatewaySchemaWiringFactory() } /** diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/NadelLegacyIntegrationTest.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/NadelLegacyIntegrationTest.kt new file mode 100644 index 000000000..2f62455f6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/NadelLegacyIntegrationTest.kt @@ -0,0 +1,68 @@ +package graphql.nadel.tests.legacy + +import graphql.ExecutionResult +import graphql.incremental.DelayedIncrementalPartialResult +import graphql.nadel.Nadel +import graphql.nadel.NadelExecutionHints +import graphql.nadel.NadelExecutionInput +import graphql.nadel.NadelSchemas +import graphql.nadel.ServiceExecution +import graphql.nadel.engine.util.JsonMap +import graphql.nadel.tests.EngineTestHook +import graphql.nadel.tests.getTestHook +import graphql.nadel.tests.next.NadelIntegrationTest +import graphql.nadel.validation.NadelSchemaValidationError +import org.intellij.lang.annotations.Language + +abstract class NadelLegacyIntegrationTest( + operationName: String? = null, + @Language("GraphQL") + query: String, + variables: JsonMap = emptyMap(), + userContext: Any? = null, + services: List, +) : NadelIntegrationTest( + operationName = operationName, + query = query, + variables = variables, + userContext = userContext, + services = services, +) { + private val legacyHook: EngineTestHook = getTestHook(javaClass.simpleName) ?: EngineTestHook.noOp + + override fun makeExecutionInput(): NadelExecutionInput.Builder = + legacyHook.makeExecutionInput(super.makeExecutionInput()) + + override fun makeExecutionHints(): NadelExecutionHints.Builder = + legacyHook.makeExecutionHints(super.makeExecutionHints()) + + override fun makeNadel(): Nadel.Builder = + legacyHook + .makeNadel(super.makeNadel()) + .transforms(legacyHook.customTransforms) + .schemaTransformationHook(legacyHook.schemaTransformationHook) + + override fun makeNadelSchemas(): NadelSchemas.Builder = + super + .makeNadelSchemas() + .overallWiringFactory(legacyHook.wiringFactory) + .underlyingWiringFactory(legacyHook.wiringFactory) + + override fun makeServiceExecution(service: Service): ServiceExecution = + legacyHook.wrapServiceExecution(service.name, super.makeServiceExecution(service)) + + override fun assert( + result: ExecutionResult, + incrementalResults: List?, + ) { + legacyHook.assertResult(result) + } + + override fun assertSchemaErrors(errors: Set) { + if (legacyHook.isSchemaValid(errors)) { + return + } + + super.assertSchemaErrors(errors) + } +} \ No newline at end of file diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/call with variables inside input objects snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/call with variables inside input objects snapshot.kt new file mode 100644 index 000000000..dcfbe1c4a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/call with variables inside input objects snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`call with variables inside input objects`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `call with variables inside input objects snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery { + | hello(arg: {}) + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/call with variables inside input objects.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/call with variables inside input objects.kt new file mode 100644 index 000000000..60c3fee62 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/call with variables inside input objects.kt @@ -0,0 +1,48 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `call with variables inside input objects` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}varIds: [ID], ${'$'}otherVar: String) { + hello(arg: {ids: ${'$'}varIds}, otherArg: ${'$'}otherVar) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: Arg, otherArg: String): String + } + input Arg { + ids: [ID] + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: Arg, otherArg: String): String + } + input Arg { + ids: [ID] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == emptyMap()) { + "world" + } else { + null + } + } + } + }, + ), + ), +) { + private data class MyService_Arg( + val ids: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute document with multiple operation definitions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute document with multiple operation definitions snapshot.kt new file mode 100644 index 000000000..95a19a746 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute document with multiple operation definitions snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can execute document with multiple operation definitions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can execute document with multiple operation definitions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | query Test { + | test: foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "test": "Test Working" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": "Test Working" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": "Test Working" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute document with multiple operation definitions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute document with multiple operation definitions.kt new file mode 100644 index 000000000..a524d6d39 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute document with multiple operation definitions.kt @@ -0,0 +1,44 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can execute document with multiple operation definitions` : NadelLegacyIntegrationTest( + operationName = "Test", + query = """ + query Foo { + foo + } + query Test { + test: foo + } + query Dog { + dog: foo + } + query Meow { + cat: foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + "Test Working" + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is empty snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is empty snapshot.kt new file mode 100644 index 000000000..1731b38fb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is empty snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can execute single named operation when operation name is empty`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can execute single named operation when operation name is empty snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | query Test { + | test: foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "test": "Test Working" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": "Test Working" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": "Test Working" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is empty.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is empty.kt new file mode 100644 index 000000000..5024bd914 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is empty.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can execute single named operation when operation name is empty` : NadelLegacyIntegrationTest( + query = """ + query Test { + test: foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + "Test Working" + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is null snapshot.kt new file mode 100644 index 000000000..3ad77253d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is null snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can execute single named operation when operation name is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can execute single named operation when operation name is null snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | query Test { + | test: foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "test": "Test Working" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": "Test Working" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": "Test Working" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is null.kt new file mode 100644 index 000000000..57c45d12c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can execute single named operation when operation name is null.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can execute single named operation when operation name is null` : NadelLegacyIntegrationTest( + query = """ + query Test { + test: foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + "Test Working" + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names forwarding original name snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names forwarding original name snapshot.kt new file mode 100644 index 000000000..680e90b21 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names forwarding original name snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can generate legacy operation names forwarding original name`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can generate legacy operation names forwarding original name snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "test", + query = """ + | query nadel_2_test_Original { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names forwarding original name.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names forwarding original name.kt new file mode 100644 index 000000000..afb2bca80 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names forwarding original name.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can generate legacy operation names forwarding original name` : NadelLegacyIntegrationTest( + query = """ + query Original { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "test", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names snapshot.kt new file mode 100644 index 000000000..4888715de --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can generate legacy operation names`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can generate legacy operation names snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "test", + query = """ + | query nadel_2_test { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names.kt new file mode 100644 index 000000000..4a56109a0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/can generate legacy operation names.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can generate legacy operation names` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "test", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/large query but not deep snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/large query but not deep snapshot.kt new file mode 100644 index 000000000..1e75727a0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/large query but not deep snapshot.kt @@ -0,0 +1,157 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`large query but not deep`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `large query but not deep snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | bar: foo { + | child { + | child { + | child { + | child { + | child { + | child { + | child { + | child { + | name + | } + | } + | } + | } + | } + | } + | } + | two: child { + | child { + | child { + | child { + | child { + | child { + | child { + | name + | } + | } + | } + | } + | } + | } + | } + | three: child { + | child { + | child { + | child { + | child { + | child { + | child { + | name + | } + | } + | } + | four: child { + | child { + | child { + | name + | } + | } + | } + | } + | } + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bar": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | child { + | child { + | child { + | child { + | child { + | child { + | child { + | child { + | name + | } + | } + | } + | } + | } + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null, + * "bar": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null, + | "bar": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/large query but not deep.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/large query but not deep.kt new file mode 100644 index 000000000..2d7cd3566 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/large query but not deep.kt @@ -0,0 +1,127 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `large query but not deep` : NadelLegacyIntegrationTest( + query = """ + query { + foo { # 1 + child { # 2 + child { # 3 + child { # 4 + child { # 5 + child { # 6 + child { # 7 + child { # 8 + child { # 9 + name # 10 + } + } + } + } + } + } + } + } + } + bar: foo { # 1 + child { # 2 + child { # 3 + child { # 4 + child { # 5 + child { # 6 + child { # 7 + child { # 8 + child { # 9 + name # 10 + } + } + } + } + } + } + } + two: child { # 3 + child { # 4 + child { # 5 + child { # 6 + child { # 7 + child { # 8 + child { # 9 + name # 10 + } + } + } + } + } + } + } + three: child { # 3 + child { # 4 + child { # 5 + child { # 6 + child { # 7 + child { # 8 + child { # 9 + name # 10 + } + } + } + four: child { # 7 + child { # 8 + child { # 9 + name # 10 + } + } + } + } + } + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + child: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + child: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.field.resultKey == "foo") { + null + } else if (env.field.resultKey == "bar") { + null + } else { + null + } + } + } + }, + ), + ), +) { + private data class Service_Foo( + val name: String? = null, + val child: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/missing null variables are handled snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/missing null variables are handled snapshot.kt new file mode 100644 index 000000000..5948294a5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/missing null variables are handled snapshot.kt @@ -0,0 +1,71 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`missing null variables are handled`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `missing null variables are handled snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Variable 'var1' has an invalid value: Variable 'var1' has coerced Null + * value for NonNull type 'String!'", + * "locations": [ + * { + * "line": 1, + * "column": 12 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Variable 'var1' has an invalid value: Variable 'var1' has coerced Null value for NonNull type 'String!'", + | "locations": [ + | { + | "line": 1, + | "column": 12 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/missing null variables are handled.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/missing null variables are handled.kt new file mode 100644 index 000000000..62b1e3682 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/missing null variables are handled.kt @@ -0,0 +1,52 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `missing null variables are handled` : NadelLegacyIntegrationTest( + query = """ + query with(${'$'}var1: String!) { + helloWithArgs(arg1: ${'$'}var1) { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + helloWithArgs(arg1: String! arg2: String): World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + helloWithArgs(arg1: String!, arg2: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/mutation can be executed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/mutation can be executed snapshot.kt new file mode 100644 index 000000000..1949bbbcc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/mutation can be executed snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`mutation can be executed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `mutation can be executed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | mutation M { + | hello + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/mutation can be executed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/mutation can be executed.kt new file mode 100644 index 000000000..49d8612e1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/mutation can be executed.kt @@ -0,0 +1,61 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `mutation can be executed` : NadelLegacyIntegrationTest( + query = """ + mutation M { + hello + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + type Subscription { + onWorldUpdate: World + onAnotherUpdate: World + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type Subscription { + onAnotherUpdate: World + onWorldUpdate: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Mutation") { type -> + type.dataFetcher("hello") { env -> + "world" + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service snapshot.kt new file mode 100644 index 000000000..21e142e65 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one call to one service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one call to one service snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service with list result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service with list result snapshot.kt new file mode 100644 index 000000000..d8eeaaf9a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service with list result snapshot.kt @@ -0,0 +1,73 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one call to one service with list result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one call to one service with list result snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | "foo1", + | "foo2" + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * "foo1", + * "foo2" + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | "foo1", + | "foo2" + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service with list result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service with list result.kt new file mode 100644 index 000000000..d22d7ea55 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service with list result.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one call to one service with list result` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: [String] + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [String] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf("foo1", "foo2") + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service.kt new file mode 100644 index 000000000..7b35e086b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/one call to one service.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one call to one service` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation depth limit snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation depth limit snapshot.kt new file mode 100644 index 000000000..026c9d762 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation depth limit snapshot.kt @@ -0,0 +1,58 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`operation depth limit`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `operation depth limit snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Maximum query depth exceeded. 11 > 10", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Maximum query depth exceeded. 11 > 10", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation depth limit.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation depth limit.kt new file mode 100644 index 000000000..06639d437 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation depth limit.kt @@ -0,0 +1,62 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `operation depth limit` : NadelLegacyIntegrationTest( + query = """ + query { + foo { # 1 + child { # 2 + child { # 3 + child { # 4 + child { # 5 + child { # 6 + child { # 7 + child { # 8 + child { # 9 + child { # 10 + name # 11 + } + } + } + } + } + } + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + child: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + child: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Service_Foo( + val name: String? = null, + val child: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation field count limit snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation field count limit snapshot.kt new file mode 100644 index 000000000..d7fb8b945 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation field count limit snapshot.kt @@ -0,0 +1,58 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`operation field count limit`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `operation field count limit snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Maximum field count exceeded. 11 > 10", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Maximum field count exceeded. 11 > 10", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation field count limit.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation field count limit.kt new file mode 100644 index 000000000..8604d51e5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/operation field count limit.kt @@ -0,0 +1,56 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `operation field count limit` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + name + child { + name + } + } + __typename + bar: foo { + barName: name + barChild: child { + barTypeName: __typename + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + child: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + child: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Service_Foo( + val name: String? = null, + val child: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/query to one service with execution input passed down snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/query to one service with execution input passed down snapshot.kt new file mode 100644 index 000000000..6632f5519 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/query to one service with execution input passed down snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query to one service with execution input passed down`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query to one service with execution input passed down snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query OpName { + | hello { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": { + | "name": "earth", + | "id": "3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": { + * "name": "earth", + * "id": "3" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": { + | "name": "earth", + | "id": "3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/query to one service with execution input passed down.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/query to one service with execution input passed down.kt new file mode 100644 index 000000000..acd3b49f3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/query to one service with execution input passed down.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query to one service with execution input passed down` : NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + type Subscription { + onWorldUpdate: World + onAnotherUpdate: World + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type Subscription { + onAnotherUpdate: World + onWorldUpdate: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + MyService_World(id = "3", name = "earth") + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/rejects multiple operation defs without explicit op name snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/rejects multiple operation defs without explicit op name snapshot.kt new file mode 100644 index 000000000..da8f86342 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/rejects multiple operation defs without explicit op name snapshot.kt @@ -0,0 +1,58 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rejects multiple operation defs without explicit op name`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rejects multiple operation defs without explicit op name snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Must provide operation name if query contains multiple operations", + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Must provide operation name if query contains multiple operations", + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/rejects multiple operation defs without explicit op name.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/rejects multiple operation defs without explicit op name.kt new file mode 100644 index 000000000..8a244c878 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/rejects multiple operation defs without explicit op name.kt @@ -0,0 +1,38 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rejects multiple operation defs without explicit op name` : NadelLegacyIntegrationTest( + query = """ + query Foo { + foo + } + query Test { + test: foo + } + query Dog { + dog: foo + } + query Meow { + cat: foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are completely filtered snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are completely filtered snapshot.kt new file mode 100644 index 000000000..f074c4eba --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are completely filtered snapshot.kt @@ -0,0 +1,87 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`service types are completely filtered`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `service types are completely filtered snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "test", + query = """ + | { + | test { + | ... on QueryError { + | extensions { + | __typename__type_filter__statusCode: __typename + | } + | } + | ... on Test { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "test": { + | "extensions": [ + | { + | "__typename__type_filter__statusCode": "GenericQueryErrorExtension" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": { + * "extensions": [ + * {} + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": { + | "extensions": [ + | {} + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are completely filtered.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are completely filtered.kt new file mode 100644 index 000000000..def77dcbb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are completely filtered.kt @@ -0,0 +1,197 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `service types are completely filtered` : NadelLegacyIntegrationTest( + query = """ + query { + test { + ... on Test { + id + } + ... on QueryError { + extensions { + ... on LabQueryErrorExtension { + statusCode + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "test", + overallSchema = """ + type Query { + test: TestResult + } + type Test { + id: ID + } + union TestResult = Test | QueryError + """.trimIndent(), + underlyingSchema = """ + type Query { + test: TestResult + } + type Test { + id: ID + } + union TestResult = Test | QueryError + interface QueryErrorExtension { + ""${'"'}A numerical code (such as a HTTP status code) representing the error category""${'"'} + statusCode: Int + ""${'"'}Application specific error type""${'"'} + errorType: String + } + type GenericQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + type QueryError { + ""${'"'}The ID of the object that would have otherwise been returned if not for the query error""${'"'} + identifier: ID + "A message describing the error" + message: String + "Use this to put extra data on the error if required" + extensions: [QueryErrorExtension!] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("test") { env -> + Test_QueryError(extensions = listOf(Test_GenericQueryErrorExtension())) + } + } + wiring.type("QueryErrorExtension") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("TestResult") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "lab", + overallSchema = """ + type LabQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + interface QueryErrorExtension { + ""${'"'}A numerical code (such as a HTTP status code) representing the error category""${'"'} + statusCode: Int + ""${'"'}Application specific error type""${'"'} + errorType: String + } + type LabQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + type QueryError { + ""${'"'}The ID of the object that would have otherwise been returned if not for the query error""${'"'} + identifier: ID + "A message describing the error" + message: String + "Use this to put extra data on the error if required" + extensions: [QueryErrorExtension!] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("QueryErrorExtension") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "shared", + overallSchema = """ + interface QueryErrorExtension { + ""${'"'}A numerical code (such as a HTTP status code) representing the error category""${'"'} + statusCode: Int + ""${'"'}Application specific error type""${'"'} + errorType: String + } + type GenericQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + type QueryError { + ""${'"'}The ID of the object that would have otherwise been returned if not for the query error""${'"'} + identifier: ID + "A message describing the error" + message: String + "Use this to put extra data on the error if required" + extensions: [QueryErrorExtension!] + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Test_GenericQueryErrorExtension( + override val statusCode: Int? = null, + override val errorType: String? = null, + ) : Test_QueryErrorExtension + + private data class Test_QueryError( + val identifier: String? = null, + val message: String? = null, + val extensions: List? = null, + ) : Test_TestResult + + private interface Test_QueryErrorExtension { + val statusCode: Int? + + val errorType: String? + } + + private data class Test_Test( + val id: String? = null, + ) : Test_TestResult + + private sealed interface Test_TestResult + + private data class Lab_LabQueryErrorExtension( + override val statusCode: Int? = null, + override val errorType: String? = null, + ) : Lab_QueryErrorExtension + + private data class Lab_QueryError( + val identifier: String? = null, + val message: String? = null, + val extensions: List? = null, + ) + + private interface Lab_QueryErrorExtension { + val statusCode: Int? + + val errorType: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are filtered snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are filtered snapshot.kt new file mode 100644 index 000000000..4521f94a8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are filtered snapshot.kt @@ -0,0 +1,80 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`service types are filtered`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `service types are filtered snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "test", + query = """ + | { + | test { + | ... on QueryError { + | extensions { + | __typename__type_filter__statusCode: __typename + | errorType + | } + | } + | ... on Test { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "test": { + | "id": "Test-1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": { + * "id": "Test-1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": { + | "id": "Test-1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are filtered.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are filtered.kt new file mode 100644 index 000000000..36469cbb5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/service types are filtered.kt @@ -0,0 +1,201 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `service types are filtered` : NadelLegacyIntegrationTest( + query = """ + query { + test { + ... on Test { + id + } + ... on QueryError { + extensions { + ...GenericQueryErrorExtensions + } + } + } + } + fragment GenericQueryErrorExtensions on QueryErrorExtension { + errorType + ... on LabQueryErrorExtension { + statusCode + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "test", + overallSchema = """ + type Query { + test: TestResult + } + type Test { + id: ID + } + union TestResult = Test | QueryError + """.trimIndent(), + underlyingSchema = """ + type Query { + test: TestResult + } + type Test { + id: ID + } + union TestResult = Test | QueryError + interface QueryErrorExtension { + ""${'"'}A numerical code (such as a HTTP status code) representing the error category""${'"'} + statusCode: Int + ""${'"'}Application specific error type""${'"'} + errorType: String + } + type GenericQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + type QueryError { + ""${'"'}The ID of the object that would have otherwise been returned if not for the query error""${'"'} + identifier: ID + "A message describing the error" + message: String + "Use this to put extra data on the error if required" + extensions: [QueryErrorExtension!] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("test") { env -> + Test_Test(id = "Test-1") + } + } + wiring.type("QueryErrorExtension") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("TestResult") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "lab", + overallSchema = """ + type LabQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + interface QueryErrorExtension { + ""${'"'}A numerical code (such as a HTTP status code) representing the error category""${'"'} + statusCode: Int + ""${'"'}Application specific error type""${'"'} + errorType: String + } + type LabQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + type QueryError { + ""${'"'}The ID of the object that would have otherwise been returned if not for the query error""${'"'} + identifier: ID + "A message describing the error" + message: String + "Use this to put extra data on the error if required" + extensions: [QueryErrorExtension!] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("QueryErrorExtension") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "shared", + overallSchema = """ + interface QueryErrorExtension { + ""${'"'}A numerical code (such as a HTTP status code) representing the error category""${'"'} + statusCode: Int + ""${'"'}Application specific error type""${'"'} + errorType: String + } + type GenericQueryErrorExtension implements QueryErrorExtension { + statusCode: Int + errorType: String + } + type QueryError { + ""${'"'}The ID of the object that would have otherwise been returned if not for the query error""${'"'} + identifier: ID + "A message describing the error" + message: String + "Use this to put extra data on the error if required" + extensions: [QueryErrorExtension!] + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Test_GenericQueryErrorExtension( + override val statusCode: Int? = null, + override val errorType: String? = null, + ) : Test_QueryErrorExtension + + private data class Test_QueryError( + val identifier: String? = null, + val message: String? = null, + val extensions: List? = null, + ) : Test_TestResult + + private interface Test_QueryErrorExtension { + val statusCode: Int? + + val errorType: String? + } + + private data class Test_Test( + val id: String? = null, + ) : Test_TestResult + + private sealed interface Test_TestResult + + private data class Lab_LabQueryErrorExtension( + override val statusCode: Int? = null, + override val errorType: String? = null, + ) : Lab_QueryErrorExtension + + private data class Lab_QueryError( + val identifier: String? = null, + val message: String? = null, + val extensions: List? = null, + ) + + private interface Lab_QueryErrorExtension { + val statusCode: Int? + + val errorType: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/subscription can be executed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/subscription can be executed snapshot.kt new file mode 100644 index 000000000..fdd4b5009 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/subscription can be executed snapshot.kt @@ -0,0 +1,50 @@ +// @formatter:off +package graphql.nadel.tests.legacy.basic + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`subscription can be executed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `subscription can be executed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "onWorldUpdate": { + * "id": "subscription M{onWorldUpdate{id}}" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "onWorldUpdate": { + | "id": "subscription M{onWorldUpdate{id}}" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/subscription can be executed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/subscription can be executed.kt new file mode 100644 index 000000000..e8e32774e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/basic/subscription can be executed.kt @@ -0,0 +1,75 @@ +package graphql.nadel.tests.legacy.basic + +import graphql.language.AstPrinter +import graphql.nadel.NadelServiceExecutionResultImpl +import graphql.nadel.ServiceExecution +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import java.util.concurrent.CompletableFuture + +class `subscription can be executed` : NadelLegacyIntegrationTest( + query = """ + subscription M { + onWorldUpdate { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + type Subscription { + onWorldUpdate: World + onAnotherUpdate: World + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type Subscription { + onAnotherUpdate: World + onWorldUpdate: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Subscription") { type -> + type.dataFetcher("onWorldUpdate") { env -> + null + } + } + }, + ), + ), +) { + override fun makeServiceExecution(service: Service): ServiceExecution = + ServiceExecution { + CompletableFuture.completedFuture( + NadelServiceExecutionResultImpl( + data = mutableMapOf( + "onWorldUpdate" to mutableMapOf( + "id" to AstPrinter.printAstCompact(it.query), + ), + ), + ), + ) + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed input snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed input snapshot.kt new file mode 100644 index 000000000..bbc7a7f82 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed input snapshot.kt @@ -0,0 +1,83 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`ari argument in renamed input`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `ari argument in renamed input snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | mutation mainJiraSoftwareStartSprintModalSubmitMutation(${'$'}v0: SprintInput) { + | startSprint(input: ${'$'}v0) { + | __typename + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "boardId": "123", + | "sprintId": "456", + | "name": "Test Input", + | "goal": null, + | "startDate": "2022-03-22", + | "endDate": "2022-04-02" + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "startSprint": { + | "__typename": "Sprint" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "startSprint": { + * "__typename": "Sprint" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "startSprint": { + | "__typename": "Sprint" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed input.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed input.kt new file mode 100644 index 000000000..a0022b985 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed input.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `ari argument in renamed input` : NadelLegacyIntegrationTest( + query = """ + mutation mainJiraSoftwareStartSprintModalSubmitMutation( + ${'$'}boardId: ID! + ${'$'}sprintId: ID! + ${'$'}name: String! + ${'$'}goal: String + ${'$'}startDate: String! + ${'$'}endDate: String! + ) { + startSprint( + input: { + boardId: ${'$'}boardId + sprintId: ${'$'}sprintId + name: ${'$'}name + goal: ${'$'}goal + startDate: ${'$'}startDate + endDate: ${'$'}endDate + } + ) { + __typename + } + } + """.trimIndent(), + variables = mapOf( + "boardId" to "ari:cloud:jira-software::board/123", + "sprintId" to "ari:cloud:jira-software::sprint/456", + "name" to "Test Input", + "goal" to null, + "startDate" to "2022-03-22", + "endDate" to "2022-04-02", + ), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + echo: String + } + type Mutation { + startSprint(input: StartSprintInput): Sprint + } + input StartSprintInput @renamed(from: "SprintInput") { + boardId: ID! @ARI(type: "board", owner: "jira-software", interpreted: true) + sprintId: ID! @ARI(type: "sprint", owner: "jira-software", interpreted: true) + name: String! + goal: String + startDate: String! + endDate: String! + } + type Sprint { + id: ID! + } + directive @ARI( + type: String! + owner: String! + interpreted: Boolean! = false + ) on ARGUMENT_DEFINITION | FIELD_DEFINITION | INPUT_FIELD_DEFINITION + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + type Mutation { + startSprint(input: SprintInput): Sprint + } + type Sprint { + id: ID! + } + input SprintInput { + boardId: ID! + sprintId: ID! + name: String! + goal: String + startDate: String! + endDate: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Mutation") { type -> + type.dataFetcher("startSprint") { env -> + if (env.getArgument("input") == + mapOf( + "boardId" to "123", + "sprintId" to "456", + "name" to "Test Input", + "goal" to null, + "startDate" to "2022-03-22", + "endDate" to "2022-04-02", + ) + ) { + MyService_Sprint() + } else { + null + } + } + } + }, + ), + ), +) { + private data class MyService_Sprint( + val id: String? = null, + ) + + private data class MyService_SprintInput( + val boardId: String? = null, + val sprintId: String? = null, + val name: String? = null, + val goal: String? = null, + val startDate: String? = null, + val endDate: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed object input in hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed object input in hydration snapshot.kt new file mode 100644 index 000000000..025483370 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed object input in hydration snapshot.kt @@ -0,0 +1,169 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`ari argument in renamed object input in hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `ari argument in renamed object input in hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query (${'$'}v0: ID!) { + | issue(id: ${'$'}v0) { + | __typename__batch_hydration__related: __typename + | batch_hydration__related__relatedIds: relatedIds { + | projectId + | } + | batch_hydration__related__relatedIds: relatedIds { + | issueId + | } + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": "ari:cloud:jira-software::issue/123" + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "issue": { + | "batch_hydration__related__relatedIds": [ + | { + | "projectId": "ari:cloud:jira-software::project/100", + | "issueId": "ari:cloud:jira-software::issue/1" + | }, + | { + | "projectId": "ari:cloud:jira-software::project/100", + | "issueId": "ari:cloud:jira-software::issue/2" + | }, + | { + | "projectId": "ari:cloud:jira-software::project/101", + | "issueId": "ari:cloud:jira-software::issue/3" + | } + | ], + | "__typename__batch_hydration__related": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "MyService", + query = """ + | query (${'$'}v0: [UnderlyingIssueInput]) { + | issues(input: ${'$'}v0) { + | batch_hydration__related__id: id + | key + | projectId + | batch_hydration__related__projectId: projectId + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": [ + | { + | "projectId": "100", + | "issueId": "1" + | }, + | { + | "projectId": "100", + | "issueId": "2" + | }, + | { + | "projectId": "101", + | "issueId": "3" + | } + | ] + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "issues": [ + | { + | "projectId": "100", + | "key": "GQLGW-001", + | "batch_hydration__related__projectId": "100", + | "batch_hydration__related__id": "1" + | }, + | { + | "projectId": "101", + | "key": "BUILD-003", + | "batch_hydration__related__projectId": "101", + | "batch_hydration__related__id": "3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "related": [ + * { + * "projectId": "ari:cloud:jira-software::project/100", + * "key": "GQLGW-001" + * }, + * null, + * { + * "projectId": "ari:cloud:jira-software::project/101", + * "key": "BUILD-003" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "related": [ + | { + | "projectId": "ari:cloud:jira-software::project/100", + | "key": "GQLGW-001" + | }, + | null, + | { + | "projectId": "ari:cloud:jira-software::project/101", + | "key": "BUILD-003" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed object input in hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed object input in hydration.kt new file mode 100644 index 000000000..53bf5bc2b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument in renamed object input in hydration.kt @@ -0,0 +1,150 @@ +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `ari argument in renamed object input in hydration` : NadelLegacyIntegrationTest( + query = """ + query { + issue(id: "ari:cloud:jira-software::issue/123") { + related { + projectId + key + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + issue(id: ID!): Issue + issues(input: [IssueInput]): [Issue] + } + type Issue { + id: ID! @ARI(type: "issue", owner: "jira-software", interpreted: true) + projectId: ID! @ARI(type: "project", owner: "jira-software", interpreted: true) + key: String! + related: [Issue] @hydrated( + service: "MyService" + field: "issues" + arguments: [{name: "input" value: "${'$'}source.relatedIds"}] + inputIdentifiedBy: [ + {sourceId: "relatedIds.projectId" resultId: "projectId"} + {sourceId: "relatedIds.issueId" resultId: "id"} + ] + ) + } + input IssueInput @renamed(from: "UnderlyingIssueInput") { + projectId: ID! @ARI(type: "project", owner: "jira-software", interpreted: true) + issueId: ID! @ARI(type: "issue", owner: "jira-software", interpreted: true) + } + type Sprint { + id: ID! + } + directive @ARI( + type: String! + owner: String! + interpreted: Boolean! = false + ) on ARGUMENT_DEFINITION | FIELD_DEFINITION | INPUT_FIELD_DEFINITION + """.trimIndent(), + underlyingSchema = """ + type Query { + issue(id: ID!): Issue + issues(input: [UnderlyingIssueInput]): [Issue] + } + type Issue { + id: ID! + projectId: ID! + key: String! + relatedIds: [RelatedIssue] + } + type RelatedIssue { + projectId: ID! + issueId: ID! + } + input UnderlyingIssueInput { + projectId: ID! + issueId: ID! + } + type Sprint { + id: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("issue") { env -> + if (env.getArgument("id") == "ari:cloud:jira-software::issue/123") { + MyService_Issue( + relatedIds = listOf( + MyService_RelatedIssue( + projectId = "ari:cloud:jira-software::project/100", + issueId = "ari:cloud:jira-software::issue/1", + ), + MyService_RelatedIssue( + projectId = "ari:cloud:jira-software::project/100", + issueId = "ari:cloud:jira-software::issue/2", + ), + MyService_RelatedIssue( + projectId = "ari:cloud:jira-software::project/101", + issueId = "ari:cloud:jira-software::issue/3", + ), + ), + ) + } else { + null + } + } + .dataFetcher("issues") { env -> + if (env.getArgument("input") == + listOf( + mapOf( + "projectId" to "100", + "issueId" to "1", + ), + mapOf( + "projectId" to "100", + "issueId" to "2" + ), + mapOf( + "projectId" to "101", + "issueId" to "3", + ), + ) + ) { + listOf( + MyService_Issue(id = "1", key = "GQLGW-001", projectId = "100"), + MyService_Issue(id = "3", key = "BUILD-003", projectId = "101"), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class MyService_Issue( + val id: String? = null, + val projectId: String? = null, + val key: String? = null, + val relatedIds: List? = null, + ) + + private data class MyService_RelatedIssue( + val projectId: String? = null, + val issueId: String? = null, + ) + + private data class MyService_Sprint( + val id: String? = null, + ) + + private data class MyService_UnderlyingIssueInput( + val projectId: String? = null, + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform on renamed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform on renamed field snapshot.kt new file mode 100644 index 000000000..65874ec0a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform on renamed field snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`ari argument transform on renamed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `ari argument transform on renamed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__issue__issueById: issueById(id: "57") { + | __typename__rename__key: __typename + | rename__key__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__issue__issueById": { + | "rename__key__id": "57", + | "__typename__rename__key": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "key": "57" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "key": "57" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform on renamed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform on renamed field.kt new file mode 100644 index 000000000..100abacb6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform on renamed field.kt @@ -0,0 +1,51 @@ +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `ari argument transform on renamed field` : NadelLegacyIntegrationTest( + query = """ + query { + issue(id: "ari:/i-forget-what-aris-actually-look-like/57") { + key + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + directive @interpretAri on ARGUMENT_DEFINITION + type Query { + issue(id: ID @interpretAri): Issue @renamed(from: "issueById") + } + type Issue { + key: ID @renamed(from: "id") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID): Issue + } + type Issue { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "57") { + Service_Issue(id = "57") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Service_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform snapshot.kt new file mode 100644 index 000000000..083df7640 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`ari argument transform`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `ari argument transform snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | issue(id: "57") { + | __typename__rename__key: __typename + | rename__key__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "rename__key__id": "57", + | "__typename__rename__key": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "key": "57" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "key": "57" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform.kt new file mode 100644 index 000000000..3271a4b56 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/ari use case/ari argument transform.kt @@ -0,0 +1,51 @@ +package graphql.nadel.tests.legacy.`chained transforms`.`ari use case` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `ari argument transform` : NadelLegacyIntegrationTest( + query = """ + query { + issue(id: "ari:/i-forget-what-aris-actually-look-like/57") { + key + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + directive @interpretAri on ARGUMENT_DEFINITION + type Query { + issue(id: ID @interpretAri): Issue + } + type Issue { + key: ID @renamed(from: "id") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "57") { + Service_Issue(id = "57") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Service_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/two transforms on a field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/two transforms on a field snapshot.kt new file mode 100644 index 000000000..d050cca95 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/two transforms on a field snapshot.kt @@ -0,0 +1,94 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`chained transforms` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`two transforms on a field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `two transforms on a field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | uuid_typename: __typename + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "id": "FOO-1", + | "uuid_typename": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `Foo.epicEntity` has been removed by RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "id": "FOO-1", + * "epicEntity": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `Foo.epicEntity` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "id": "FOO-1", + | "epicEntity": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/two transforms on a field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/two transforms on a field.kt new file mode 100644 index 000000000..efdee67fc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/chained transforms/two transforms on a field.kt @@ -0,0 +1,67 @@ +package graphql.nadel.tests.legacy.`chained transforms` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `two transforms on a field` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + id + epicEntity { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + foo: Foo + } + type Foo { + id: ID + epicEntity: Epic @renamed(from: "epic") @toBeDeleted + } + type Epic { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + epic: Epic + } + type Epic { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo(id = "FOO-1") + } + } + }, + ), + ), +) { + private data class Service_Epic( + val id: String? = null, + val name: String? = null, + ) + + private data class Service_Foo( + val id: String? = null, + val epic: Service_Epic? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside another rename of type List snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside another rename of type List snapshot.kt new file mode 100644 index 000000000..8a76fda7c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside another rename of type List snapshot.kt @@ -0,0 +1,137 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside another rename of type List`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside another rename of type List snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | boardScope { + | board { + | __typename__rename__cardChildren: __typename + | rename__cardChildren__issueChildren: issueChildren { + | __typename__deep_rename__key: __typename + | __typename__deep_rename__summary: __typename + | id + | deep_rename__key__issue: issue { + | key + | } + | deep_rename__summary__issue: issue { + | summary + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "boardScope": { + | "board": { + | "rename__cardChildren__issueChildren": [ + | { + | "id": "1234", + | "deep_rename__key__issue": { + | "key": "abc" + | }, + | "__typename__deep_rename__key": "Card", + | "deep_rename__summary__issue": { + | "summary": "Summary 1" + | }, + | "__typename__deep_rename__summary": "Card" + | }, + | { + | "id": "456", + | "deep_rename__key__issue": { + | "key": "def" + | }, + | "__typename__deep_rename__key": "Card", + | "deep_rename__summary__issue": { + | "summary": "Summary 2" + | }, + | "__typename__deep_rename__summary": "Card" + | } + | ], + | "__typename__rename__cardChildren": "Board" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "boardScope": { + * "board": { + * "cardChildren": [ + * { + * "id": "1234", + * "key": "abc", + * "summary": "Summary 1" + * }, + * { + * "id": "456", + * "key": "def", + * "summary": "Summary 2" + * } + * ] + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "boardScope": { + | "board": { + | "cardChildren": [ + | { + | "id": "1234", + | "key": "abc", + | "summary": "Summary 1" + | }, + | { + | "id": "456", + | "key": "def", + | "summary": "Summary 2" + | } + | ] + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside another rename of type List.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside another rename of type List.kt new file mode 100644 index 000000000..d91526f8f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside another rename of type List.kt @@ -0,0 +1,102 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside another rename of type List` : NadelLegacyIntegrationTest( + query = """ + query { + boardScope { + board { + cardChildren { + id + key + summary + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + boardScope: BoardScope + } + type BoardScope { + board: SoftwareBoard + } + type SoftwareBoard @renamed(from: "Board") { + cardChildren: [SoftwareCard] @renamed(from: "issueChildren") + } + type SoftwareCard @renamed(from: "Card") { + id: ID + key: String @renamed(from: "issue.key") + summary: String @renamed(from: "issue.summary") + } + """.trimIndent(), + underlyingSchema = """ + type Board { + id: ID + issueChildren: [Card] + } + type BoardScope { + board: Board + } + type Card { + id: ID + issue: Issue + } + type Issue { + id: ID + key: String + summary: String + } + type Query { + boardScope: BoardScope + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("boardScope") { env -> + Issues_BoardScope( + board = Issues_Board( + issueChildren = listOf( + Issues_Card( + id = "1234", + issue = Issues_Issue(key = "abc", summary = "Summary 1"), + ), + Issues_Card( + id = "456", + issue = Issues_Issue(key = "def", summary = "Summary 2"), + ), + ), + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_Board( + val id: String? = null, + val issueChildren: List? = null, + ) + + private data class Issues_BoardScope( + val board: Issues_Board? = null, + ) + + private data class Issues_Card( + val id: String? = null, + val issue: Issues_Issue? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val key: String? = null, + val summary: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration null object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration null object snapshot.kt new file mode 100644 index 000000000..45be83930 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration null object snapshot.kt @@ -0,0 +1,148 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside batch hydration null object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots] + */ +@Suppress("unused") +public class `deep rename inside batch hydration null object snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issuesByIds(id: ["issue-1", "issue-2", "issue-3"]) { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | batch_hydration__issue__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "deep_rename__name__detail": { + | "detailName": "Memes are the DNA of the soul" + | }, + | "__typename__deep_rename__name": "Issue", + | "batch_hydration__issue__id": "issue-1" + | }, + | null, + | { + | "deep_rename__name__detail": { + | "detailName": "Names are arbitrary" + | }, + | "__typename__deep_rename__name": "Issue", + | "batch_hydration__issue__id": "issue-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "batch_hydration__issue__issueId": "issue-1", + | "__typename__batch_hydration__issue": "User" + | }, + | { + | "batch_hydration__issue__issueId": "issue-2", + | "__typename__batch_hydration__issue": "User" + | }, + | { + | "batch_hydration__issue__issueId": "issue-3", + | "__typename__batch_hydration__issue": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "users": [ + * { + * "issue": { + * "name": "Memes are the DNA of the soul" + * } + * }, + * { + * "issue": null + * }, + * { + * "issue": { + * "name": "Names are arbitrary" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "users": [ + | { + | "issue": { + | "name": "Memes are the DNA of the soul" + | } + | }, + | { + | "issue": null + | }, + | { + | "issue": { + | "name": "Names are arbitrary" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration null object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration null object.kt new file mode 100644 index 000000000..117b5c0d1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration null object.kt @@ -0,0 +1,114 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside batch hydration null object` : NadelLegacyIntegrationTest( + query = """ + query { + users { + issue { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issuesByIds(id: [ID!]): [Issue] + } + type Issue { + name: String @renamed(from: "detail.detailName") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + detail: IssueDetails + } + type IssueDetails { + detailName: String + } + type Query { + issuesByIds(id: [ID!]): [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + IssueService_Issue( + detail = IssueService_IssueDetails( + detailName = "Memes are the DNA of the soul", + ), + id = "issue-1", + ), + IssueService_Issue( + detail = IssueService_IssueDetails( + detailName = "Names are arbitrary", + ), + id = "issue-3", + ), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("id")?.map(issuesByIds::get) + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issuesByIds" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + listOf( + UserService_User(issueId = "issue-1"), + UserService_User(issueId = "issue-2"), + UserService_User(issueId = "issue-3"), + ) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + val detail: IssueService_IssueDetails? = null, + ) + + private data class IssueService_IssueDetails( + val detailName: String? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration snapshot.kt new file mode 100644 index 000000000..9866eba63 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration snapshot.kt @@ -0,0 +1,158 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside batch hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issuesByIds(id: ["issue-1", "issue-2", "issue-3"]) { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | batch_hydration__issue__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "deep_rename__name__detail": { + | "detailName": "It amounts to nothing" + | }, + | "__typename__deep_rename__name": "Issue", + | "batch_hydration__issue__id": "issue-1" + | }, + | { + | "deep_rename__name__detail": { + | "detailName": "Details are cool" + | }, + | "__typename__deep_rename__name": "Issue", + | "batch_hydration__issue__id": "issue-2" + | }, + | { + | "deep_rename__name__detail": { + | "detailName": "Names are arbitrary" + | }, + | "__typename__deep_rename__name": "Issue", + | "batch_hydration__issue__id": "issue-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "batch_hydration__issue__issueId": "issue-1", + | "__typename__batch_hydration__issue": "User" + | }, + | { + | "batch_hydration__issue__issueId": "issue-2", + | "__typename__batch_hydration__issue": "User" + | }, + | { + | "batch_hydration__issue__issueId": "issue-3", + | "__typename__batch_hydration__issue": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "users": [ + * { + * "issue": { + * "name": "It amounts to nothing" + * } + * }, + * { + * "issue": { + * "name": "Details are cool" + * } + * }, + * { + * "issue": { + * "name": "Names are arbitrary" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "users": [ + | { + | "issue": { + | "name": "It amounts to nothing" + | } + | }, + | { + | "issue": { + | "name": "Details are cool" + | } + | }, + | { + | "issue": { + | "name": "Names are arbitrary" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration.kt new file mode 100644 index 000000000..8554d7ee2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside batch hydration.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside batch hydration` : NadelLegacyIntegrationTest( + query = """ + query { + users { + issue { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issuesByIds(id: [ID!]): [Issue] + } + type Issue { + name: String @renamed(from: "detail.detailName") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + detail: IssueDetails + } + type IssueDetails { + detailName: String + } + type Query { + issuesByIds(id: [ID!]): [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + IssueService_Issue( + detail = IssueService_IssueDetails( + detailName = "It amounts to nothing", + ), + id = "issue-1", + ), + IssueService_Issue( + detail = IssueService_IssueDetails(detailName = "Details are cool"), + id = "issue-2", + ), + IssueService_Issue( + detail = IssueService_IssueDetails( + detailName = "Names are arbitrary", + ), + id = "issue-3", + ), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("id")?.map(issuesByIds::get) + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issuesByIds" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + listOf( + UserService_User(issueId = "issue-1"), + UserService_User(issueId = "issue-2"), + UserService_User(issueId = "issue-3"), + ) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + val detail: IssueService_IssueDetails? = null, + ) + + private data class IssueService_IssueDetails( + val detailName: String? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside deep rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside deep rename snapshot.kt new file mode 100644 index 000000000..a55e0f476 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside deep rename snapshot.kt @@ -0,0 +1,92 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside deep rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside deep rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | rename__issue__first: first { + | __typename__deep_rename__extras: __typename + | deep_rename__extras__details: details { + | extras { + | __typename__deep_rename__ownerName: __typename + | deep_rename__ownerName__owner: owner { + | name + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__issue__first": { + | "deep_rename__extras__details": { + | "extras": { + | "deep_rename__ownerName__owner": { + | "name": "Franklin" + | }, + | "__typename__deep_rename__ownerName": "IssueExtra" + | } + | }, + | "__typename__deep_rename__extras": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "extras": { + * "ownerName": "Franklin" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "extras": { + | "ownerName": "Franklin" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside deep rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside deep rename.kt new file mode 100644 index 000000000..76fc587fa --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside deep rename.kt @@ -0,0 +1,78 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside deep rename` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + extras { + ownerName + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issue: JiraIssue @renamed(from: "first") + } + type JiraIssue @renamed(from: "Issue") { + extras: IssueExtra @renamed(from: "details.extras") + } + type IssueExtra { + ownerName: String @renamed(from: "owner.name") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + first: Issue + } + type Issue { + details: IssueDetail + } + type IssueDetail { + extras: IssueExtra + } + type IssueExtra { + owner: User + } + type User { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("first") { env -> + Issues_Issue( + details = Issues_IssueDetail( + extras = Issues_IssueExtra( + owner = Issues_User(name = "Franklin"), + ), + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val details: Issues_IssueDetail? = null, + ) + + private data class Issues_IssueDetail( + val extras: Issues_IssueExtra? = null, + ) + + private data class Issues_IssueExtra( + val owner: Issues_User? = null, + ) + + private data class Issues_User( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydration snapshot.kt new file mode 100644 index 000000000..7c059c727 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydration snapshot.kt @@ -0,0 +1,106 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-1") { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "deep_rename__name__detail": { + | "detailName": "Detail-1" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | me { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "me": { + | "hydration__issue__issueId": "issue-1", + | "__typename__hydration__issue": "User" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "me": { + * "issue": { + * "name": "Detail-1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "me": { + | "issue": { + | "name": "Detail-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydration.kt new file mode 100644 index 000000000..55e1090ac --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydration.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside hydration` : NadelLegacyIntegrationTest( + query = """ + query { + me { + issue { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID!): Issue + } + type Issue { + name: String @renamed(from: "detail.detailName") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + detail: IssueDetails + } + type IssueDetails { + detailName: String + } + type Query { + issueById(id: ID!): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "issue-1") { + IssueService_Issue(detail = IssueService_IssueDetails(detailName = "Detail-1")) + } else { + null + } + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + me: User + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issueById" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + me: User + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("me") { env -> + UserService_User(issueId = "issue-1") + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val detail: IssueService_IssueDetails? = null, + ) + + private data class IssueService_IssueDetails( + val detailName: String? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydrations snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydrations snapshot.kt new file mode 100644 index 000000000..a2151bc80 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydrations snapshot.kt @@ -0,0 +1,196 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside hydrations`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside hydrations snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-1") { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "deep_rename__name__detail": { + | "detailName": "Detail-1" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-2") { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "deep_rename__name__detail": { + | "detailName": "Detail-2" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-3") { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "deep_rename__name__detail": { + | "detailName": "A name goes here" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "hydration__issue__issueId": "issue-1", + | "__typename__hydration__issue": "User" + | }, + | { + | "hydration__issue__issueId": "issue-2", + | "__typename__hydration__issue": "User" + | }, + | { + | "hydration__issue__issueId": "issue-3", + | "__typename__hydration__issue": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "users": [ + * { + * "issue": { + * "name": "Detail-1" + * } + * }, + * { + * "issue": { + * "name": "Detail-2" + * } + * }, + * { + * "issue": { + * "name": "A name goes here" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "users": [ + | { + | "issue": { + | "name": "Detail-1" + | } + | }, + | { + | "issue": { + | "name": "Detail-2" + | } + | }, + | { + | "issue": { + | "name": "A name goes here" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydrations.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydrations.kt new file mode 100644 index 000000000..1294788af --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside hydrations.kt @@ -0,0 +1,104 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside hydrations` : NadelLegacyIntegrationTest( + query = """ + query { + users { + issue { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID!): Issue + } + type Issue { + name: String @renamed(from: "detail.detailName") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + detail: IssueDetails + } + type IssueDetails { + detailName: String + } + type Query { + issueById(id: ID!): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "issue-1") { + IssueService_Issue(detail = IssueService_IssueDetails(detailName = "Detail-1")) + } else if (env.getArgument("id") == "issue-2") { + IssueService_Issue(detail = IssueService_IssueDetails(detailName = "Detail-2")) + } else if (env.getArgument("id") == "issue-3") { + IssueService_Issue(detail = IssueService_IssueDetails(detailName = "A name goes here")) + } else { + null + } + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issueById" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + listOf( + UserService_User(issueId = "issue-1"), + UserService_User(issueId = "issue-2"), + UserService_User(issueId = "issue-3"), + ) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val detail: IssueService_IssueDetails? = null, + ) + + private data class IssueService_IssueDetails( + val detailName: String? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside list snapshot.kt new file mode 100644 index 000000000..3a4112777 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside list snapshot.kt @@ -0,0 +1,106 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | rename__issues__all: all { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | key + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__issues__all": [ + | { + | "deep_rename__name__details": { + | "key": "GQLGW-1012" + | }, + | "__typename__deep_rename__name": "Issue" + | }, + | { + | "deep_rename__name__details": null, + | "__typename__deep_rename__name": "Issue" + | }, + | { + | "deep_rename__name__details": { + | "key": "Fix the bug" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "name": "GQLGW-1012" + * }, + * { + * "name": null + * }, + * { + * "name": "Fix the bug" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "name": "GQLGW-1012" + | }, + | { + | "name": null + | }, + | { + | "name": "Fix the bug" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside list.kt new file mode 100644 index 000000000..a8efedc23 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside list.kt @@ -0,0 +1,61 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside list` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [JiraIssue] @renamed(from: "all") + } + type JiraIssue @renamed(from: "Issue") { + name: String @renamed(from: "details.key") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + all: [Issue] + } + type Issue { + details: IssueDetail + } + type IssueDetail { + key: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("all") { env -> + listOf( + Issues_Issue(details = Issues_IssueDetail(key = "GQLGW-1012")), + Issues_Issue(details = null), + Issues_Issue( + details = Issues_IssueDetail( + key = "Fix the bug", + ), + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val details: Issues_IssueDetail? = null, + ) + + private data class Issues_IssueDetail( + val key: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside rename snapshot.kt new file mode 100644 index 000000000..120307cce --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside rename snapshot.kt @@ -0,0 +1,116 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | rename__first__first: first { + | __typename + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__first__first": { + | "__typename": "Issue", + | "deep_rename__name__details": { + | "name": "name-from-details" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | rename__issue__first: first { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__issue__first": { + | "deep_rename__name__details": { + | "name": "name-from-details-2" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "first": { + * "__typename": "JiraIssue", + * "name": "name-from-details" + * }, + * "issue": { + * "name": "name-from-details-2" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "first": { + | "__typename": "JiraIssue", + | "name": "name-from-details" + | }, + | "issue": { + | "name": "name-from-details-2" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside rename.kt new file mode 100644 index 000000000..3a3c8f387 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside rename.kt @@ -0,0 +1,63 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside rename` : NadelLegacyIntegrationTest( + query = """ + query { + first: issue { + __typename + name + } + issue { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issue: JiraIssue @renamed(from: "first") + } + type JiraIssue @renamed(from: "Issue") { + name: String @renamed(from: "details.name") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + first: Issue + } + type Issue { + details: IssueDetail + } + type IssueDetail { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("first") { env -> + if (env.field.resultKey == "rename__issue__first") { + Issues_Issue(details = Issues_IssueDetail(name = "name-from-details-2")) + } else if (env.field.resultKey == "rename__first__first") { + Issues_Issue(details = Issues_IssueDetail(name = "name-from-details")) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val details: Issues_IssueDetail? = null, + ) + + private data class Issues_IssueDetail( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside renamed type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside renamed type snapshot.kt new file mode 100644 index 000000000..41f0d9783 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside renamed type snapshot.kt @@ -0,0 +1,116 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename inside renamed type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename inside renamed type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | first { + | __typename + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "first": { + | "__typename": "Issue", + | "deep_rename__name__details": { + | "name": "name-from-details" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | second: first { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "second": { + | "deep_rename__name__details": { + | "name": "name-from-details-2" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "first": { + * "__typename": "JiraIssue", + * "name": "name-from-details" + * }, + * "second": { + * "name": "name-from-details-2" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "first": { + | "__typename": "JiraIssue", + | "name": "name-from-details" + | }, + | "second": { + | "name": "name-from-details-2" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside renamed type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside renamed type.kt new file mode 100644 index 000000000..e2b25ffa6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename inside renamed type.kt @@ -0,0 +1,63 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename inside renamed type` : NadelLegacyIntegrationTest( + query = """ + query { + first { + __typename + name + } + second: first { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + first: JiraIssue + } + type JiraIssue @renamed(from: "Issue") { + name: String @renamed(from: "details.name") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + first: Issue + } + type Issue { + details: IssueDetail + } + type IssueDetail { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("first") { env -> + if (env.field.resultKey == "first") { + Issues_Issue(details = Issues_IssueDetail(name = "name-from-details")) + } else if (env.field.resultKey == "second") { + Issues_Issue(details = Issues_IssueDetail(name = "name-from-details-2")) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val details: Issues_IssueDetail? = null, + ) + + private data class Issues_IssueDetail( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename nested inside renamed type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename nested inside renamed type snapshot.kt new file mode 100644 index 000000000..f0cda12f9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename nested inside renamed type snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename nested inside renamed type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename nested inside renamed type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | first { + | user { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "first": { + | "user": { + | "deep_rename__name__details": { + | "firstName": "name-from-details" + | }, + | "__typename__deep_rename__name": "User" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | second: first { + | __typename + | user { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "second": { + | "__typename": "Issue", + | "user": { + | "deep_rename__name__details": { + | "firstName": "name-from-details-2" + | }, + | "__typename__deep_rename__name": "User" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "first": { + * "user": { + * "name": "name-from-details" + * } + * }, + * "second": { + * "__typename": "JiraIssue", + * "user": { + * "name": "name-from-details-2" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "first": { + | "user": { + | "name": "name-from-details" + | } + | }, + | "second": { + | "__typename": "JiraIssue", + | "user": { + | "name": "name-from-details-2" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename nested inside renamed type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename nested inside renamed type.kt new file mode 100644 index 000000000..858304922 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename nested inside renamed type.kt @@ -0,0 +1,91 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename nested inside renamed type` : NadelLegacyIntegrationTest( + query = """ + query { + first { + user { + name + } + } + second: first { + __typename + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + first: JiraIssue + } + type JiraIssue @renamed(from: "Issue") { + user: User + } + type User { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + first: Issue + } + type Issue { + user: User + } + type UserDetails { + firstName: String + } + type User { + id: ID + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("first") { env -> + if (env.field.resultKey == "first") { + Issues_Issue( + user = Issues_User( + details = Issues_UserDetails( + firstName = "name-from-details", + ), + ), + ) + } else if (env.field.resultKey == "second") { + Issues_Issue( + user = Issues_User( + details = Issues_UserDetails( + firstName = "name-from-details-2", + ), + ), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val user: Issues_User? = null, + ) + + private data class Issues_User( + val id: String? = null, + val details: Issues_UserDetails? = null, + ) + + private data class Issues_UserDetails( + val firstName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename not asked for with unions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename not asked for with unions snapshot.kt new file mode 100644 index 000000000..ce81be593 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename not asked for with unions snapshot.kt @@ -0,0 +1,101 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename not asked for with unions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename not asked for with unions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | names { + | ... on Edible { + | name + | } + | ... on Issue { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "names": [ + * { + * "name": "GQLGW-001" + * }, + * { + * "name": "GQLGW-1102" + * }, + * { + * "name": "Spaghetti" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename not asked for with unions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename not asked for with unions.kt new file mode 100644 index 000000000..e181e17f1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename not asked for with unions.kt @@ -0,0 +1,116 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename not asked for with unions` : NadelLegacyIntegrationTest( + query = """ + query { + names { + ... on JiraIssue { + name + } + ... on Edible { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + names: [HasName] + } + union HasName = JiraIssue | Edible | Troll | User + type JiraIssue @renamed(from: "Issue") { + name: String + } + type Edible { + name: String + } + type Troll { + name: String @renamed(from: "firstEat.item.name") + } + type User { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + union HasName = Issue | Edible | Troll | User + type Query { + names: [HasName] + } + type Troll { + id: ID + firstEat: EatLog + } + type EatLog { + id: ID + item: Edible + } + type Edible { + name: String + } + type Issue { + name: String + } + type UserDetails { + firstName: String + } + type User { + id: ID + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("names") { env -> + listOf( + Issues_Issue(name = "GQLGW-001"), + Issues_Issue(name = "GQLGW-1102"), + Issues_Edible(name = "Spaghetti"), + ) + } + } + wiring.type("HasName") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_EatLog( + val id: String? = null, + val item: Issues_Edible? = null, + ) + + private data class Issues_Edible( + val name: String? = null, + ) : Issues_HasName + + private sealed interface Issues_HasName + + private data class Issues_Issue( + val name: String? = null, + ) : Issues_HasName + + private data class Issues_Troll( + val id: String? = null, + val firstEat: Issues_EatLog? = null, + ) : Issues_HasName + + private data class Issues_User( + val id: String? = null, + val details: Issues_UserDetails? = null, + ) : Issues_HasName + + private data class Issues_UserDetails( + val firstName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object snapshot.kt new file mode 100644 index 000000000..f8f19c8e5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object snapshot.kt @@ -0,0 +1,130 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename of an object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename of an object snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__deep_rename__authorName: __typename + | deep_rename__authorName__authorDetails: authorDetails { + | name { + | __typename__rename__firstName: __typename + | __typename__rename__lastName: __typename + | rename__firstName__fName: fName + | rename__lastName__lName: lName + | } + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "deep_rename__authorName__authorDetails": { + | "name": { + | "rename__firstName__fName": "George", + | "__typename__rename__firstName": "Name", + | "rename__lastName__lName": "Smith", + | "__typename__rename__lastName": "Name" + | } + | }, + | "__typename__deep_rename__authorName": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "deep_rename__authorName__authorDetails": { + | "name": { + | "rename__firstName__fName": "Elizabeth", + | "__typename__rename__firstName": "Name", + | "rename__lastName__lName": "Windsor", + | "__typename__rename__lastName": "Name" + | } + | }, + | "__typename__deep_rename__authorName": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authorName": { + * "firstName": "George", + * "lastName": "Smith" + * } + * }, + * { + * "id": "ISSUE-2", + * "authorName": { + * "firstName": "Elizabeth", + * "lastName": "Windsor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authorName": { + | "firstName": "George", + | "lastName": "Smith" + | } + | }, + | { + | "id": "ISSUE-2", + | "authorName": { + | "firstName": "Elizabeth", + | "lastName": "Windsor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object with transformations inside object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object with transformations inside object snapshot.kt new file mode 100644 index 000000000..e4e00a737 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object with transformations inside object snapshot.kt @@ -0,0 +1,128 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename of an object with transformations inside object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename of an object with transformations inside object snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__deep_rename__authorName: __typename + | deep_rename__authorName__authorDetails: authorDetails { + | name { + | __typename__rename__firstName: __typename + | lastName + | rename__firstName__originalFirstName: originalFirstName + | } + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "deep_rename__authorName__authorDetails": { + | "name": { + | "rename__firstName__originalFirstName": "George", + | "__typename__rename__firstName": "OriginalName", + | "lastName": "Smith" + | } + | }, + | "__typename__deep_rename__authorName": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "deep_rename__authorName__authorDetails": { + | "name": { + | "rename__firstName__originalFirstName": "Elizabeth", + | "__typename__rename__firstName": "OriginalName", + | "lastName": "Windsor" + | } + | }, + | "__typename__deep_rename__authorName": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authorName": { + * "lastName": "Smith", + * "firstName": "George" + * } + * }, + * { + * "id": "ISSUE-2", + * "authorName": { + * "lastName": "Windsor", + * "firstName": "Elizabeth" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authorName": { + | "lastName": "Smith", + | "firstName": "George" + | } + | }, + | { + | "id": "ISSUE-2", + | "authorName": { + | "lastName": "Windsor", + | "firstName": "Elizabeth" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object with transformations inside object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object with transformations inside object.kt new file mode 100644 index 000000000..cc97c5cbb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object with transformations inside object.kt @@ -0,0 +1,86 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename of an object with transformations inside object` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authorName { + firstName + lastName + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authorName: Name @renamed(from: "authorDetails.name") + } + type Name @renamed(from: "OriginalName") { + firstName: String @renamed(from: "originalFirstName") + lastName: String + } + """.trimIndent(), + underlyingSchema = """ + type AuthorDetail { + name: OriginalName + } + type Issue { + authorDetails: AuthorDetail + id: ID + } + type OriginalName { + lastName: String + originalFirstName: String + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorDetails = Issues_AuthorDetail( + name = Issues_OriginalName(lastName = "Smith", originalFirstName = "George"), + ), + id = "ISSUE-1", + ), + Issues_Issue( + authorDetails = Issues_AuthorDetail( + name = Issues_OriginalName(lastName = "Windsor", originalFirstName = "Elizabeth"), + ), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_AuthorDetail( + val name: Issues_OriginalName? = null, + ) + + private data class Issues_Issue( + val authorDetails: Issues_AuthorDetail? = null, + val id: String? = null, + ) + + private data class Issues_OriginalName( + val lastName: String? = null, + val originalFirstName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object.kt new file mode 100644 index 000000000..43266401f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of an object.kt @@ -0,0 +1,92 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename of an object` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authorName { + firstName + lastName + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authorName: Name @renamed(from: "authorDetails.name") + } + type Name { + firstName: String @renamed(from: "fName") + lastName: String @renamed(from: "lName") + } + """.trimIndent(), + underlyingSchema = """ + type AuthorDetail { + name: Name + } + type Issue { + authorDetails: AuthorDetail + id: ID + } + type Name { + fName: String + lName: String + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorDetails = Issues_AuthorDetail( + name = Issues_Name( + fName = "George", + lName = "Smith", + ), + ), + id = "ISSUE-1", + ), + Issues_Issue( + authorDetails = Issues_AuthorDetail( + name = Issues_Name( + fName = "Elizabeth", + lName = "Windsor" + ) + ), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_AuthorDetail( + val name: Issues_Name? = null, + ) + + private data class Issues_Issue( + val authorDetails: Issues_AuthorDetail? = null, + val id: String? = null, + ) + + private data class Issues_Name( + val fName: String? = null, + val lName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list of list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list of list snapshot.kt new file mode 100644 index 000000000..c2183b3cd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list of list snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename of list of list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename of list of list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | details { + | __typename__deep_rename__labels: __typename + | deep_rename__labels__issue: issue { + | labels + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "details": [ + | { + | "deep_rename__labels__issue": { + | "labels": [ + | [ + | "label1", + | "label2" + | ], + | [ + | "label3" + | ] + | ] + | }, + | "__typename__deep_rename__labels": "IssueDetail" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "details": [ + * { + * "labels": [ + * [ + * "label1", + * "label2" + * ], + * [ + * "label3" + * ] + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "details": [ + | { + | "labels": [ + | [ + | "label1", + | "label2" + | ], + | [ + | "label3" + | ] + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list of list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list of list.kt new file mode 100644 index 000000000..cf14fbdfb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list of list.kt @@ -0,0 +1,62 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename of list of list` : NadelLegacyIntegrationTest( + query = """ + query { + details { + labels + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + details: [IssueDetail] + } + type IssueDetail { + labels: [[String]] @renamed(from: "issue.labels") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + labels: [[String]] + } + type IssueDetail { + issue: Issue + } + type Query { + details: [IssueDetail] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("details") { env -> + listOf( + Issues_IssueDetail( + issue = Issues_Issue( + labels = listOf( + listOf("label1", "label2"), + listOf("label3"), + ), + ), + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val labels: List?>? = null, + ) + + private data class Issues_IssueDetail( + val issue: Issues_Issue? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list snapshot.kt new file mode 100644 index 000000000..c73176195 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list snapshot.kt @@ -0,0 +1,93 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename of list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename of list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | details { + | __typename__deep_rename__labels: __typename + | deep_rename__labels__issue: issue { + | labels + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "details": [ + | { + | "deep_rename__labels__issue": { + | "labels": [ + | "label1", + | "label2" + | ] + | }, + | "__typename__deep_rename__labels": "IssueDetail" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "details": [ + * { + * "labels": [ + * "label1", + * "label2" + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "details": [ + | { + | "labels": [ + | "label1", + | "label2" + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list.kt new file mode 100644 index 000000000..14dedb14c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename of list.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename of list` : NadelLegacyIntegrationTest( + query = """ + query { + details { + labels + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + details: [IssueDetail] + } + type IssueDetail { + labels: [String] @renamed(from: "issue.labels") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + labels: [String] + } + type IssueDetail { + issue: Issue + } + type Query { + details: [IssueDetail] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("details") { env -> + listOf(Issues_IssueDetail(issue = Issues_Issue(labels = listOf("label1", "label2")))) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val labels: List? = null, + ) + + private data class Issues_IssueDetail( + val issue: Issues_Issue? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename returns null snapshot.kt new file mode 100644 index 000000000..7ff10fc6a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename returns null snapshot.kt @@ -0,0 +1,80 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | troll { + | __typename__deep_rename__name: __typename + | deep_rename__name__firstEat: firstEat { + | item { + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "troll": { + | "deep_rename__name__firstEat": { + | "item": null + | }, + | "__typename__deep_rename__name": "Troll" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "troll": { + * "name": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "troll": { + | "name": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename returns null.kt new file mode 100644 index 000000000..24562d207 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename returns null.kt @@ -0,0 +1,64 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename returns null` : NadelLegacyIntegrationTest( + query = """ + query { + troll { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + troll: Troll + } + type Troll { + name: String @renamed(from: "firstEat.item.name") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + troll: Troll + } + type Troll { + id: ID + firstEat: EatLog + } + type EatLog { + id: ID + item: Edible + } + type Edible { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("troll") { env -> + Issues_Troll(firstEat = Issues_EatLog(item = null)) + } + } + }, + ), + ), +) { + private data class Issues_EatLog( + val id: String? = null, + val item: Issues_Edible? = null, + ) + + private data class Issues_Edible( + val name: String? = null, + ) + + private data class Issues_Troll( + val id: String? = null, + val firstEat: Issues_EatLog? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with argument works snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with argument works snapshot.kt new file mode 100644 index 000000000..93926033d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with argument works snapshot.kt @@ -0,0 +1,78 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename with argument works`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename with argument works snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issue { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName(userId: "USER-01") + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "deep_rename__name__detail": { + | "detailName": "My Issue" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "name": "My Issue" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "name": "My Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with argument works.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with argument works.kt new file mode 100644 index 000000000..61b670305 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with argument works.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename with argument works` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + name(userId: "USER-01") + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + name(userId: ID!): String @renamed(from: "detail.detailName") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + detail: IssueDetails + } + type IssueDetails { + detailName(userId: ID!): String + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueService_Issue(detail = IssueService_IssueDetails(detailName = "My Issue")) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val detail: IssueService_IssueDetails? = null, + ) + + private data class IssueService_IssueDetails( + val detailName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces asking typename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces asking typename snapshot.kt new file mode 100644 index 000000000..5dcd529fd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces asking typename snapshot.kt @@ -0,0 +1,118 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename with interfaces asking typename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename with interfaces asking typename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | names { + | ... on Issue { + | __typename + | name + | } + | ... on User { + | __typename + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "names": [ + | { + | "__typename": "Issue", + | "name": "GQLGW-001" + | }, + | { + | "__typename": "Issue", + | "name": "GQLGW-1102" + | }, + | { + | "__typename": "User", + | "deep_rename__name__details": { + | "firstName": "Franklin" + | }, + | "__typename__deep_rename__name": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "names": [ + * { + * "__typename": "JiraIssue", + * "name": "GQLGW-001" + * }, + * { + * "__typename": "JiraIssue", + * "name": "GQLGW-1102" + * }, + * { + * "__typename": "User", + * "name": "Franklin" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "names": [ + | { + | "__typename": "JiraIssue", + | "name": "GQLGW-001" + | }, + | { + | "__typename": "JiraIssue", + | "name": "GQLGW-1102" + | }, + | { + | "__typename": "User", + | "name": "Franklin" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces asking typename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces asking typename.kt new file mode 100644 index 000000000..f5eb4b6cc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces asking typename.kt @@ -0,0 +1,91 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename with interfaces asking typename` : NadelLegacyIntegrationTest( + query = """ + query { + names { + __typename + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + names: [HasName] + } + type JiraIssue implements HasName @renamed(from: "Issue") { + name: String + } + interface HasName { + name: String + } + type User implements HasName { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + names: [HasName] + } + interface HasName { + name: String + } + type Issue implements HasName { + name: String + } + type UserDetails implements HasName { + name: String + firstName: String + } + type User implements HasName { + name: String + id: ID + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("names") { env -> + listOf( + Issues_Issue(name = "GQLGW-001"), + Issues_Issue(name = "GQLGW-1102"), + Issues_User(details = Issues_UserDetails(firstName = "Franklin")), + ) + } + } + wiring.type("HasName") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface Issues_HasName { + val name: String? + } + + private data class Issues_Issue( + override val name: String? = null, + ) : Issues_HasName + + private data class Issues_User( + override val name: String? = null, + val id: String? = null, + val details: Issues_UserDetails? = null, + ) : Issues_HasName + + private data class Issues_UserDetails( + override val name: String? = null, + val firstName: String? = null, + ) : Issues_HasName +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces snapshot.kt new file mode 100644 index 000000000..017bccd1f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces snapshot.kt @@ -0,0 +1,107 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename with interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename with interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | names { + | ... on Issue { + | name + | } + | ... on User { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "deep_rename__name__details": { + | "firstName": "Franklin" + | }, + | "__typename__deep_rename__name": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "names": [ + * { + * "name": "GQLGW-001" + * }, + * { + * "name": "GQLGW-1102" + * }, + * { + * "name": "Franklin" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "name": "Franklin" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces.kt new file mode 100644 index 000000000..fe42de7da --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with interfaces.kt @@ -0,0 +1,90 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename with interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + names { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + names: [HasName] + } + type JiraIssue implements HasName @renamed(from: "Issue") { + name: String + } + interface HasName { + name: String + } + type User implements HasName { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + names: [HasName] + } + interface HasName { + name: String + } + type Issue implements HasName { + name: String + } + type UserDetails implements HasName { + name: String + firstName: String + } + type User implements HasName { + id: ID + name: String + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("names") { env -> + listOf( + Issues_Issue(name = "GQLGW-001"), + Issues_Issue(name = "GQLGW-1102"), + Issues_User(details = Issues_UserDetails(firstName = "Franklin")), + ) + } + } + wiring.type("HasName") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface Issues_HasName { + val name: String? + } + + private data class Issues_Issue( + override val name: String? = null, + ) : Issues_HasName + + private data class Issues_User( + val id: String? = null, + override val name: String? = null, + val details: Issues_UserDetails? = null, + ) : Issues_HasName + + private data class Issues_UserDetails( + override val name: String? = null, + val firstName: String? = null, + ) : Issues_HasName +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more interfaces snapshot.kt new file mode 100644 index 000000000..01d88e3ad --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more interfaces snapshot.kt @@ -0,0 +1,141 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename with more interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename with more interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | names { + | ... on Edible { + | name + | } + | ... on Issue { + | name + | } + | ... on Troll { + | __typename__deep_rename__name: __typename + | deep_rename__name__firstEat: firstEat { + | item { + | name + | } + | } + | } + | ... on User { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "deep_rename__name__firstEat": { + | "item": { + | "name": "My Arm" + | } + | }, + | "__typename__deep_rename__name": "Troll" + | }, + | { + | "deep_rename__name__details": { + | "firstName": "Franklin" + | }, + | "__typename__deep_rename__name": "User" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "names": [ + * { + * "name": "GQLGW-001" + * }, + * { + * "name": "GQLGW-1102" + * }, + * { + * "name": "My Arm" + * }, + * { + * "name": "Franklin" + * }, + * { + * "name": "Spaghetti" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "name": "My Arm" + | }, + | { + | "name": "Franklin" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more interfaces.kt new file mode 100644 index 000000000..200444d0c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more interfaces.kt @@ -0,0 +1,126 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename with more interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + names { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + names: [HasName] + } + type JiraIssue implements HasName @renamed(from: "Issue") { + name: String + } + type Edible implements HasName { + name: String + } + type Troll implements HasName { + # Trolls are typically named after whatever they first attempted to eat + name: String @renamed(from: "firstEat.item.name") + } + interface HasName { + name: String + } + type User implements HasName { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + names: [HasName] + } + interface HasName { + name: String + } + type Troll implements HasName { + id: ID + name: String + firstEat: EatLog + } + type EatLog { + id: ID + item: Edible + } + type Edible implements HasName { + name: String + } + type Issue implements HasName { + name: String + } + type UserDetails { + firstName: String + } + type User implements HasName { + id: ID + name: String + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("names") { env -> + listOf( + Issues_Issue(name = "GQLGW-001"), + Issues_Issue(name = "GQLGW-1102"), + Issues_Troll(firstEat = Issues_EatLog(item = Issues_Edible(name = "My Arm"))), + Issues_User(details = Issues_UserDetails(firstName = "Franklin")), + Issues_Edible( + name = "Spaghetti", + ), + ) + } + } + wiring.type("HasName") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_EatLog( + val id: String? = null, + val item: Issues_Edible? = null, + ) + + private data class Issues_Edible( + override val name: String? = null, + ) : Issues_HasName + + private interface Issues_HasName { + val name: String? + } + + private data class Issues_Issue( + override val name: String? = null, + ) : Issues_HasName + + private data class Issues_Troll( + val id: String? = null, + override val name: String? = null, + val firstEat: Issues_EatLog? = null, + ) : Issues_HasName + + private data class Issues_User( + val id: String? = null, + override val name: String? = null, + val details: Issues_UserDetails? = null, + ) : Issues_HasName + + private data class Issues_UserDetails( + val firstName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more unions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more unions snapshot.kt new file mode 100644 index 000000000..7e1255357 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more unions snapshot.kt @@ -0,0 +1,141 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename with more unions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename with more unions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | names { + | ... on Edible { + | name + | } + | ... on Issue { + | name + | } + | ... on Troll { + | __typename__deep_rename__name: __typename + | deep_rename__name__firstEat: firstEat { + | item { + | name + | } + | } + | } + | ... on User { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "deep_rename__name__firstEat": { + | "item": { + | "name": "My Arm" + | } + | }, + | "__typename__deep_rename__name": "Troll" + | }, + | { + | "deep_rename__name__details": { + | "firstName": "Franklin" + | }, + | "__typename__deep_rename__name": "User" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "names": [ + * { + * "name": "GQLGW-001" + * }, + * { + * "name": "GQLGW-1102" + * }, + * { + * "name": "My Arm" + * }, + * { + * "name": "Franklin" + * }, + * { + * "name": "Spaghetti" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "name": "My Arm" + | }, + | { + | "name": "Franklin" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more unions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more unions.kt new file mode 100644 index 000000000..02b6c9cd1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with more unions.kt @@ -0,0 +1,126 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename with more unions` : NadelLegacyIntegrationTest( + query = """ + query { + names { + ... on JiraIssue { + name + } + ... on Edible { + name + } + ... on Troll { + name + } + ... on User { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + names: [HasName] + } + union HasName = JiraIssue | Edible | Troll | User + type JiraIssue @renamed(from: "Issue") { + name: String + } + type Edible { + name: String + } + type Troll { + name: String @renamed(from: "firstEat.item.name") + } + type User { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + union HasName = Issue | Edible | Troll | User + type Query { + names: [HasName] + } + type Troll { + id: ID + firstEat: EatLog + } + type EatLog { + id: ID + item: Edible + } + type Edible { + name: String + } + type Issue { + name: String + } + type UserDetails { + firstName: String + } + type User { + id: ID + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("names") { env -> + listOf( + Issues_Issue(name = "GQLGW-001"), + Issues_Issue(name = "GQLGW-1102"), + Issues_Troll(firstEat = Issues_EatLog(item = Issues_Edible(name = "My Arm"))), + Issues_User(details = Issues_UserDetails(firstName = "Franklin")), + Issues_Edible( + name = "Spaghetti", + ), + ) + } + } + wiring.type("HasName") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_EatLog( + val id: String? = null, + val item: Issues_Edible? = null, + ) + + private data class Issues_Edible( + val name: String? = null, + ) : Issues_HasName + + private sealed interface Issues_HasName + + private data class Issues_Issue( + val name: String? = null, + ) : Issues_HasName + + private data class Issues_Troll( + val id: String? = null, + val firstEat: Issues_EatLog? = null, + ) : Issues_HasName + + private data class Issues_User( + val id: String? = null, + val details: Issues_UserDetails? = null, + ) : Issues_HasName + + private data class Issues_UserDetails( + val firstName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with unions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with unions snapshot.kt new file mode 100644 index 000000000..ad26d2ff3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with unions snapshot.kt @@ -0,0 +1,141 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename with unions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename with unions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | names { + | ... on Edible { + | name + | } + | ... on Issue { + | name + | } + | ... on Troll { + | __typename__deep_rename__name: __typename + | deep_rename__name__firstEat: firstEat { + | item { + | name + | } + | } + | } + | ... on User { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | firstName + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "deep_rename__name__firstEat": { + | "item": { + | "name": "My Arm" + | } + | }, + | "__typename__deep_rename__name": "Troll" + | }, + | { + | "deep_rename__name__details": { + | "firstName": "Franklin" + | }, + | "__typename__deep_rename__name": "User" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "names": [ + * { + * "name": "GQLGW-001" + * }, + * { + * "name": "GQLGW-1102" + * }, + * { + * "name": "My Arm" + * }, + * { + * "name": "Franklin" + * }, + * { + * "name": "Spaghetti" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "names": [ + | { + | "name": "GQLGW-001" + | }, + | { + | "name": "GQLGW-1102" + | }, + | { + | "name": "My Arm" + | }, + | { + | "name": "Franklin" + | }, + | { + | "name": "Spaghetti" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with unions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with unions.kt new file mode 100644 index 000000000..644070093 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename with unions.kt @@ -0,0 +1,126 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename with unions` : NadelLegacyIntegrationTest( + query = """ + query { + names { + ... on JiraIssue { + name + } + ... on Edible { + name + } + ... on Troll { + name + } + ... on User { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + names: [HasName] + } + union HasName = JiraIssue | Edible | Troll | User + type JiraIssue @renamed(from: "Issue") { + name: String + } + type Edible { + name: String + } + type Troll { + name: String @renamed(from: "firstEat.item.name") + } + type User { + name: String @renamed(from: "details.firstName") + } + """.trimIndent(), + underlyingSchema = """ + union HasName = Issue | Edible | Troll | User + type Query { + names: [HasName] + } + type Troll { + id: ID + firstEat: EatLog + } + type EatLog { + id: ID + item: Edible + } + type Edible { + name: String + } + type Issue { + name: String + } + type UserDetails { + firstName: String + } + type User { + id: ID + details: UserDetails + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("names") { env -> + listOf( + Issues_Issue(name = "GQLGW-001"), + Issues_Issue(name = "GQLGW-1102"), + Issues_Troll(firstEat = Issues_EatLog(item = Issues_Edible(name = "My Arm"))), + Issues_User(details = Issues_UserDetails(firstName = "Franklin")), + Issues_Edible( + name = "Spaghetti", + ), + ) + } + } + wiring.type("HasName") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_EatLog( + val id: String? = null, + val item: Issues_Edible? = null, + ) + + private data class Issues_Edible( + val name: String? = null, + ) : Issues_HasName + + private sealed interface Issues_HasName + + private data class Issues_Issue( + val name: String? = null, + ) : Issues_HasName + + private data class Issues_Troll( + val id: String? = null, + val firstEat: Issues_EatLog? = null, + ) : Issues_HasName + + private data class Issues_User( + val id: String? = null, + val details: Issues_UserDetails? = null, + ) : Issues_HasName + + private data class Issues_UserDetails( + val firstName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename works snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename works snapshot.kt new file mode 100644 index 000000000..44bf19708 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename works snapshot.kt @@ -0,0 +1,78 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`deep rename works`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `deep rename works snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issue { + | __typename__deep_rename__name: __typename + | deep_rename__name__detail: detail { + | detailName + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "deep_rename__name__detail": { + | "detailName": "My Issue" + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "name": "My Issue" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "name": "My Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename works.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename works.kt new file mode 100644 index 000000000..859d6b605 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/deep rename works.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `deep rename works` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + name: String @renamed(from: "detail.detailName") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + detail: IssueDetails + } + type IssueDetails { + detailName: String + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueService_Issue(detail = IssueService_IssueDetails(detailName = "My Issue")) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val detail: IssueService_IssueDetails? = null, + ) + + private data class IssueService_IssueDetails( + val detailName: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames merged fields with same path and field rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames merged fields with same path and field rename snapshot.kt new file mode 100644 index 000000000..05e0ac20a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames merged fields with same path and field rename snapshot.kt @@ -0,0 +1,109 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`two deep renames merged fields with same path and field rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `two deep renames merged fields with same path and field rename snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename__deep_rename__authorId: __typename + | __typename__deep_rename__authorName: __typename + | __typename__rename__details: __typename + | deep_rename__authorId__authorDetails: authorDetails { + | authorId + | } + | deep_rename__authorName__authorDetails: authorDetails { + | name + | } + | rename__details__authorDetails: authorDetails { + | __typename__rename__extra: __typename + | rename__extra__extraInfo: extraInfo + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "id": "ISSUE-1", + | "deep_rename__authorId__authorDetails": { + | "authorId": "USER-1" + | }, + | "__typename__deep_rename__authorId": "Issue", + | "deep_rename__authorName__authorDetails": { + | "name": "User 1" + | }, + | "__typename__deep_rename__authorName": "Issue", + | "rename__details__authorDetails": { + | "rename__extra__extraInfo": "extra 1", + | "__typename__rename__extra": "AuthorDetail" + | }, + | "__typename__rename__details": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "id": "ISSUE-1", + * "authorId": "USER-1", + * "authorName": "User 1", + * "details": { + * "extra": "extra 1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "id": "ISSUE-1", + | "authorId": "USER-1", + | "authorName": "User 1", + | "details": { + | "extra": "extra 1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames merged fields with same path and field rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames merged fields with same path and field rename.kt new file mode 100644 index 000000000..83d30a8ea --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames merged fields with same path and field rename.kt @@ -0,0 +1,77 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `two deep renames merged fields with same path and field rename` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + id + authorId + authorName + details { + extra + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + id: ID + authorId: ID @renamed(from: "authorDetails.authorId") + authorName: String @renamed(from: "authorDetails.name") + details: AuthorDetail @renamed(from: "authorDetails") + } + type AuthorDetail { + extra: String @renamed(from: "extraInfo") + } + """.trimIndent(), + underlyingSchema = """ + type AuthorDetail { + authorId: ID + extraInfo: String + name: String + } + type Issue { + authorDetails: AuthorDetail + id: ID + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_Issue( + authorDetails = Issues_AuthorDetail( + authorId = "USER-1", + name = "User 1", + extraInfo = "extra 1", + ), + id = "ISSUE-1", + ) + } + } + }, + ), + ), +) { + private data class Issues_AuthorDetail( + val authorId: String? = null, + val extraInfo: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorDetails: Issues_AuthorDetail? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames snapshot.kt new file mode 100644 index 000000000..580b5c234 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames snapshot.kt @@ -0,0 +1,119 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`two deep renames`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `two deep renames snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__deep_rename__authorId: __typename + | __typename__deep_rename__authorName: __typename + | deep_rename__authorId__authorDetails: authorDetails { + | authorId + | } + | deep_rename__authorName__authorDetails: authorDetails { + | name + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "deep_rename__authorId__authorDetails": { + | "authorId": "USER-1" + | }, + | "__typename__deep_rename__authorId": "Issue", + | "deep_rename__authorName__authorDetails": { + | "name": "User 1" + | }, + | "__typename__deep_rename__authorName": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "deep_rename__authorId__authorDetails": { + | "authorId": "USER-2" + | }, + | "__typename__deep_rename__authorId": "Issue", + | "deep_rename__authorName__authorDetails": { + | "name": "User 2" + | }, + | "__typename__deep_rename__authorName": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authorId": "USER-1", + * "authorName": "User 1" + * }, + * { + * "id": "ISSUE-2", + * "authorId": "USER-2", + * "authorName": "User 2" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authorId": "USER-1", + | "authorName": "User 1" + | }, + | { + | "id": "ISSUE-2", + | "authorId": "USER-2", + | "authorName": "User 2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames.kt new file mode 100644 index 000000000..4e596628c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/deep renames/two deep renames.kt @@ -0,0 +1,76 @@ +package graphql.nadel.tests.legacy.`deep renames` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `two deep renames` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authorId + authorName + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authorId: ID @renamed(from: "authorDetails.authorId") + authorName: String @renamed(from: "authorDetails.name") + } + """.trimIndent(), + underlyingSchema = """ + type AuthorDetail { + authorId: ID + name: String + } + type Issue { + authorDetails: AuthorDetail + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorDetails = Issues_AuthorDetail( + authorId = "USER-1", + name = "User 1", + ), + id = "ISSUE-1", + ), + Issues_Issue( + authorDetails = Issues_AuthorDetail( + authorId = "USER-2", + name = "User 2", + ), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class Issues_AuthorDetail( + val authorId: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorDetails: Issues_AuthorDetail? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments snapshot.kt new file mode 100644 index 000000000..d56145045 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments snapshot.kt @@ -0,0 +1,86 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`inlined all arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `inlined all arguments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: InputWithJsonUnderlying, ${'$'}v1: JSON!, ${'$'}v2: String, ${'$'}v3: String, ${'$'}v4: String) { + | hello(arg: ${'$'}v0, arg1: ${'$'}v1, arg2: ${'$'}v2, arg3: ${'$'}v3, arg4Nullable: ${'$'}v4) + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "names": [ + | "Bobba", + | "Fett" + | ], + | "payload": { + | "name": "Bobert", + | "age": "23" + | } + | }, + | "v1": { + | "interests": [ + | "photography", + | "basketball" + | ] + | }, + | "v2": null, + | "v3": "input1", + | "v4": "defaulted" + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with mixed literals and variables snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with mixed literals and variables snapshot.kt new file mode 100644 index 000000000..08feaa0b3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with mixed literals and variables snapshot.kt @@ -0,0 +1,80 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`inlined all arguments with mixed literals and variables`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `inlined all arguments with mixed literals and variables snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: UnderlyingInputArgType) { + | hello(arg: ${'$'}v0) + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "age": 50, + | "inputWithJson": { + | "names": [ + | "Bobba", + | "Fett" + | ], + | "payload": { + | "name": "Bobert", + | "age": "23" + | } + | } + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with mixed literals and variables.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with mixed literals and variables.kt new file mode 100644 index 000000000..62f0598cc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with mixed literals and variables.kt @@ -0,0 +1,81 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `inlined all arguments with mixed literals and variables` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}varX: InputWithJson) { + hello(arg: { age: 50, inputWithJson: ${'$'}varX } ) + } + """.trimIndent(), + variables = mapOf( + "varX" to mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf("name" to "Bobert", "age" to "23"), + ), + ), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: InputArgType): String + } + input InputArgType @renamed(from: "UnderlyingInputArgType") { + age: Int + inputWithJson: InputWithJson + } + input InputWithJson @renamed(from: "InputWithJsonUnderlying") { + names: [String!]! + payload: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: UnderlyingInputArgType): String + } + input UnderlyingInputArgType { + age: Int + inputWithJson: InputWithJsonUnderlying + } + input InputWithJsonUnderlying { + names: [String!]! + payload: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == + mapOf( + "age" to 50, + "inputWithJson" to mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf("name" to "Bobert", "age" to "23"), + ), + ) + ) { + "world" + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJsonUnderlying( + val names: List? = null, + val payload: Any? = null, + ) + + private data class MyService_UnderlyingInputArgType( + val age: Int? = null, + val inputWithJson: MyService_InputWithJsonUnderlying? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field input is wrapped in a list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field input is wrapped in a list snapshot.kt new file mode 100644 index 000000000..c50dc7f1c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field input is wrapped in a list snapshot.kt @@ -0,0 +1,93 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`inlined all arguments with renamed field input is wrapped in a list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `inlined all arguments with renamed field input is wrapped in a list snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: [UnderlyingInputArgType]) { + | rename__hello__helloUnderlying: helloUnderlying(arg: ${'$'}v0) { + | value + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": [ + | { + | "age": 50, + | "inputWithJson": [ + | { + | "names": [ + | "Bobba", + | "Fett" + | ], + | "payload": { + | "name": "Bobert", + | "age": "23" + | } + | } + | ] + | } + | ] + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "rename__hello__helloUnderlying": { + | "value": "world" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": { + * "value": "world" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": { + | "value": "world" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field input is wrapped in a list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field input is wrapped in a list.kt new file mode 100644 index 000000000..467d169c6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field input is wrapped in a list.kt @@ -0,0 +1,102 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `inlined all arguments with renamed field input is wrapped in a list` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}varX: [InputWithJson]) { + hello(arg: [{ age: 50, inputWithJson: ${'$'}varX }] ) { + value + } + } + """.trimIndent(), + variables = mapOf( + "varX" to listOf( + mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf("name" to "Bobert", "age" to "23"), + ), + ), + ), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: [InputArgType]): Output @renamed(from: "helloUnderlying") + } + input InputArgType @renamed(from: "UnderlyingInputArgType") { + age: Int + inputWithJson: [InputWithJson] + } + input InputWithJson @renamed(from: "InputWithJsonUnderlying") { + names: [String!]! + payload: JSON + } + type Output @renamed(from: "OutputUnderlying") { + value: String + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + helloUnderlying(arg: [UnderlyingInputArgType]): OutputUnderlying + } + input UnderlyingInputArgType { + age: Int + inputWithJson: [InputWithJsonUnderlying] + } + input InputWithJsonUnderlying { + names: [String!]! + payload: JSON + } + type OutputUnderlying { + value: String + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("helloUnderlying") { env -> + if (env.getArgument("arg") == + listOf( + mapOf( + "age" to 50, + "inputWithJson" to listOf( + mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf( + "name" to "Bobert", + "age" to "23", + ), + ), + ), + ), + ) + ) { + MyService_OutputUnderlying(`value` = "world") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJsonUnderlying( + val names: List? = null, + val payload: Any? = null, + ) + + private data class MyService_OutputUnderlying( + val `value`: String? = null, + ) + + private data class MyService_UnderlyingInputArgType( + val age: Int? = null, + val inputWithJson: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field snapshot.kt new file mode 100644 index 000000000..463a9133b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`inlined all arguments with renamed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `inlined all arguments with renamed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: UnderlyingInputArgType) { + | rename__hello__helloUnderlying: helloUnderlying(arg: ${'$'}v0) { + | value + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "age": 50, + | "inputWithJson": { + | "names": [ + | "Bobba", + | "Fett" + | ], + | "payload": { + | "name": "Bobert", + | "age": "23" + | } + | } + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "rename__hello__helloUnderlying": { + | "value": "world" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": { + * "value": "world" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": { + | "value": "world" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field.kt new file mode 100644 index 000000000..93948881b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments with renamed field.kt @@ -0,0 +1,93 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `inlined all arguments with renamed field` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}varX: InputWithJson) { + hello(arg: { age: 50, inputWithJson: ${'$'}varX } ) { + value + } + } + """.trimIndent(), + variables = mapOf( + "varX" to mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf("name" to "Bobert", "age" to "23"), + ), + ), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: InputArgType): Output @renamed(from: "helloUnderlying") + } + input InputArgType @renamed(from: "UnderlyingInputArgType") { + age: Int + inputWithJson: InputWithJson + } + input InputWithJson @renamed(from: "InputWithJsonUnderlying") { + names: [String!]! + payload: JSON + } + type Output @renamed(from: "OutputUnderlying") { + value: String + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + helloUnderlying(arg: UnderlyingInputArgType): OutputUnderlying + } + input UnderlyingInputArgType { + age: Int + inputWithJson: InputWithJsonUnderlying + } + input InputWithJsonUnderlying { + names: [String!]! + payload: JSON + } + type OutputUnderlying { + value: String + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("helloUnderlying") { env -> + if (env.getArgument("arg") == + mapOf( + "age" to 50, + "inputWithJson" to mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf("name" to "Bobert", "age" to "23"), + ), + ) + ) { + MyService_OutputUnderlying(`value` = "world") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJsonUnderlying( + val names: List? = null, + val payload: Any? = null, + ) + + private data class MyService_OutputUnderlying( + val `value`: String? = null, + ) + + private data class MyService_UnderlyingInputArgType( + val age: Int? = null, + val inputWithJson: MyService_InputWithJsonUnderlying? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments.kt new file mode 100644 index 000000000..0ccf9a53a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined all arguments.kt @@ -0,0 +1,80 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `inlined all arguments` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}inputVar1: String, ${'$'}inputVar2: String! = "defaulted", ${'$'}inputVar3: String) { + hello( + arg: { names: ["Bobba", "Fett"] payload: {name: "Bobert", age: "23"}}, + arg1: {interests: ["photography", "basketball"]}, + arg2: null, + arg3: ${'$'}inputVar1, + arg4Nullable: ${'$'}inputVar2 + arg5Nullable: ${'$'}inputVar3 + ) + } + """.trimIndent(), + variables = mapOf("inputVar1" to "input1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello( + arg: InputWithJson, + arg1: JSON!, + arg2: String, + arg3: String, + arg4Nullable: String, + arg5Nullable: String + ): String + } + input InputWithJson @renamed(from: "InputWithJsonUnderlying") { + names: [String!]! + payload: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: InputWithJsonUnderlying, + arg1: JSON!, arg2: String, arg3: String, arg4Nullable: String, arg5Nullable: String): String + } + input InputWithJsonUnderlying { + names: [String!]! + payload: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == + mapOf( + "names" to listOf("Bobba", "Fett"), + "payload" to mapOf("name" to "Bobert", "age" to "23"), + ) && + env.getArgument("arg1") == + mapOf("interests" to listOf("photography", "basketball")) && + env.getArgument("arg2") == null && + env.getArgument("arg3") == "input1" && + env.getArgument("arg4Nullable") == "defaulted" + ) { + "world" + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJsonUnderlying( + val names: List? = null, + val payload: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined json arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined json arguments snapshot.kt new file mode 100644 index 000000000..7b169e863 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined json arguments snapshot.kt @@ -0,0 +1,77 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`inlined json arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `inlined json arguments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: JSON, ${'$'}v1: JSON!) { + | hello(arg: {payload : ${'$'}v0}, arg1: ${'$'}v1) + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "name": "Bobert", + | "age": "23" + | }, + | "v1": { + | "interests": [ + | "photography", + | "basketball" + | ] + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined json arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined json arguments.kt new file mode 100644 index 000000000..2560cb6a7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/inlined json arguments.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `inlined json arguments` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + hello(arg: {payload: {name: "Bobert", age: "23"}}, arg1: {interests: ["photography", "basketball"]}) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: InputWithJson, arg1: JSON!): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: InputWithJson, arg1: JSON!): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == + mapOf( + "payload" to mapOf( + "name" to "Bobert", + "age" to "23", + ), + ) && + env.getArgument("arg1") == + mapOf( + "interests" to listOf( + "photography", + "basketball", + ), + ) + ) { + "world" + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJson( + val payload: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/input object with json field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/input object with json field snapshot.kt new file mode 100644 index 000000000..302096e83 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/input object with json field snapshot.kt @@ -0,0 +1,70 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`input object with json field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `input object with json field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: JSON) { + | hello(arg: {payload : ${'$'}v0}) + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "48x48": "file.jpeg" + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/input object with json field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/input object with json field.kt new file mode 100644 index 000000000..017e724ae --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/input object with json field.kt @@ -0,0 +1,52 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `input object with json field` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}var: JSON!) { + hello(arg: {payload: ${'$'}var}) + } + """.trimIndent(), + variables = mapOf("var" to mapOf("48x48" to "file.jpeg")), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: InputWithJson): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: InputWithJson): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == mapOf("payload" to mapOf("48x48" to "file.jpeg"))) { + "world" + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJson( + val payload: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments snapshot.kt new file mode 100644 index 000000000..3dde3b585 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`primitive json arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `primitive json arguments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: JSON, ${'$'}v1: JSON!) { + | hello(arg: {payload : ${'$'}v0}, arg1: ${'$'}v1) + | } + """.trimMargin(), + variables = """ + | { + | "v0": "String JSON input", + | "v1": false + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments variables snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments variables snapshot.kt new file mode 100644 index 000000000..c69663851 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments variables snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`primitive json arguments variables`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `primitive json arguments variables snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery(${'$'}v0: JSON, ${'$'}v1: JSON!) { + | hello(arg: {payload : ${'$'}v0}, arg1: ${'$'}v1) + | } + """.trimMargin(), + variables = """ + | { + | "v0": "String JSON input", + | "v1": false + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": "world" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": "world" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments variables.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments variables.kt new file mode 100644 index 000000000..9ab05b26a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments variables.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `primitive json arguments variables` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}var1: JSON!, ${'$'}var2: JSON!) { + hello(arg: {payload: ${'$'}var1}, arg1: ${'$'}var2) + } + """.trimIndent(), + variables = mapOf("var1" to "String JSON input", "var2" to false), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: InputWithJson, arg1: JSON!): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: InputWithJson, arg1: JSON!): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == mapOf("payload" to "String JSON input") && + env.getArgument("arg1") == false + ) { + "world" + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJson( + val payload: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments.kt new file mode 100644 index 000000000..269b9a515 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/document variable handling/primitive json arguments.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.`document variable handling` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `primitive json arguments` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + hello(arg: {payload: "String JSON input"}, arg1: false) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: InputWithJson, arg1: JSON!): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: InputWithJson, arg1: JSON!): String + } + input InputWithJson { + payload: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == mapOf("payload" to "String JSON input") && + env.getArgument("arg1") == false + ) { + "world" + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class MyService_InputWithJson( + val payload: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles complex fragments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles complex fragments snapshot.kt new file mode 100644 index 000000000..757432f21 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles complex fragments snapshot.kt @@ -0,0 +1,94 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`dynamic service resolution handles complex fragments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `dynamic service resolution handles complex fragments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "RepoService", + query = """ + | { + | node(id: "pull-request:id-123") { + | id + | ... on PullRequest { + | author { + | avatarUrl + | name + | } + | description + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123", + | "description": "this is a pull request", + | "author": { + | "name": "I'm an User", + | "avatarUrl": "https://avatar.acme.com/user-123" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "node": { + * "id": "pull-request:id-123", + * "description": "this is a pull request", + * "author": { + * "name": "I'm an User", + * "avatarUrl": "https://avatar.acme.com/user-123" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123", + | "description": "this is a pull request", + | "author": { + | "name": "I'm an User", + | "avatarUrl": "https://avatar.acme.com/user-123" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles complex fragments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles complex fragments.kt new file mode 100644 index 000000000..c5151552f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles complex fragments.kt @@ -0,0 +1,162 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `dynamic service resolution handles complex fragments` : NadelLegacyIntegrationTest( + query = """ + { + node(id: "pull-request:id-123") { + ... { + ... { + ... on PullRequest { + id + } + } + } + ... on PullRequest { + description + author { + ... on User { + name + ... { + avatarUrl + } + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + author: User + } + type User { + name: String + avatarUrl: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + author: User + } + type User { + name: String + avatarUrl: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "pull-request:id-123") { + RepoService_PullRequest( + id = "pull-request:id-123", + author = RepoService_User( + avatarUrl = "https://avatar.acme.com/user-123", + name = "I'm an User", + ), + description = "this is a pull request", + ) + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "IssueService", + overallSchema = """ + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + val author: RepoService_User? = null, + ) : RepoService_Node + + private data class RepoService_User( + val name: String? = null, + val avatarUrl: String? = null, + ) + + private data class IssueService_Issue( + override val id: String? = null, + val issueKey: String? = null, + ) : IssueService_Node + + private interface IssueService_Node { + val id: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles inline fragments from multiple services snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles inline fragments from multiple services snapshot.kt new file mode 100644 index 000000000..eef67c90f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles inline fragments from multiple services snapshot.kt @@ -0,0 +1,81 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`dynamic service resolution handles inline fragments from multiple services`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `dynamic service resolution handles inline fragments from multiple services snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "RepoService", + query = """ + | { + | node(id: "pull-request:id-123") { + | __typename__type_filter__issueKey: __typename + | id + | ... on PullRequest { + | description + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123", + | "__typename__type_filter__issueKey": "PullRequest", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "node": { + * "id": "pull-request:id-123", + * "description": "this is a pull request" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles inline fragments from multiple services.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles inline fragments from multiple services.kt new file mode 100644 index 000000000..af0b5f89d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution handles inline fragments from multiple services.kt @@ -0,0 +1,134 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `dynamic service resolution handles inline fragments from multiple services` : NadelLegacyIntegrationTest( + query = """ + { + node(id: "pull-request:id-123") { + # this fragment uses a type from the RepoService + ... on PullRequest { + id + description + } + # and this one uses a type from IssueService + ... on Issue { + id + issueKey + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "pull-request:id-123") { + RepoService_PullRequest( + id = "pull-request:id-123", + description = "this is a pull request", + ) + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "IssueService", + overallSchema = """ + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + ) : RepoService_Node + + private data class IssueService_Issue( + override val id: String? = null, + val issueKey: String? = null, + ) : IssueService_Node + + private interface IssueService_Node { + val id: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services snapshot.kt new file mode 100644 index 000000000..1a7b6cb7e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`dynamic service resolution multiple services`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `dynamic service resolution multiple services snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issue: node(id: "issue/id-123") { + | id + | ... on Issue { + | issueKey + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "id": "issue/id-123", + | "issueKey": "ISSUE-1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "RepoService", + query = """ + | { + | pr: node(id: "pull-request:id-123") { + | id + | ... on PullRequest { + | description + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pr": { + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pr": { + * "id": "pull-request:id-123", + * "description": "this is a pull request" + * }, + * "issue": { + * "id": "issue/id-123", + * "issueKey": "ISSUE-1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pr": { + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | }, + | "issue": { + | "id": "issue/id-123", + | "issueKey": "ISSUE-1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services with one unmapped node lookup snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services with one unmapped node lookup snapshot.kt new file mode 100644 index 000000000..b8ed5463d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services with one unmapped node lookup snapshot.kt @@ -0,0 +1,105 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`dynamic service resolution multiple services with one unmapped node lookup`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `dynamic service resolution multiple services with one unmapped node lookup snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issue: node(id: "issue/id-123") { + | id + | ... on Issue { + | issueKey + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "id": "issue/id-123", + | "issueKey": "ISSUE-1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Could not resolve service for field: /commit", + * "locations": [], + * "path": [ + * "commit" + * ], + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": { + * "commit": null, + * "issue": { + * "id": "issue/id-123", + * "issueKey": "ISSUE-1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Could not resolve service for field: /commit", + | "locations": [], + | "path": [ + | "commit" + | ], + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": { + | "commit": null, + | "issue": { + | "id": "issue/id-123", + | "issueKey": "ISSUE-1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services with one unmapped node lookup.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services with one unmapped node lookup.kt new file mode 100644 index 000000000..56b254f62 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services with one unmapped node lookup.kt @@ -0,0 +1,131 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `dynamic service resolution multiple services with one unmapped node lookup` : NadelLegacyIntegrationTest( + query = """ + { + commit: node(id: "commit:id-123") { + ... on PullRequest { + id + description + } + } + issue: node(id: "issue/id-123") { + ... on Issue { + id + issueKey + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "IssueService", + overallSchema = """ + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "issue/id-123") { + IssueService_Issue(id = "issue/id-123", issueKey = "ISSUE-1") + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + ) : RepoService_Node + + private data class IssueService_Issue( + override val id: String? = null, + val issueKey: String? = null, + ) : IssueService_Node + + private interface IssueService_Node { + val id: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services.kt new file mode 100644 index 000000000..e42b5f34c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution multiple services.kt @@ -0,0 +1,143 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `dynamic service resolution multiple services` : NadelLegacyIntegrationTest( + query = """ + { + pr: node(id: "pull-request:id-123") { + ... on PullRequest { + id + description + } + } + issue: node(id: "issue/id-123") { + ... on Issue { + id + issueKey + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "pull-request:id-123") { + RepoService_PullRequest( + id = "pull-request:id-123", + description = "this is a pull request", + ) + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "IssueService", + overallSchema = """ + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "issue/id-123") { + IssueService_Issue(id = "issue/id-123", issueKey = "ISSUE-1") + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + ) : RepoService_Node + + private data class IssueService_Issue( + override val id: String? = null, + val issueKey: String? = null, + ) : IssueService_Node + + private interface IssueService_Node { + val id: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution simple success case snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution simple success case snapshot.kt new file mode 100644 index 000000000..3bd7d774c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution simple success case snapshot.kt @@ -0,0 +1,78 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`dynamic service resolution simple success case`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `dynamic service resolution simple success case snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "RepoService", + query = """ + | { + | node(id: "pull-request:id-123") { + | id + | ... on PullRequest { + | description + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "node": { + * "id": "pull-request:id-123", + * "description": "this is a pull request" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution simple success case.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution simple success case.kt new file mode 100644 index 000000000..20325035f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution simple success case.kt @@ -0,0 +1,89 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `dynamic service resolution simple success case` : NadelLegacyIntegrationTest( + query = """ + { + node(id: "pull-request:id-123") { + ... on PullRequest { + id + description + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "pull-request:id-123") { + RepoService_PullRequest( + id = "pull-request:id-123", + description = "this is a pull request", + ) + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + ) : RepoService_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution with no fragments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution with no fragments snapshot.kt new file mode 100644 index 000000000..7ca821a42 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution with no fragments snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`dynamic service resolution with no fragments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `dynamic service resolution with no fragments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "RepoService", + query = """ + | { + | node(id: "pull-request:id-123") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "node": { + * "id": "pull-request:id-123" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "node": { + | "id": "pull-request:id-123" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution with no fragments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution with no fragments.kt new file mode 100644 index 000000000..461a92c56 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/dynamic service resolution with no fragments.kt @@ -0,0 +1,122 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `dynamic service resolution with no fragments` : NadelLegacyIntegrationTest( + query = """ + { + node(id: "pull-request:id-123") { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "pull-request:id-123") { + RepoService_PullRequest(id = "pull-request:id-123") + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "IssueService", + overallSchema = """ + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + issueKey: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + ) : RepoService_Node + + private data class IssueService_Issue( + override val id: String? = null, + val issueKey: String? = null, + ) : IssueService_Node + + private interface IssueService_Node { + val id: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/typename is passed on queries using dynamic resolved services snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/typename is passed on queries using dynamic resolved services snapshot.kt new file mode 100644 index 000000000..6956b075a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/typename is passed on queries using dynamic resolved services snapshot.kt @@ -0,0 +1,83 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is passed on queries using dynamic resolved services`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is passed on queries using dynamic resolved services snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "RepoService", + query = """ + | { + | node(id: "pull-request:id-123") { + | __typename + | id + | ... on PullRequest { + | description + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "__typename": "PullRequest", + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "node": { + * "__typename": "PullRequest", + * "id": "pull-request:id-123", + * "description": "this is a pull request" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "node": { + | "__typename": "PullRequest", + | "id": "pull-request:id-123", + | "description": "this is a pull request" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/typename is passed on queries using dynamic resolved services.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/typename is passed on queries using dynamic resolved services.kt new file mode 100644 index 000000000..c6cbaa6e7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/dynamic service resolution/typename is passed on queries using dynamic resolved services.kt @@ -0,0 +1,90 @@ +package graphql.nadel.tests.legacy.`dynamic service resolution` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is passed on queries using dynamic resolved services` : NadelLegacyIntegrationTest( + query = """ + { + node(id: "pull-request:id-123") { + __typename + ... on PullRequest { + id + description + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + directive @dynamicServiceResolution on FIELD_DEFINITION + type Query { + node(id: ID!): Node @dynamicServiceResolution + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "RepoService", + overallSchema = """ + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID! + } + type PullRequest implements Node { + id: ID! + description: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "pull-request:id-123") { + RepoService_PullRequest( + id = "pull-request:id-123", + description = "this is a pull request", + ) + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface RepoService_Node { + val id: String? + } + + private data class RepoService_PullRequest( + override val id: String? = null, + val description: String? = null, + ) : RepoService_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and no data from a service execution are reflected in the result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and no data from a service execution are reflected in the result snapshot.kt new file mode 100644 index 000000000..5c39c4f6e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and no data from a service execution are reflected in the result snapshot.kt @@ -0,0 +1,115 @@ +// @formatter:off +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`errors and no data from a service execution are reflected in the result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `errors and no data from a service execution are reflected in the result snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Problem1", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Problem2", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Problem1", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * }, + * { + * "message": "Problem2", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "hello": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Problem1", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Problem2", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and no data from a service execution are reflected in the result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and no data from a service execution are reflected in the result.kt new file mode 100644 index 000000000..de0d8c819 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and no data from a service execution are reflected in the result.kt @@ -0,0 +1,71 @@ +package graphql.nadel.tests.legacy.errors + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `errors and no data from a service execution are reflected in the result` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + helloWithArgs(arg1: String! arg2: String): World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + helloWithArgs(arg1: String!, arg2: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Problem1", + ), + ), + toGraphQLError(mapOf("message" to "Problem2")), + ), + ).build() + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and some data from a service execution are reflected in the result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and some data from a service execution are reflected in the result snapshot.kt new file mode 100644 index 000000000..b5063e559 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and some data from a service execution are reflected in the result snapshot.kt @@ -0,0 +1,121 @@ +// @formatter:off +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`errors and some data from a service execution are reflected in the result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `errors and some data from a service execution are reflected in the result snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Problem1", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Problem2", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "hello": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Problem1", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * }, + * { + * "message": "Problem2", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "hello": { + * "name": "World" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Problem1", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Problem2", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "hello": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and some data from a service execution are reflected in the result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and some data from a service execution are reflected in the result.kt new file mode 100644 index 000000000..fdc9e45bc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/errors and some data from a service execution are reflected in the result.kt @@ -0,0 +1,70 @@ +package graphql.nadel.tests.legacy.errors + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `errors and some data from a service execution are reflected in the result` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + helloWithArgs(arg1: String! arg2: String): World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + helloWithArgs(arg1: String!, arg2: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + DataFetcherResult + .newResult() + .data( + MyService_World( + name = "World", + ), + ).errors( + listOf( + toGraphQLError(mapOf("message" to "Problem1")), + toGraphQLError(mapOf("message" to "Problem2")), + ), + ).build() + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in hydration call that fail with errors are reflected in the result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in hydration call that fail with errors are reflected in the result snapshot.kt new file mode 100644 index 000000000..dab7765c1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in hydration call that fail with errors are reflected in the result snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`exceptions in hydration call that fail with errors are reflected in the result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `exceptions in hydration call that fail with errors are reflected in the result snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId123", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "An exception occurred invoking the service 'Bar': Pop goes the weasel", + * "locations": [], + * "extensions": { + * "executionId": "test", + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "An exception occurred invoking the service 'Bar': Pop goes the weasel", + | "locations": [], + | "extensions": { + | "executionId": "test", + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in hydration call that fail with errors are reflected in the result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in hydration call that fail with errors are reflected in the result.kt new file mode 100644 index 000000000..ce7b38ded --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in hydration call that fail with errors are reflected in the result.kt @@ -0,0 +1,100 @@ +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `exceptions in hydration call that fail with errors are reflected in the result` : + NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + nestedBar { + name + nestedBar { + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bar: Bar + barById(id: ID): Bar + } + type Bar { + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.nestedBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + nestedBarId: ID + } + type Query { + bar: Bar + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + bar: Bar + @hydrated( + service: "Bar" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + name: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Foo_Foo(barId = "barId123") + } + } + }, + ), + ), + ) { + private data class Bar_Bar( + val id: String? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution call result in graphql errors and call onerror instrumentation snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution call result in graphql errors and call onerror instrumentation snapshot.kt new file mode 100644 index 000000000..4a37f44df --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution call result in graphql errors and call onerror instrumentation snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`exceptions in service execution call result in graphql errors and call onerror instrumentation`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `exceptions in service execution call result in graphql errors and call onerror instrumentation snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "An exception occurred invoking the service 'MyService': Pop goes the + * weasel", + * "locations": [], + * "extensions": { + * "executionId": "test", + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "hello": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "An exception occurred invoking the service 'MyService': Pop goes the weasel", + | "locations": [], + | "extensions": { + | "executionId": "test", + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution call result in graphql errors and call onerror instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution call result in graphql errors and call onerror instrumentation.kt new file mode 100644 index 000000000..d121b17e4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution call result in graphql errors and call onerror instrumentation.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `exceptions in service execution call result in graphql errors and call onerror instrumentation` : + NadelLegacyIntegrationTest( + query = """ + query { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + helloWithArgs(arg1: String! arg2: String): World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + helloWithArgs(arg1: String!, arg2: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution result completable future in graphql errors snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution result completable future in graphql errors snapshot.kt new file mode 100644 index 000000000..3b53ec400 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution result completable future in graphql errors snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`exceptions in service execution result completable future in graphql errors`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `exceptions in service execution result completable future in graphql errors snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "An exception occurred invoking the service 'MyService': Pop goes the + * weasel", + * "locations": [], + * "extensions": { + * "executionId": "test", + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "hello": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "An exception occurred invoking the service 'MyService': Pop goes the weasel", + | "locations": [], + | "extensions": { + | "executionId": "test", + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution result completable future in graphql errors.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution result completable future in graphql errors.kt new file mode 100644 index 000000000..43abd0d16 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/errors/exceptions in service execution result completable future in graphql errors.kt @@ -0,0 +1,52 @@ +package graphql.nadel.tests.legacy.errors + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `exceptions in service execution result completable future in graphql errors` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + helloWithArgs(arg1: String! arg2: String): World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + helloWithArgs(arg1: String!, arg2: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from input snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from input snapshot.kt new file mode 100644 index 000000000..0f3136047 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from input snapshot.kt @@ -0,0 +1,67 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`execution id` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`execution id is transferred from input`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `execution id is transferred from input snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from input.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from input.kt new file mode 100644 index 000000000..42c794129 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from input.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.`execution id` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `execution id is transferred from input` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + type Subscription { + onWorldUpdate: World + onAnotherUpdate: World + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type Subscription { + onAnotherUpdate: World + onWorldUpdate: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + null + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from provider if missing in input snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from provider if missing in input snapshot.kt new file mode 100644 index 000000000..b18232952 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from provider if missing in input snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`execution id` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`execution id is transferred from provider if missing in input`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `execution id is transferred from provider if missing in input snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from provider if missing in input.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from provider if missing in input.kt new file mode 100644 index 000000000..1f058dba9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/execution id/execution id is transferred from provider if missing in input.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.`execution id` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `execution id is transferred from provider if missing in input` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + type Subscription { + onWorldUpdate: World + onAnotherUpdate: World + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type Subscription { + onAnotherUpdate: World + onWorldUpdate: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + null + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible snapshot.kt new file mode 100644 index 000000000..932d3234c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`extending types from another service is possible`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `extending types from another service is possible snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Service1", + query = """ + | { + | anotherRoot + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "anotherRoot": "anotherRoot" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Service1", + query = """ + | { + | root { + | __typename__hydration__extension: __typename + | id + | hydration__extension__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "root": { + | "id": "rootId", + | "name": "rootName", + | "hydration__extension__id": "rootId", + | "__typename__hydration__extension": "Root" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Service2", + query = """ + | { + | lookup(id: "rootId") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "lookup": { + | "id": "rootId", + | "name": "extensionName" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "root": { + * "id": "rootId", + * "name": "rootName", + * "extension": { + * "id": "rootId", + * "name": "extensionName" + * } + * }, + * "anotherRoot": "anotherRoot" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "root": { + | "id": "rootId", + | "name": "rootName", + | "extension": { + | "id": "rootId", + | "name": "extensionName" + | } + | }, + | "anotherRoot": "anotherRoot" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible with synthetic fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible with synthetic fields snapshot.kt new file mode 100644 index 000000000..ba77b4fbe --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible with synthetic fields snapshot.kt @@ -0,0 +1,137 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`extending types from another service is possible with synthetic fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `extending types from another service is possible with synthetic fields snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Service1", + query = """ + | { + | anotherRoot + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "anotherRoot": "anotherRoot" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Service1", + query = """ + | { + | root { + | __typename__hydration__extension: __typename + | id + | hydration__extension__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "root": { + | "id": "rootId", + | "name": "rootName", + | "hydration__extension__id": "rootId", + | "__typename__hydration__extension": "Root" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Service2", + query = """ + | { + | lookUpQuery { + | lookup(id: "rootId") { + | id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "lookUpQuery": { + | "lookup": { + | "id": "rootId", + | "name": "extensionName" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "root": { + * "id": "rootId", + * "name": "rootName", + * "extension": { + * "id": "rootId", + * "name": "extensionName" + * } + * }, + * "anotherRoot": "anotherRoot" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "root": { + | "id": "rootId", + | "name": "rootName", + | "extension": { + | "id": "rootId", + | "name": "extensionName" + | } + | }, + | "anotherRoot": "anotherRoot" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible with synthetic fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible with synthetic fields.kt new file mode 100644 index 000000000..9c7804877 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible with synthetic fields.kt @@ -0,0 +1,130 @@ +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `extending types from another service is possible with synthetic fields` : NadelLegacyIntegrationTest( + query = """ + query { + root { + id + name + extension { + id + name + } + } + anotherRoot + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Service2", + overallSchema = """ + type Query { + lookUpQuery: LookUpQuery + } + type LookUpQuery { + lookup(id: ID): Extension + } + extend type Root { + extension: Extension + @hydrated( + service: "Service2" + field: "lookUpQuery.lookup" + arguments: [{name: "id" value: "${'$'}source.id"}] + identifiedBy: "id" + ) + } + type Extension { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Extension { + id: ID + name: String + } + type LookUpQuery { + lookup(id: ID): Extension + } + type Query { + lookUpQuery: LookUpQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("lookUpQuery") { + Unit + } + } + wiring.type("LookUpQuery") { type -> + type.dataFetcher("lookup") { env -> + if (env.getArgument("id") == "rootId") { + Service2_Extension(id = "rootId", name = "extensionName") + } else { + null + } + } + } + }, + ), + Service( + name = "Service1", + overallSchema = """ + extend type Query { + root: Root + } + extend type Query { + anotherRoot: String + } + type Root { + id: ID + } + extend type Root { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + root: Root + } + extend type Query { + anotherRoot: String + } + type Root { + id: ID + } + extend type Root { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("anotherRoot") { env -> + "anotherRoot" + } + .dataFetcher("root") { env -> + Service1_Root(id = "rootId", name = "rootName") + } + } + }, + ), + ), +) { + private data class Service2_Extension( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_LookUpQuery( + val lookup: Service2_Extension? = null, + ) + + private data class Service1_Root( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible.kt new file mode 100644 index 000000000..55550be6b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types from another service is possible.kt @@ -0,0 +1,115 @@ +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `extending types from another service is possible` : NadelLegacyIntegrationTest( + query = """ + query { + root { + id + name + extension { + id + name + } + } + anotherRoot + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Service2", + overallSchema = """ + type Query { + lookup(id: ID): Extension + } + extend type Root { + extension: Extension + @hydrated( + service: "Service2" + field: "lookup" + arguments: [{name: "id" value: "${'$'}source.id"}] + identifiedBy: "id" + ) + } + type Extension { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Extension { + id: ID + name: String + } + type Query { + lookup(id: ID): Extension + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("lookup") { env -> + if (env.getArgument("id") == "rootId") { + Service2_Extension(id = "rootId", name = "extensionName") + } else { + null + } + } + } + }, + ), + Service( + name = "Service1", + overallSchema = """ + extend type Query { + root: Root + } + extend type Query { + anotherRoot: String + } + type Root { + id: ID + } + extend type Root { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + root: Root + } + extend type Query { + anotherRoot: String + } + type Root { + id: ID + } + extend type Root { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("anotherRoot") { env -> + "anotherRoot" + } + .dataFetcher("root") { env -> + Service1_Root(id = "rootId", name = "rootName") + } + } + }, + ), + ), +) { + private data class Service2_Extension( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Root( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration returning a connection snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration returning a connection snapshot.kt new file mode 100644 index 000000000..8cb15d185 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration returning a connection snapshot.kt @@ -0,0 +1,154 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`extending types via hydration returning a connection`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `extending types via hydration returning a connection snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Association", + query = """ + | { + | association(filter: {name : "value"}, id: "ISSUE-1") { + | nodes { + | __typename__hydration__page: __typename + | hydration__page__pageId: pageId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "association": { + | "nodes": [ + | { + | "hydration__page__pageId": "1", + | "__typename__hydration__page": "Association" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Association", + query = """ + | { + | pages { + | page(id: "1") { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pages": { + | "page": { + | "id": "1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issue", + query = """ + | { + | synth { + | issue { + | __typename__hydration__association: __typename + | hydration__association__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "synth": { + | "issue": { + | "hydration__association__id": "ISSUE-1", + | "__typename__hydration__association": "Issue" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "synth": { + * "issue": { + * "association": { + * "nodes": [ + * { + * "page": { + * "id": "1" + * } + * } + * ] + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "synth": { + | "issue": { + | "association": { + | "nodes": [ + | { + | "page": { + | "id": "1" + | } + | } + | ] + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration returning a connection.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration returning a connection.kt new file mode 100644 index 000000000..0b6bc25de --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration returning a connection.kt @@ -0,0 +1,182 @@ +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `extending types via hydration returning a connection` : NadelLegacyIntegrationTest( + query = """ + query { + synth { + issue { + association(filter: {name: "value"}) { + nodes { + page { + id + } + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issue", + overallSchema = """ + type Query { + synth: Synth + } + type Synth { + issue: Issue + } + type Issue { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + synth: Synth + } + type Synth { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("synth") { env -> + Issue_Synth(issue = Issue_Issue(id = "ISSUE-1")) + } + } + }, + ), + Service( + name = "Association", + overallSchema = """ + type Query { + association(id: ID, filter: Filter): AssociationConnection + pages: Pages + } + type Pages { + page(id: ID): Page + } + type AssociationConnection { + nodes: [Association] + } + input Filter { + name: String + } + type Association { + id: ID + nameOfAssociation: String + page: Page + @hydrated( + service: "Association" + field: "pages.page" + arguments: [{name: "id" value: "${'$'}source.pageId"}] + ) + } + type Page { + id: ID + } + extend type Issue { + association(filter: Filter): AssociationConnection + @hydrated( + service: "Association" + field: "association" + arguments: [{name: "id" value: "${'$'}source.id"} {name: "filter" value: "${'$'}argument.filter"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Association { + id: ID + nameOfAssociation: String + pageId: ID + } + type AssociationConnection { + nodes: [Association] + } + type Page { + id: ID + } + type Pages { + page(id: ID): Page + } + type Query { + association(filter: Filter, id: ID): AssociationConnection + pages: Pages + } + input Filter { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("pages") { + Unit + } + } + wiring.type("Query") { type -> + type.dataFetcher("association") { env -> + if (env.getArgument("filter") == mapOf("name" to "value") && + env.getArgument("id") == "ISSUE-1" + ) { + Association_AssociationConnection( + nodes = listOf( + Association_Association( + pageId = "1", + ), + ), + ) + } else { + null + } + } + } + + wiring.type("Pages") { type -> + type.dataFetcher("page") { env -> + if (env.getArgument("id") == "1") { + Association_Page(id = "1") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issue_Issue( + val id: String? = null, + ) + + private data class Issue_Synth( + val issue: Issue_Issue? = null, + ) + + private data class Association_Association( + val id: String? = null, + val nameOfAssociation: String? = null, + val pageId: String? = null, + ) + + private data class Association_AssociationConnection( + val nodes: List? = null, + ) + + private data class Association_Filter( + val name: String? = null, + ) + + private data class Association_Page( + val id: String? = null, + ) + + private data class Association_Pages( + val page: Association_Page? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with arguments passed on snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with arguments passed on snapshot.kt new file mode 100644 index 000000000..485cab7fd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with arguments passed on snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`extending types via hydration with arguments passed on`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `extending types via hydration with arguments passed on snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Association", + query = """ + | { + | association(filter: {name : "value"}, id: "ISSUE-1") { + | nameOfAssociation + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "association": { + | "nameOfAssociation": "ASSOC NAME" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issue", + query = """ + | { + | issue { + | __typename__hydration__association: __typename + | hydration__association__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__association__id": "ISSUE-1", + | "__typename__hydration__association": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "association": { + * "nameOfAssociation": "ASSOC NAME" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "association": { + | "nameOfAssociation": "ASSOC NAME" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with arguments passed on.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with arguments passed on.kt new file mode 100644 index 000000000..d3db3d6de --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with arguments passed on.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `extending types via hydration with arguments passed on` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + association(filter: {name: "value"}) { + nameOfAssociation + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issue", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issue_Issue(id = "ISSUE-1") + } + } + }, + ), + Service( + name = "Association", + overallSchema = """ + type Query { + association(id: ID, filter: Filter): Association + } + input Filter { + name: String + } + type Association { + id: ID + nameOfAssociation: String + } + extend type Issue { + association(filter: Filter): Association + @hydrated( + service: "Association" + field: "association" + arguments: [{name: "id" value: "${'$'}source.id"} {name: "filter" value: "${'$'}argument.filter"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Association { + id: ID + nameOfAssociation: String + } + type Query { + association(filter: Filter, id: ID): Association + } + input Filter { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("association") { env -> + if (env.getArgument("filter") == mapOf("name" to "value") && + env.getArgument("id") == "ISSUE-1" + ) { + Association_Association(nameOfAssociation = "ASSOC NAME") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issue_Issue( + val id: String? = null, + ) + + private data class Association_Association( + val id: String? = null, + val nameOfAssociation: String? = null, + ) + + private data class Association_Filter( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with variables arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with variables arguments snapshot.kt new file mode 100644 index 000000000..e101d8728 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with variables arguments snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`extending types via hydration with variables arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `extending types via hydration with variables arguments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Association", + query = """ + | query MyQuery { + | association(filter: {name : "value"}, id: "ISSUE-1") { + | nameOfAssociation + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "association": { + | "nameOfAssociation": "ASSOC NAME" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issue", + query = """ + | query MyQuery { + | issue { + | __typename__hydration__association: __typename + | hydration__association__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__association__id": "ISSUE-1", + | "__typename__hydration__association": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "association": { + * "nameOfAssociation": "ASSOC NAME" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "association": { + | "nameOfAssociation": "ASSOC NAME" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with variables arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with variables arguments.kt new file mode 100644 index 000000000..332003d64 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/extend type/extending types via hydration with variables arguments.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.`extend type` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `extending types via hydration with variables arguments` : NadelLegacyIntegrationTest( + query = """ + query MyQuery(${'$'}filter: Filter) { + issue { + association(filter: ${'$'}filter) { + nameOfAssociation + } + } + } + """.trimIndent(), + variables = mapOf("filter" to mapOf("name" to "value")), + services = listOf( + Service( + name = "Issue", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issue_Issue(id = "ISSUE-1") + } + } + }, + ), + Service( + name = "Association", + overallSchema = """ + type Query { + association(id: ID, filter: Filter): RenamedAssociation + } + input Filter { + name: String + } + type RenamedAssociation @renamed(from: "Association") { + id: ID + nameOfAssociation: String + } + extend type Issue { + association(filter: Filter): RenamedAssociation + @hydrated( + service: "Association" + field: "association" + arguments: [{name: "id" value: "${'$'}source.id"} {name: "filter" value: "${'$'}argument.filter"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Association { + id: ID + nameOfAssociation: String + } + type Query { + association(filter: Filter, id: ID): Association + } + input Filter { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("association") { env -> + if (env.getArgument("filter") == mapOf("name" to "value") && + env.getArgument("id") == "ISSUE-1" + ) { + Association_Association(nameOfAssociation = "ASSOC NAME") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issue_Issue( + val id: String? = null, + ) + + private data class Association_Association( + val id: String? = null, + val nameOfAssociation: String? = null, + ) + + private data class Association_Filter( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hidden namespaced hydration top level field is removed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hidden namespaced hydration top level field is removed snapshot.kt new file mode 100644 index 000000000..0fe8ed305 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hidden namespaced hydration top level field is removed snapshot.kt @@ -0,0 +1,97 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hidden namespaced hydration top level field is removed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hidden namespaced hydration top level field is removed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "C1") { + | __typename__hydration__comment: __typename + | hydration__comment__commentId: commentId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "id": "C1", + | "hydration__comment__commentId": "C1", + | "__typename__hydration__comment": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `CommentApi.commentById` has been removed by + * RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issueById": { + * "id": "C1", + * "comment": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issueById": { + | "id": "C1", + | "comment": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hidden namespaced hydration top level field is removed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hidden namespaced hydration top level field is removed.kt new file mode 100644 index 000000000..9a4a497d5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hidden namespaced hydration top level field is removed.kt @@ -0,0 +1,104 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hidden namespaced hydration top level field is removed` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "C1") { + id + comment { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issueById(id: ID): Issue @namespaced + } + type Issue { + id: ID + comment: Comment @hydrated( + service: "CommentService" + field: "commentApi.commentById" + arguments: [ + {name: "id", value: "${'$'}source.commentId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID): Issue + } + type Issue { + id: ID + commentId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "C1") { + IssueService_Issue(commentId = "C1", id = "C1") + } else { + null + } + } + } + }, + ), + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentApi: CommentApi @namespaced @hidden + echo: String + } + type CommentApi { + commentById(id: ID): Comment @toBeDeleted @hidden + echo: String + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentApi: CommentApi + echo: String + } + type CommentApi { + commentById(id: ID): Comment + echo: String + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + val commentId: String? = null, + ) + + private data class CommentService_Comment( + val id: String? = null, + ) + + private data class CommentService_CommentApi( + val commentById: CommentService_Comment? = null, + val echo: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hydration top level field is removed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hydration top level field is removed snapshot.kt new file mode 100644 index 000000000..19bcaf5ad --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hydration top level field is removed snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration top level field is removed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration top level field is removed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "C1") { + | __typename__hydration__comment: __typename + | hydration__comment__commentId: commentId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "id": "C1", + | "hydration__comment__commentId": "C1", + | "__typename__hydration__comment": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `Query.commentById` has been removed by RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issueById": { + * "id": "C1", + * "comment": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `Query.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issueById": { + | "id": "C1", + | "comment": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hydration top level field is removed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hydration top level field is removed.kt new file mode 100644 index 000000000..972f2f57e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/hydration top level field is removed.kt @@ -0,0 +1,88 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration top level field is removed` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "C1") { + id + comment { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID): Issue + } + type Issue { + id: ID + comment: Comment @hydrated( + service: "CommentService" + field: "commentById" + arguments: [ + {name: "id", value: "${'$'}source.commentId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID): Issue + } + type Issue { + id: ID + commentId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "C1") { + IssueService_Issue(commentId = "C1", id = "C1") + } else { + null + } + } + } + }, + ), + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentById(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentById(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + val commentId: String? = null, + ) + + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed snapshot.kt new file mode 100644 index 000000000..aae427a0b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`namespaced field is removed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `namespaced field is removed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `CommentApi.commentById` has been removed by + * RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "commentApi": { + * "commentById": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "commentApi": { + | "commentById": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed with renames snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed with renames snapshot.kt new file mode 100644 index 000000000..cef904f49 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed with renames snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`namespaced field is removed with renames`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `namespaced field is removed with renames snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `CommentApi.commentById` has been removed by + * RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "commentApi": { + * "commentById": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "commentApi": { + | "commentById": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed with renames.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed with renames.kt new file mode 100644 index 000000000..f084a210f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed with renames.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `namespaced field is removed with renames` : NadelLegacyIntegrationTest( + query = """ + query { + commentApi { + commentById(id: "C1") { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + directive @namespaced on FIELD_DEFINITION + type Query { + commentApi: CommentApi @namespaced + } + type CommentApi @renamed(from: "CommentApiUnderlying") { + commentById(id: ID): Comment @toBeDeleted @renamed(from: "commentByIdUnderlying") + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentApi: CommentApiUnderlying + } + type CommentApiUnderlying { + commentByIdUnderlying(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) + + private data class CommentService_CommentApiUnderlying( + val commentByIdUnderlying: CommentService_Comment? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed.kt new file mode 100644 index 000000000..d32ea78f3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced field is removed.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `namespaced field is removed` : NadelLegacyIntegrationTest( + query = """ + query { + commentApi { + commentById(id: "C1") { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + directive @namespaced on FIELD_DEFINITION + type Query { + commentApi: CommentApi @namespaced + } + type CommentApi { + commentById(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentApi: CommentApi + } + type CommentApi { + commentById(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) + + private data class CommentService_CommentApi( + val commentById: CommentService_Comment? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced hydration top level field is removed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced hydration top level field is removed snapshot.kt new file mode 100644 index 000000000..a35dc98ac --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced hydration top level field is removed snapshot.kt @@ -0,0 +1,97 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`namespaced hydration top level field is removed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `namespaced hydration top level field is removed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "C1") { + | __typename__hydration__comment: __typename + | hydration__comment__commentId: commentId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "id": "C1", + | "hydration__comment__commentId": "C1", + | "__typename__hydration__comment": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `CommentApi.commentById` has been removed by + * RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issueById": { + * "id": "C1", + * "comment": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `CommentApi.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issueById": { + | "id": "C1", + | "comment": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced hydration top level field is removed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced hydration top level field is removed.kt new file mode 100644 index 000000000..4ca6bf01e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/namespaced hydration top level field is removed.kt @@ -0,0 +1,99 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `namespaced hydration top level field is removed` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "C1") { + id + comment { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issueById(id: ID): Issue @namespaced + } + type Issue { + id: ID + comment: Comment @hydrated( + service: "CommentService" + field: "commentApi.commentById" + arguments: [ + {name: "id", value: "${'$'}source.commentId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID): Issue + } + type Issue { + id: ID + commentId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "C1") { + IssueService_Issue(commentId = "C1", id = "C1") + } else { + null + } + } + } + }, + ), + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentApi: CommentApi @namespaced + } + type CommentApi { + commentById(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentApi: CommentApi + } + type CommentApi { + commentById(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + val commentId: String? = null, + ) + + private data class CommentService_Comment( + val id: String? = null, + ) + + private data class CommentService_CommentApi( + val commentById: CommentService_Comment? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/renamed top level field is not removed short circuit hint is on snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/renamed top level field is not removed short circuit hint is on snapshot.kt new file mode 100644 index 000000000..3ba8771ec --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/renamed top level field is not removed short circuit hint is on snapshot.kt @@ -0,0 +1,73 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed top level field is not removed short circuit hint is on`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed top level field is not removed short circuit hint is on snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "CommentService", + query = """ + | { + | rename__commentById__commentByIdUnderlying: commentByIdUnderlying(id: "C1") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__commentById__commentByIdUnderlying": { + | "id": "C1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "commentById": { + * "id": "C1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "commentById": { + | "id": "C1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/renamed top level field is not removed short circuit hint is on.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/renamed top level field is not removed short circuit hint is on.kt new file mode 100644 index 000000000..949353f05 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/renamed top level field is not removed short circuit hint is on.kt @@ -0,0 +1,51 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed top level field is not removed short circuit hint is on` : NadelLegacyIntegrationTest( + query = """ + query { + commentById(id: "C1") { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentById(id: ID): Comment @renamed(from: "commentByIdUnderlying") + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentByIdUnderlying(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("commentByIdUnderlying") { env -> + if (env.getArgument("id") == "C1") { + CommentService_Comment(id = "C1") + } else { + null + } + } + } + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription snapshot.kt new file mode 100644 index 000000000..0248f59da --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field is removed for a subscription`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field is removed for a subscription snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `Subscription.onCommentUpdated` has been removed by + * RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "onCommentUpdated": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `Subscription.onCommentUpdated` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "onCommentUpdated": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription with namespaced field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription with namespaced field snapshot.kt new file mode 100644 index 000000000..632281b99 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription with namespaced field snapshot.kt @@ -0,0 +1,66 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field is removed for a subscription with namespaced field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field is removed for a subscription with namespaced field snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `CommentsApi.onCommentUpdated` has been removed by + * RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "commentsApi": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `CommentsApi.onCommentUpdated` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "commentsApi": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription with namespaced field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription with namespaced field.kt new file mode 100644 index 000000000..a06987d76 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription with namespaced field.kt @@ -0,0 +1,60 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field is removed for a subscription with namespaced field` : NadelLegacyIntegrationTest( + query = """ + subscription { + commentsApi { + onCommentUpdated(id: "C1") { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentById(id: ID): Comment @toBeDeleted + } + type Subscription { + commentsApi: CommentsApi @namespaced + } + type CommentsApi { + onCommentUpdated(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentById(id: ID): Comment + } + type Subscription { + commentsApi: CommentsApi + } + type CommentsApi { + onCommentUpdated(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) + + private data class CommentService_CommentsApi( + val onCommentUpdated: CommentService_Comment? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription.kt new file mode 100644 index 000000000..777df62a7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed for a subscription.kt @@ -0,0 +1,48 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field is removed for a subscription` : NadelLegacyIntegrationTest( + query = """ + subscription { + onCommentUpdated(id: "C1") { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentById(id: ID): Comment + } + type Subscription { + onCommentUpdated(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentById(id: ID): Comment + } + type Subscription { + onCommentUpdated(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed hint is off snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed hint is off snapshot.kt new file mode 100644 index 000000000..4ff483c3e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed hint is off snapshot.kt @@ -0,0 +1,82 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field is removed hint is off`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field is removed hint is off snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "CommentService", + query = """ + | { + | uuid_typename: __typename + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "uuid_typename": "Query" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `Query.commentById` has been removed by RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "commentById": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `Query.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "commentById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed hint is off.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed hint is off.kt new file mode 100644 index 000000000..84ef838a7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed hint is off.kt @@ -0,0 +1,47 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field is removed hint is off` : NadelLegacyIntegrationTest( + query = """ + query { + commentById(id: "C1") { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentById(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentById(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("__typename") { env -> + "Query" + } + } + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed snapshot.kt new file mode 100644 index 000000000..6a77f2c27 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field is removed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field is removed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "field `Query.commentById` has been removed by RemoveFieldTestTransform", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "commentById": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "field `Query.commentById` has been removed by RemoveFieldTestTransform", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "commentById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed.kt new file mode 100644 index 000000000..7cdf247ac --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/field removed/top level field is removed.kt @@ -0,0 +1,42 @@ +package graphql.nadel.tests.legacy.`field removed` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field is removed` : NadelLegacyIntegrationTest( + query = """ + query { + commentById(id: "C1") { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "CommentService", + overallSchema = """ + directive @toBeDeleted on FIELD_DEFINITION + type Query { + commentById(id: ID): Comment @toBeDeleted + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentById(id: ID): Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/graphqlcontext/graphqlcontextispresentoninput snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/graphqlcontext/graphqlcontextispresentoninput snapshot.kt new file mode 100644 index 000000000..e36f7def4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/graphqlcontext/graphqlcontextispresentoninput snapshot.kt @@ -0,0 +1,66 @@ +// @formatter:off +package graphql.nadel.tests.legacy.graphqlcontext + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `graphqlcontextispresentoninput snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello(arg: "x") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/graphqlcontext/graphqlcontextispresentoninput.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/graphqlcontext/graphqlcontextispresentoninput.kt new file mode 100644 index 000000000..ea976f2bf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/graphqlcontext/graphqlcontextispresentoninput.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.graphqlcontext + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class graphqlcontextispresentoninput : NadelLegacyIntegrationTest( + query = """ + query { + hello(arg: "x") { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello(arg: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello(arg: String): World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + if (env.getArgument("arg") == "x") { + null + } else { + null + } + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/can query non hidden fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/can query non hidden fields snapshot.kt new file mode 100644 index 000000000..483b4cc1a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/can query non hidden fields snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can query non hidden fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can query non hidden fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": { + | "id": "ID", + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": { + * "id": "ID", + * "name": "World" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": { + | "id": "ID", + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/can query non hidden fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/can query non hidden fields.kt new file mode 100644 index 000000000..b16686aa2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/can query non hidden fields.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can query non hidden fields` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + id + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + directive @hidden on FIELD_DEFINITION + type Query { + hello: World + hiddenField: String @hidden + } + type World { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + hiddenField: String + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + MyService_World(id = "ID", name = "World") + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden fields snapshot.kt new file mode 100644 index 000000000..5bc4e677e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden fields snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`cannot query hidden fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `cannot query hidden fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Validation error (FieldUndefined@[hello/area51]) : Field 'area51' in type + * 'World' is undefined", + * "locations": [ + * { + * "line": 5, + * "column": 5 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ] + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Validation error (FieldUndefined@[hello/area51]) : Field 'area51' in type 'World' is undefined", + | "locations": [ + | { + | "line": 5, + | "column": 5 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ] + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden fields.kt new file mode 100644 index 000000000..1b68bbb4a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden fields.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `cannot query hidden fields` : NadelLegacyIntegrationTest( + query = """ + query { + hello { + id + name + area51 { + name + coordinates + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + directive @hidden on FIELD_DEFINITION + type Query { + hello: World + } + type World { + id: ID + name: String + area51: Area @hidden + } + type Area { + name: String + coordinates: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + area51: Area + } + type Area { + name: String + coordinates: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_Area( + val name: String? = null, + val coordinates: String? = null, + ) + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + val area51: MyService_Area? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden top level fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden top level fields snapshot.kt new file mode 100644 index 000000000..ba4ffdfb3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden top level fields snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`cannot query hidden top level fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `cannot query hidden top level fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Validation error (FieldUndefined@[hiddenField]) : Field 'hiddenField' in + * type 'Query' is undefined", + * "locations": [ + * { + * "line": 2, + * "column": 3 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ] + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Validation error (FieldUndefined@[hiddenField]) : Field 'hiddenField' in type 'Query' is undefined", + | "locations": [ + | { + | "line": 2, + | "column": 3 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ] + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden top level fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden top level fields.kt new file mode 100644 index 000000000..869c76607 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/cannot query hidden top level fields.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `cannot query hidden top level fields` : NadelLegacyIntegrationTest( + query = """ + query { + hiddenField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + directive @hidden on FIELD_DEFINITION + type Query { + hello: World + hiddenField: String @hidden + } + type World { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + hiddenField: String + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/introspection does not show hidden fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/introspection does not show hidden fields snapshot.kt new file mode 100644 index 000000000..62bdbd1c4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/introspection does not show hidden fields snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`introspection does not show hidden fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `introspection does not show hidden fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "__schema": { + * "queryType": { + * "fields": [ + * { + * "name": "hello" + * } + * ] + * } + * }, + * "__type": { + * "name": "World", + * "fields": [ + * { + * "name": "id" + * }, + * { + * "name": "name" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__schema": { + | "queryType": { + | "fields": [ + | { + | "name": "hello" + | } + | ] + | } + | }, + | "__type": { + | "name": "World", + | "fields": [ + | { + | "name": "id" + | }, + | { + | "name": "name" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/introspection does not show hidden fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/introspection does not show hidden fields.kt new file mode 100644 index 000000000..ac148322b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/hidden/introspection does not show hidden fields.kt @@ -0,0 +1,60 @@ +package graphql.nadel.tests.legacy.hidden + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `introspection does not show hidden fields` : NadelLegacyIntegrationTest( + query = """ + query introspection_query { + __schema { + queryType { + fields(includeDeprecated: false) { + name + } + } + } + __type(name: "World") { + name + fields { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + directive @hidden on FIELD_DEFINITION + type Query { + hello: World + hiddenField: String @hidden + } + type World { + id: ID + name: String + area51: String @hidden + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + hiddenField: String + } + type World { + id: ID + name: String + area51: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + val area51: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute in CF within instrumentation still calls enhancing instrumentation snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute in CF within instrumentation still calls enhancing instrumentation snapshot.kt new file mode 100644 index 000000000..7d11ac420 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute in CF within instrumentation still calls enhancing instrumentation snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`abort beginExecute in CF within instrumentation still calls enhancing instrumentation`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `abort beginExecute in CF within instrumentation still calls enhancing instrumentation snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "beginExecute", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": { + * "step": "beginExecute" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "beginExecute", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": { + | "step": "beginExecute" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute in CF within instrumentation still calls enhancing instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute in CF within instrumentation still calls enhancing instrumentation.kt new file mode 100644 index 000000000..d145b40a6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute in CF within instrumentation still calls enhancing instrumentation.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `abort beginExecute in CF within instrumentation still calls enhancing instrumentation` : + NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = mapOf("var1" to "val1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute within instrumentation still calls enhancing instrumentation snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute within instrumentation still calls enhancing instrumentation snapshot.kt new file mode 100644 index 000000000..a44589f14 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute within instrumentation still calls enhancing instrumentation snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`abort beginExecute within instrumentation still calls enhancing instrumentation`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `abort beginExecute within instrumentation still calls enhancing instrumentation snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "beginExecute", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": { + * "step": "beginExecute" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "beginExecute", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": { + | "step": "beginExecute" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute within instrumentation still calls enhancing instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute within instrumentation still calls enhancing instrumentation.kt new file mode 100644 index 000000000..a3b54db70 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginExecute within instrumentation still calls enhancing instrumentation.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `abort beginExecute within instrumentation still calls enhancing instrumentation` : + NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = mapOf("var1" to "val1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginQueryExecution within instrumentation still calls enhancing instrumentation snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginQueryExecution within instrumentation still calls enhancing instrumentation snapshot.kt new file mode 100644 index 000000000..0bc282430 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginQueryExecution within instrumentation still calls enhancing instrumentation snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`abort beginQueryExecution within instrumentation still calls enhancing instrumentation`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `abort beginQueryExecution within instrumentation still calls enhancing instrumentation snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "beginQueryExecution", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": { + * "step": "beginQueryExecution" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "beginQueryExecution", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": { + | "step": "beginQueryExecution" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginQueryExecution within instrumentation still calls enhancing instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginQueryExecution within instrumentation still calls enhancing instrumentation.kt new file mode 100644 index 000000000..a7d1c8cc5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginQueryExecution within instrumentation still calls enhancing instrumentation.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `abort beginQueryExecution within instrumentation still calls enhancing instrumentation` : NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = mapOf("var1" to "val1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginValidation within instrumentation still calls enhancing instrumentation snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginValidation within instrumentation still calls enhancing instrumentation snapshot.kt new file mode 100644 index 000000000..b8b53cf07 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginValidation within instrumentation still calls enhancing instrumentation snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`abort beginValidation within instrumentation still calls enhancing instrumentation`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `abort beginValidation within instrumentation still calls enhancing instrumentation snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "beginValidation", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": { + * "step": "beginValidation" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "beginValidation", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": { + | "step": "beginValidation" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginValidation within instrumentation still calls enhancing instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginValidation within instrumentation still calls enhancing instrumentation.kt new file mode 100644 index 000000000..c284ade93 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/abort beginValidation within instrumentation still calls enhancing instrumentation.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `abort beginValidation within instrumentation still calls enhancing instrumentation` : + NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = mapOf("var1" to "val1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/chained instrumentation works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/chained instrumentation works as expected snapshot.kt new file mode 100644 index 000000000..f1e9c299f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/chained instrumentation works as expected snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`chained instrumentation works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `chained instrumentation works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query OpName { + | hello { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": { + | "name": "earth", + | "id": "3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": { + * "name": "earth", + * "id": "3" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": { + | "name": "earth", + | "id": "3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/chained instrumentation works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/chained instrumentation works as expected.kt new file mode 100644 index 000000000..a03dc7781 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/chained instrumentation works as expected.kt @@ -0,0 +1,58 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `chained instrumentation works as expected` : NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = mapOf("var1" to "val1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + MyService_World(id = "3", name = "earth") + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally inside cf snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally inside cf snapshot.kt new file mode 100644 index 000000000..4f21f83db --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally inside cf snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`execution is aborted when beginExecute completes exceptionally inside cf`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `execution is aborted when beginExecute completes exceptionally inside cf snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "instrumented-error", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": null, + * "extensions": { + * "instrumentedExtension": "dummy extension" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "instrumented-error", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": null, + | "extensions": { + | "instrumentedExtension": "dummy extension" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally inside cf.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally inside cf.kt new file mode 100644 index 000000000..284a0d77b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally inside cf.kt @@ -0,0 +1,44 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `execution is aborted when beginExecute completes exceptionally inside cf` : NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally snapshot.kt new file mode 100644 index 000000000..833043d0a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`execution is aborted when beginExecute completes exceptionally`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `execution is aborted when beginExecute completes exceptionally snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "instrumented-error", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": null, + * "extensions": { + * "instrumentedExtension": "dummy extension" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "instrumented-error", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": null, + | "extensions": { + | "instrumentedExtension": "dummy extension" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally using chained instrumentation snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally using chained instrumentation snapshot.kt new file mode 100644 index 000000000..708303577 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally using chained instrumentation snapshot.kt @@ -0,0 +1,60 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`execution is aborted when beginExecute completes exceptionally using chained instrumentation`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `execution is aborted when beginExecute completes exceptionally using chained instrumentation snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "instrumented-error", + * "extensions": { + * "classification": "ExecutionAborted" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "instrumented-error", + | "extensions": { + | "classification": "ExecutionAborted" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally using chained instrumentation.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally using chained instrumentation.kt new file mode 100644 index 000000000..85f162249 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally using chained instrumentation.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `execution is aborted when beginExecute completes exceptionally using chained instrumentation` : + NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally.kt new file mode 100644 index 000000000..a85e170c6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/execution is aborted when beginExecute completes exceptionally.kt @@ -0,0 +1,44 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `execution is aborted when beginExecute completes exceptionally` : NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/instrumentation is called snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/instrumentation is called snapshot.kt new file mode 100644 index 000000000..985f8628c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/instrumentation is called snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`instrumentation is called`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `instrumentation is called snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query OpName { + | hello { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": { + | "name": "earth", + | "id": "3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "hello": { + * "name": "earth", + * "id": "3" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "hello": { + | "name": "earth", + | "id": "3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/instrumentation is called.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/instrumentation is called.kt new file mode 100644 index 000000000..f514141fa --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/instrumentation/instrumentation is called.kt @@ -0,0 +1,58 @@ +package graphql.nadel.tests.legacy.instrumentation + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `instrumentation is called` : NadelLegacyIntegrationTest( + query = """ + query OpName { + hello { + name + } + hello { + id + } + } + """.trimIndent(), + variables = mapOf("var1" to "val1"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + MyService_World(id = "3", name = "earth") + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can ask for query typename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can ask for query typename snapshot.kt new file mode 100644 index 000000000..2551a45fc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can ask for query typename snapshot.kt @@ -0,0 +1,46 @@ +// @formatter:off +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can ask for query typename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can ask for query typename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "__typename": "Query" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__typename": "Query" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can ask for query typename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can ask for query typename.kt new file mode 100644 index 000000000..3b0b87f62 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can ask for query typename.kt @@ -0,0 +1,48 @@ +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can ask for query typename` : NadelLegacyIntegrationTest( + query = """ + query { + __typename + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can specify max introspection response size snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can specify max introspection response size snapshot.kt new file mode 100644 index 000000000..122fc4bdf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can specify max introspection response size snapshot.kt @@ -0,0 +1,50 @@ +// @formatter:off +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can specify max introspection response size`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can specify max introspection response size snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "__schema": { + * "types": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__schema": { + | "types": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can specify max introspection response size.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can specify max introspection response size.kt new file mode 100644 index 000000000..54d1547f2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/can specify max introspection response size.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can specify max introspection response size` : NadelLegacyIntegrationTest( + query = """ + query Test { + __schema { + types { + name + description + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/if there are a mix of system fields and normal fields it works snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/if there are a mix of system fields and normal fields it works snapshot.kt new file mode 100644 index 000000000..b668e5bad --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/if there are a mix of system fields and normal fields it works snapshot.kt @@ -0,0 +1,85 @@ +// @formatter:off +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`if there are a mix of system fields and normal fields it works`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `if there are a mix of system fields and normal fields it works snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | hello { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "hello": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "__schema": { + * "queryType": { + * "name": "Query" + * } + * }, + * "__typename": "Query", + * "hello": { + * "name": "World" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__schema": { + | "queryType": { + | "name": "Query" + | } + | }, + | "__typename": "Query", + | "hello": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/if there are a mix of system fields and normal fields it works.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/if there are a mix of system fields and normal fields it works.kt new file mode 100644 index 000000000..ca6bb1645 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/if there are a mix of system fields and normal fields it works.kt @@ -0,0 +1,61 @@ +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `if there are a mix of system fields and normal fields it works` : NadelLegacyIntegrationTest( + query = """ + query { + __schema { + queryType { + name + } + } + __typename + hello { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("hello") { env -> + MyService_World(name = "World") + } + } + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection can be performed even with fragments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection can be performed even with fragments snapshot.kt new file mode 100644 index 000000000..deb36d184 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection can be performed even with fragments snapshot.kt @@ -0,0 +1,62 @@ +// @formatter:off +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`introspection can be performed even with fragments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `introspection can be performed even with fragments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "__schema": { + * "queryType": { + * "name": "Query" + * } + * }, + * "__type": { + * "name": "World" + * }, + * "__typename": "Query" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__schema": { + | "queryType": { + | "name": "Query" + | } + | }, + | "__type": { + | "name": "World" + | }, + | "__typename": "Query" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection can be performed even with fragments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection can be performed even with fragments.kt new file mode 100644 index 000000000..b43aa8027 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection can be performed even with fragments.kt @@ -0,0 +1,59 @@ +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `introspection can be performed even with fragments` : NadelLegacyIntegrationTest( + query = """ + query { + ...IntrospectionFrag + __type(name: "World") { + name + } + __typename + } + fragment IntrospectionFrag on Query { + __schema { + queryType { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + } + type World { + id: ID + name: String + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + hello: World + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection with variables FF on snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection with variables FF on snapshot.kt new file mode 100644 index 000000000..c36bf6c81 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection with variables FF on snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`introspection with variables FF on`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `introspection with variables FF on snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "__schema": { + * "queryType": { + * "fields": [ + * { + * "name": "earth", + * "isDeprecated": false + * }, + * { + * "name": "pluto", + * "isDeprecated": true + * } + * ] + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__schema": { + | "queryType": { + | "fields": [ + | { + | "name": "earth", + | "isDeprecated": false + | }, + | { + | "name": "pluto", + | "isDeprecated": true + | } + | ] + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection with variables FF on.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection with variables FF on.kt new file mode 100644 index 000000000..ab9e92dee --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/introspection with variables FF on.kt @@ -0,0 +1,56 @@ +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `introspection with variables FF on` : NadelLegacyIntegrationTest( + query = """ + query { + __schema { + queryType { + fields(includeDeprecated: true) { + name + isDeprecated + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + earth: Planet + pluto: Planet @deprecated(reason: "Oh no") + } + type Planet { + id: ID + } + type Mutation { + hello: String + } + """.trimIndent(), + underlyingSchema = """ + type Mutation { + hello: String + } + type Query { + earth: Planet + pluto: Planet @deprecated(reason: "Oh no") + } + type Planet { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_Planet( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/no introspections on subscriptions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/no introspections on subscriptions snapshot.kt new file mode 100644 index 000000000..051270a57 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/no introspections on subscriptions snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`no introspections on subscriptions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `no introspections on subscriptions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Validation error (SubscriptionIntrospectionRootField) : Subscription + * operation 'null' root field '__typename' cannot be an introspection field", + * "locations": [ + * { + * "line": 2, + * "column": 3 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ] + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Validation error (SubscriptionIntrospectionRootField) : Subscription operation 'null' root field '__typename' cannot be an introspection field", + | "locations": [ + | { + | "line": 2, + | "column": 3 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ] + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/no introspections on subscriptions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/no introspections on subscriptions.kt new file mode 100644 index 000000000..b952636f1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/introspection/no introspections on subscriptions.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.introspection + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `no introspections on subscriptions` : NadelLegacyIntegrationTest( + query = """ + subscription { + __typename + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + comment: Comment + } + type Subscription { + onComment: Comment @namespaced + } + type Comment { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + comment: Comment + } + type Subscription { + onComment: Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/java-compat/java ari transform snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/java-compat/java ari transform snapshot.kt new file mode 100644 index 000000000..6a99250e3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/java-compat/java ari transform snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`java-compat` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`java ari transform`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `java ari transform snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | issue(id: "57") { + | __typename__rename__key: __typename + | rename__key__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "rename__key__id": "57", + | "__typename__rename__key": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "key": "57" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "key": "57" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/java-compat/java ari transform.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/java-compat/java ari transform.kt new file mode 100644 index 000000000..80e2e2635 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/java-compat/java ari transform.kt @@ -0,0 +1,51 @@ +package graphql.nadel.tests.legacy.`java-compat` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `java ari transform` : NadelLegacyIntegrationTest( + query = """ + query { + issue(id: "ari:/i-forget-what-aris-actually-look-like/57") { + key + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + directive @interpretAri on ARGUMENT_DEFINITION + type Query { + issue(id: ID @interpretAri): Issue + } + type Issue { + key: ID @renamed(from: "id") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "57") { + Service_Issue(id = "57") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Service_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/monitor/monitor emits timings snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/monitor/monitor emits timings snapshot.kt new file mode 100644 index 000000000..3afd4588c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/monitor/monitor emits timings snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.monitor + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`monitor emits timings`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `monitor emits timings snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/monitor/monitor emits timings.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/monitor/monitor emits timings.kt new file mode 100644 index 000000000..5e2d92104 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/monitor/monitor emits timings.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.monitor + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `monitor emits timings` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/aliased typename is wiped when other data fails snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/aliased typename is wiped when other data fails snapshot.kt new file mode 100644 index 000000000..fc19a5644 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/aliased typename is wiped when other data fails snapshot.kt @@ -0,0 +1,95 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`aliased typename is wiped when other data fails`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `aliased typename is wiped when other data fails snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/aliased typename is wiped when other data fails.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/aliased typename is wiped when other data fails.kt new file mode 100644 index 000000000..875ed73cd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/aliased typename is wiped when other data fails.kt @@ -0,0 +1,111 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `aliased typename is wiped when other data fails` : NadelLegacyIntegrationTest( + query = """ + { + issue { + test: __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/both of the namespaced services returns error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/both of the namespaced services returns error snapshot.kt new file mode 100644 index 000000000..fa0965672 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/both of the namespaced services returns error snapshot.kt @@ -0,0 +1,140 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`both of the namespaced services returns error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `both of the namespaced services returns error snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * }, + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/both of the namespaced services returns error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/both of the namespaced services returns error.kt new file mode 100644 index 000000000..2f83f01db --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/both of the namespaced services returns error.kt @@ -0,0 +1,129 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `both of the namespaced services returns error` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typename is kept when nothing else is asked for snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typename is kept when nothing else is asked for snapshot.kt new file mode 100644 index 000000000..0b81b4c21 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typename is kept when nothing else is asked for snapshot.kt @@ -0,0 +1,52 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`multiple typename is kept when nothing else is asked for`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `multiple typename is kept when nothing else is asked for snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "hello": "IssueQuery" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "hello": "IssueQuery" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typename is kept when nothing else is asked for.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typename is kept when nothing else is asked for.kt new file mode 100644 index 000000000..6900e203e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typename is kept when nothing else is asked for.kt @@ -0,0 +1,91 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `multiple typename is kept when nothing else is asked for` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + hello: __typename + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typenames are wiped when other data fails snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typenames are wiped when other data fails snapshot.kt new file mode 100644 index 000000000..1184c6116 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typenames are wiped when other data fails snapshot.kt @@ -0,0 +1,95 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`multiple typenames are wiped when other data fails`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `multiple typenames are wiped when other data fails snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typenames are wiped when other data fails.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typenames are wiped when other data fails.kt new file mode 100644 index 000000000..f81ae1494 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/multiple typenames are wiped when other data fails.kt @@ -0,0 +1,113 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `multiple typenames are wiped when other data fails` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + thing: __typename + getIssue { + text + } + __other: __typename + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/mutation with two services sharing a namespaced field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/mutation with two services sharing a namespaced field snapshot.kt new file mode 100644 index 000000000..0b5fa1857 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/mutation with two services sharing a namespaced field snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`mutation with two services sharing a namespaced field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `mutation with two services sharing a namespaced field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | mutation { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | mutation { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": { + * "count": 100 + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/mutation with two services sharing a namespaced field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/mutation with two services sharing a namespaced field.kt new file mode 100644 index 000000000..df01601da --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/mutation with two services sharing a namespaced field.kt @@ -0,0 +1,114 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `mutation with two services sharing a namespaced field` : NadelLegacyIntegrationTest( + query = """ + mutation { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + echo: String + } + directive @namespaced on FIELD_DEFINITION + type Mutation { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + type Mutation { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Mutation") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + type Mutation { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Mutation") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 100)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/namespaced result map has correct entries on partial failure snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/namespaced result map has correct entries on partial failure snapshot.kt new file mode 100644 index 000000000..a3cfdf3bd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/namespaced result map has correct entries on partial failure snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`namespaced result map has correct entries on partial failure`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `namespaced result map has correct entries on partial failure snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/namespaced result map has correct entries on partial failure.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/namespaced result map has correct entries on partial failure.kt new file mode 100644 index 000000000..95f06ed9d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/namespaced result map has correct entries on partial failure.kt @@ -0,0 +1,123 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `namespaced result map has correct entries on partial failure` : NadelLegacyIntegrationTest( + query = """ + { ...F } + fragment F on Query { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + "locations" to emptyList(), + "extensions" to mapOf( + "classification" to "DataFetchingException", + ), + ), + ), + ), + ).build() + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child has null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child has null snapshot.kt new file mode 100644 index 000000000..3084fe8e9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child has null snapshot.kt @@ -0,0 +1,136 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`not nullable namespaced child has null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `not nullable namespaced child has null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "The field at path '/issue/search' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'SearchResult' within parent type 'IssueQuery'", + | "path": [ + | "issue", + | "search" + | ], + | "extensions": { + | "classification": "NullValueInNonNullableField" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "The field at path '/issue/search' was declared as a non null type, but the + * code involved in retrieving data has wrongly returned a null value. The graphql specification + * requires that the parent field be set to null, or if that is non nullable that it bubble up null + * to its parent and so on. The non-nullable type is 'SearchResult' within parent type + * 'IssueQuery'", + * "locations": [], + * "path": [ + * "issue", + * "search" + * ], + * "extensions": { + * "classification": "NullValueInNonNullableField" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "The field at path '/issue/search' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'SearchResult' within parent type 'IssueQuery'", + | "locations": [], + | "path": [ + | "issue", + | "search" + | ], + | "extensions": { + | "classification": "NullValueInNonNullableField" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child has null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child has null.kt new file mode 100644 index 000000000..6e46da7aa --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child has null.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `not nullable namespaced child has null` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult! + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult! + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = null) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child is absent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child is absent snapshot.kt new file mode 100644 index 000000000..b1ff99f81 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child is absent snapshot.kt @@ -0,0 +1,121 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`not nullable namespaced child is absent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `not nullable namespaced child is absent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error on IssueSearch", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error on IssueSearch", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error on IssueSearch", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child is absent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child is absent.kt new file mode 100644 index 000000000..997e933a1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/not nullable namespaced child is absent.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `not nullable namespaced child is absent` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult! + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult! + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error on IssueSearch", + ), + ), + ), + ).build() + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error reversed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error reversed snapshot.kt new file mode 100644 index 000000000..c4ac80191 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error reversed snapshot.kt @@ -0,0 +1,131 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one of the namespaced services returns error reversed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one of the namespaced services returns error reversed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 1 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error on IssueSearch", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error on IssueSearch", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": { + * "search": { + * "count": 1 + * }, + * "getIssue": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error on IssueSearch", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": { + | "search": { + | "count": 1 + | }, + | "getIssue": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error reversed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error reversed.kt new file mode 100644 index 000000000..e5f4f6563 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error reversed.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one of the namespaced services returns error reversed` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error on IssueSearch", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 1)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error snapshot.kt new file mode 100644 index 000000000..6e0c882f0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error snapshot.kt @@ -0,0 +1,131 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one of the namespaced services returns error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one of the namespaced services returns error snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error on IssueSearch", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error on IssueSearch", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error on IssueSearch", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error.kt new file mode 100644 index 000000000..b421ab699 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/one of the namespaced services returns error.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one of the namespaced services returns error` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error on IssueSearch", + ), + ), + ), + ).build() + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with namespaced fields that have matching subfields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with namespaced fields that have matching subfields snapshot.kt new file mode 100644 index 000000000..cc9e31a15 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with namespaced fields that have matching subfields snapshot.kt @@ -0,0 +1,149 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with namespaced fields that have matching subfields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with namespaced fields that have matching subfields snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Pages", + query = """ + | { + | page { + | getIssue { + | pageText + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "page": { + | "getIssue": { + | "pageText": "Bar" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": { + * "count": 100 + * } + * }, + * "page": { + * "getIssue": { + * "pageText": "Bar" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": { + | "count": 100 + | } + | }, + | "page": { + | "getIssue": { + | "pageText": "Bar" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with namespaced fields that have matching subfields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with namespaced fields that have matching subfields.kt new file mode 100644 index 000000000..94e142163 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with namespaced fields that have matching subfields.kt @@ -0,0 +1,153 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with namespaced fields that have matching subfields` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + page { + getIssue { + pageText + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 100)) + } + } + }, + ), + Service( + name = "Pages", + overallSchema = """ + type Query { + page: PagesQuery @namespaced + } + type PagesQuery { + getIssue: IssuePage + } + type IssuePage { + id: ID + pageText: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + page: PagesQuery + } + type PagesQuery { + getIssue: IssuePage + } + type IssuePage { + id: ID + pageText: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("page") { env -> + Pages_PagesQuery(getIssue = Pages_IssuePage(pageText = "Bar")) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class Pages_IssuePage( + val id: String? = null, + val pageText: String? = null, + ) + + private data class Pages_PagesQuery( + val getIssue: Pages_IssuePage? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field and a non namespaced top level field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field and a non namespaced top level field snapshot.kt new file mode 100644 index 000000000..7fd564012 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field and a non namespaced top level field snapshot.kt @@ -0,0 +1,142 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with two services sharing a namespaced field and a non namespaced top level field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with two services sharing a namespaced field and a non namespaced top level field snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | conf { + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "conf": { + | "title": "Page title" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": { + * "count": 100 + * } + * }, + * "conf": { + * "title": "Page title" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": { + | "count": 100 + | } + | }, + | "conf": { + | "title": "Page title" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field and a non namespaced top level field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field and a non namespaced top level field.kt new file mode 100644 index 000000000..a69b8aa96 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field and a non namespaced top level field.kt @@ -0,0 +1,127 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with two services sharing a namespaced field and a non namespaced top level field` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + conf { + title + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + conf: Page + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + type Page { + id: ID + title: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + conf: Page + } + type Page { + id: ID + title: String + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("conf") { env -> + Issues_Page(title = "Page title") + } + .dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 100)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class Issues_Page( + val id: String? = null, + val title: String? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field fragment query snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field fragment query snapshot.kt new file mode 100644 index 000000000..4005f7349 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field fragment query snapshot.kt @@ -0,0 +1,113 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with two services sharing a namespaced field fragment query`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with two services sharing a namespaced field fragment query snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": { + * "count": 100 + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field fragment query.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field fragment query.kt new file mode 100644 index 000000000..2dacf5015 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field fragment query.kt @@ -0,0 +1,106 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with two services sharing a namespaced field fragment query` : NadelLegacyIntegrationTest( + query = """ + { ...F } + fragment F on Query { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 100)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field snapshot.kt new file mode 100644 index 000000000..464e3af99 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with two services sharing a namespaced field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with two services sharing a namespaced field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "getIssue": { + * "text": "Foo" + * }, + * "search": { + * "count": 100 + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | }, + | "search": { + | "count": 100 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field.kt new file mode 100644 index 000000000..c37fd8fa1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/query with two services sharing a namespaced field.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with two services sharing a namespaced field` : NadelLegacyIntegrationTest( + query = """ + { + issue { + getIssue { + text + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 100)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when data is partially returned snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when data is partially returned snapshot.kt new file mode 100644 index 000000000..dcf179d19 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when data is partially returned snapshot.kt @@ -0,0 +1,133 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is kept when data is partially returned`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is kept when data is partially returned snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "count": 10 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "search": { + * "count": 10 + * }, + * "getIssue": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "search": { + | "count": 10 + | }, + | "getIssue": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when data is partially returned.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when data is partially returned.kt new file mode 100644 index 000000000..9c160ab04 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when data is partially returned.kt @@ -0,0 +1,119 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is kept when data is partially returned` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + id + } + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery(search = IssueSearch_SearchResult(count = 10)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when nothing else is asked for snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when nothing else is asked for snapshot.kt new file mode 100644 index 000000000..20ed9baca --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when nothing else is asked for snapshot.kt @@ -0,0 +1,50 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is kept when nothing else is asked for`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is kept when nothing else is asked for snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when nothing else is asked for.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when nothing else is asked for.kt new file mode 100644 index 000000000..06cfe9458 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is kept when nothing else is asked for.kt @@ -0,0 +1,90 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is kept when nothing else is asked for` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is passed on namespaced fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is passed on namespaced fields snapshot.kt new file mode 100644 index 000000000..15acd5238 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is passed on namespaced fields snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is passed on namespaced fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is passed on namespaced fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename + | aliasTypename: __typename + | getIssue { + | __typename + | aliasTypename: __typename + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "aliasTypename": "IssueQuery", + | "getIssue": { + | "__typename": "Issue", + | "aliasTypename": "Issue", + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "aliasTypename": "IssueQuery", + * "getIssue": { + * "__typename": "Issue", + * "aliasTypename": "Issue", + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "aliasTypename": "IssueQuery", + | "getIssue": { + | "__typename": "Issue", + | "aliasTypename": "Issue", + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is passed on namespaced fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is passed on namespaced fields.kt new file mode 100644 index 000000000..b8cda9f2a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is passed on namespaced fields.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is passed on namespaced fields` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + aliasTypename: __typename + getIssue { + __typename + aliasTypename: __typename + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when namespaced type is extended in declaring service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when namespaced type is extended in declaring service snapshot.kt new file mode 100644 index 000000000..981dfc64b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when namespaced type is extended in declaring service snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is resolved even when namespaced type is extended in declaring service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `typename is resolved even when namespaced type is extended in declaring service snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "getIssue": { + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when namespaced type is extended in declaring service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when namespaced type is extended in declaring service.kt new file mode 100644 index 000000000..2a36072a7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when namespaced type is extended in declaring service.kt @@ -0,0 +1,128 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is resolved even when namespaced type is extended in declaring service` : + NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + val getIssues: List? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when no fields are queried from declaring service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when no fields are queried from declaring service snapshot.kt new file mode 100644 index 000000000..9ccabb228 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when no fields are queried from declaring service snapshot.kt @@ -0,0 +1,87 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is resolved even when no fields are queried from declaring service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is resolved even when no fields are queried from declaring service snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "id": "search-id", + | "count": 1001 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "search": { + * "id": "search-id", + * "count": 1001 + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "search": { + | "id": "search-id", + | "count": 1001 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when no fields are queried from declaring service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when no fields are queried from declaring service.kt new file mode 100644 index 000000000..2ac53b536 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when no fields are queried from declaring service.kt @@ -0,0 +1,126 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is resolved even when no fields are queried from declaring service` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + search { + id + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery( + search = IssueSearch_SearchResult( + count = 1_001, + id = "search-id", + ), + ) + } + } + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when there are multiple services declaring namespaced type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when there are multiple services declaring namespaced type snapshot.kt new file mode 100644 index 000000000..d5d19ff94 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when there are multiple services declaring namespaced type snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is resolved even when there are multiple services declaring namespaced type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `typename is resolved even when there are multiple services declaring namespaced type snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "getIssue": { + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when there are multiple services declaring namespaced type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when there are multiple services declaring namespaced type.kt new file mode 100644 index 000000000..705328451 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved even when there are multiple services declaring namespaced type.kt @@ -0,0 +1,121 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is resolved even when there are multiple services declaring namespaced type` : + NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved on namespaced fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved on namespaced fields snapshot.kt new file mode 100644 index 000000000..0f3ab5dd1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved on namespaced fields snapshot.kt @@ -0,0 +1,92 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is resolved on namespaced fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is resolved on namespaced fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | __typename + | aliasTypename: __typename + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "__typename": "Issue", + | "aliasTypename": "Issue", + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "aliasTypename": "IssueQuery", + * "getIssue": { + * "__typename": "Issue", + * "aliasTypename": "Issue", + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "aliasTypename": "IssueQuery", + | "getIssue": { + | "__typename": "Issue", + | "aliasTypename": "Issue", + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved on namespaced fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved on namespaced fields.kt new file mode 100644 index 000000000..5c63450dd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved on namespaced fields.kt @@ -0,0 +1,66 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is resolved on namespaced fields` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + aliasTypename: __typename + getIssue { + __typename + aliasTypename: __typename + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved when namespaced field and type are defined in different services snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved when namespaced field and type are defined in different services snapshot.kt new file mode 100644 index 000000000..3bf9a9bbc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved when namespaced field and type are defined in different services snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is resolved when namespaced field and type are defined in different services`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `typename is resolved when namespaced field and type are defined in different services snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "getIssue": { + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved when namespaced field and type are defined in different services.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved when namespaced field and type are defined in different services.kt new file mode 100644 index 000000000..53df48626 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is resolved when namespaced field and type are defined in different services.kt @@ -0,0 +1,128 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is resolved when namespaced field and type are defined in different services` : + NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + type Query { + issue: IssueQuery @namespaced + } + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + val getIssues: List? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent only to service that owns namespace type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent only to service that owns namespace type snapshot.kt new file mode 100644 index 000000000..050f0be92 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent only to service that owns namespace type snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is sent only to service that owns namespace type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is sent only to service that owns namespace type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "getIssue": { + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent only to service that owns namespace type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent only to service that owns namespace type.kt new file mode 100644 index 000000000..545786275 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent only to service that owns namespace type.kt @@ -0,0 +1,120 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is sent only to service that owns namespace type` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when namespaced field and type are defined in different services snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when namespaced field and type are defined in different services snapshot.kt new file mode 100644 index 000000000..440b8b542 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when namespaced field and type are defined in different services snapshot.kt @@ -0,0 +1,86 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is sent owning service even when namespaced field and type are defined in different services`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `typename is sent owning service even when namespaced field and type are defined in different services snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "getIssue": { + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when namespaced field and type are defined in different services.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when namespaced field and type are defined in different services.kt new file mode 100644 index 000000000..575847617 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when namespaced field and type are defined in different services.kt @@ -0,0 +1,128 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is sent owning service even when namespaced field and type are defined in different services` : + NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + type Query { + issue: IssueQuery @namespaced + } + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), + ) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + val getIssues: List? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when type is extended in it snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when type is extended in it snapshot.kt new file mode 100644 index 000000000..298af9fd2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when type is extended in it snapshot.kt @@ -0,0 +1,85 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is sent owning service even when type is extended in it`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is sent owning service even when type is extended in it snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "getIssue": { + * "text": "Foo" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "getIssue": { + | "text": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when type is extended in it.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when type is extended in it.kt new file mode 100644 index 000000000..9cbfbcc74 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent owning service even when type is extended in it.kt @@ -0,0 +1,127 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is sent owning service even when type is extended in it` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + extend type IssueQuery { + getIssues: [Issue] + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery(getIssue = Issues_Issue(text = "Foo")) + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + val getIssues: List? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent to owning service even when no fields are queried snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent to owning service even when no fields are queried snapshot.kt new file mode 100644 index 000000000..1162e2763 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent to owning service even when no fields are queried snapshot.kt @@ -0,0 +1,109 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is sent to owning service even when no fields are queried`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is sent to owning service even when no fields are queried snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "search": { + | "id": "search-id", + | "count": 1001 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "__typename": "IssueQuery", + * "search": { + * "id": "search-id", + * "count": 1001 + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "__typename": "IssueQuery", + | "search": { + | "id": "search-id", + | "count": 1001 + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent to owning service even when no fields are queried.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent to owning service even when no fields are queried.kt new file mode 100644 index 000000000..fe9cb38cb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is sent to owning service even when no fields are queried.kt @@ -0,0 +1,131 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is sent to owning service even when no fields are queried` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + search { + id + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_IssueQuery() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + IssueSearch_IssueQuery( + search = IssueSearch_SearchResult( + count = 1_001, + id = "search-id", + ), + ) + } + } + }, + ), + Service( + name = "IssueComments", + overallSchema = """ + extend type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + commentsCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) + + private data class IssueComments_IssueQuery( + val commentsCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails includes not nullable field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails includes not nullable field snapshot.kt new file mode 100644 index 000000000..abcb73d4f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails includes not nullable field snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is wiped when other data fails includes not nullable field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is wiped when other data fails includes not nullable field snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueSearch", + query = """ + | { + | issue { + | search { + | count + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails includes not nullable field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails includes not nullable field.kt new file mode 100644 index 000000000..1cc7bc23e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails includes not nullable field.kt @@ -0,0 +1,111 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is wiped when other data fails includes not nullable field` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + search { + count + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult! + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult! + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails snapshot.kt new file mode 100644 index 000000000..ef6ca9793 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails snapshot.kt @@ -0,0 +1,95 @@ +// @formatter:off +package graphql.nadel.tests.legacy.namespaced + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is wiped when other data fails`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is wiped when other data fails snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | getIssue { + | text + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issue": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issue": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails.kt new file mode 100644 index 000000000..653dca80e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/namespaced/typename is wiped when other data fails.kt @@ -0,0 +1,111 @@ +package graphql.nadel.tests.legacy.namespaced + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is wiped when other data fails` : NadelLegacyIntegrationTest( + query = """ + { + issue { + __typename + getIssue { + text + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + directive @namespaced on FIELD_DEFINITION + type Query { + issue: IssueQuery @namespaced + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + getIssue: Issue + } + type Issue { + id: ID + text: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "IssueSearch", + overallSchema = """ + extend type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue: IssueQuery + } + type IssueQuery { + search: SearchResult + } + type SearchResult { + id: ID + count: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val text: String? = null, + ) + + private data class Issues_IssueQuery( + val getIssue: Issues_Issue? = null, + ) + + private data class IssueSearch_IssueQuery( + val search: IssueSearch_SearchResult? = null, + ) + + private data class IssueSearch_SearchResult( + val id: String? = null, + val count: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/able to ask for field and use same field as hydration source snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/able to ask for field and use same field as hydration source snapshot.kt new file mode 100644 index 000000000..f35380404 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/able to ask for field and use same field as hydration source snapshot.kt @@ -0,0 +1,141 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`able to ask for field and use same field as hydration source`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `able to ask for field and use same field as hydration source snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | bar { + | __typename__hydration__nestedBar: __typename + | barId + | hydration__nestedBar__barId: barId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bar": { + | "barId": "1", + | "hydration__nestedBar__barId": "1", + | "__typename__hydration__nestedBar": "Bar", + | "name": "Test" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barById(id: "1") { + | __typename__hydration__nestedBar: __typename + | hydration__nestedBar__barId: barId + | barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "hydration__nestedBar__barId": "1", + | "__typename__hydration__nestedBar": "Bar", + | "barId": "1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barById(id: "1") { + | barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "barId": "1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "bar": { + * "barId": "1", + * "name": "Test", + * "nestedBar": { + * "barId": "1", + * "nestedBar": { + * "barId": "1" + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "bar": { + | "barId": "1", + | "name": "Test", + | "nestedBar": { + | "barId": "1", + | "nestedBar": { + | "barId": "1" + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/able to ask for field and use same field as hydration source.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/able to ask for field and use same field as hydration source.kt new file mode 100644 index 000000000..b48a66f7a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/able to ask for field and use same field as hydration source.kt @@ -0,0 +1,74 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `able to ask for field and use same field as hydration source` : NadelLegacyIntegrationTest( + query = """ + query { + bar { + barId + nestedBar { + nestedBar { + barId + } + barId + } + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bar: Bar + barById(id: ID): Bar + } + type Bar { + barId: ID + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + barId: ID + name: String + } + type Query { + bar: Bar + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("bar") { env -> + Bar_Bar(barId = "1", name = "Test") + } + .dataFetcher("barById") { env -> + if (env.getArgument("id") == "1") { + Bar_Bar(barId = "1") + } else if (env.getArgument("id") == "1") { + Bar_Bar(barId = "1") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a batch hydration snapshot.kt new file mode 100644 index 000000000..f4f64c880 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a batch hydration snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`no object fields in the result are backed a batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `no object fields in the result are backed a batch hydration snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | ... on Activity { + | __typename__batch_hydration__user: __typename + | batch_hydration__user__userId: userId + | } + | ... on SingleActivity { + | user { + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "user": { + * "name": "John" + * } + * }, + * { + * "user": { + * "name": "Mayor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a batch hydration.kt new file mode 100644 index 000000000..9268f4b0d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a batch hydration.kt @@ -0,0 +1,129 @@ +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `no object fields in the result are backed a batch hydration` : NadelLegacyIntegrationTest( + query = """ + { + activity { + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [IActivity] + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + user: User + @hydrated( + service: "users" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.userId"}] + inputIdentifiedBy: [{sourceId: "userId" resultId: "id"}] + ) + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + } + type User { + id: ID! + name: String + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + userId: ID + user: User @deprecated(reason: "Fake") + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_SingleActivity(user = Activity_User(name = "John")), + Activity_SingleActivity(user = Activity_User(name = "Mayor")), + ) + } + } + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val userId: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private interface Activity_IActivity { + val user: Activity_User? + } + + private data class Activity_SingleActivity( + val id: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a hydration snapshot.kt new file mode 100644 index 000000000..139c665af --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a hydration snapshot.kt @@ -0,0 +1,107 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`no object fields in the result are backed a hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `no object fields in the result are backed a hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | ... on Activity { + | __typename__hydration__user: __typename + | hydration__user__userId: userId + | } + | ... on SingleActivity { + | user { + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "user": { + * "name": "John" + * } + * }, + * { + * "user": { + * "name": "Mayor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a hydration.kt new file mode 100644 index 000000000..0f823b0c6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/no object fields in the result are backed a hydration.kt @@ -0,0 +1,128 @@ +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `no object fields in the result are backed a hydration` : NadelLegacyIntegrationTest( + query = """ + { + activity { + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [IActivity] + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + user: User + @hydrated( + service: "users" + field: "userById" + arguments: [{name: "id" value: "${'$'}source.userId"}] + ) + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + } + type User { + id: ID! + name: String + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + userId: ID + user: User @deprecated(reason: "Fake") + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_SingleActivity(user = Activity_User(name = "John")), + Activity_SingleActivity(user = Activity_User(name = "Mayor")), + ) + } + } + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val userId: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private interface Activity_IActivity { + val user: Activity_User? + } + + private data class Activity_SingleActivity( + val id: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a batch hydration snapshot.kt new file mode 100644 index 000000000..1ff1f48d7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a batch hydration snapshot.kt @@ -0,0 +1,166 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`some object fields in the result are backed a batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `some object fields in the result are backed a batch hydration snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | ... on Activity { + | __typename__batch_hydration__user: __typename + | batch_hydration__user__userId: userId + | } + | ... on SingleActivity { + | user { + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "batch_hydration__user__userId": "user-100", + | "__typename__batch_hydration__user": "Activity" + | }, + | { + | "batch_hydration__user__userId": "user-20", + | "__typename__batch_hydration__user": "Activity" + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | usersByIds(ids: ["user-100", "user-20"]) { + | batch_hydration__user__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "Spaces", + | "batch_hydration__user__id": "user-100" + | }, + | { + | "name": "Newmarket", + | "batch_hydration__user__id": "user-20" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "user": { + * "name": "John" + * } + * }, + * { + * "user": { + * "name": "Spaces" + * } + * }, + * { + * "user": { + * "name": "Newmarket" + * } + * }, + * { + * "user": { + * "name": "Mayor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Spaces" + | } + | }, + | { + | "user": { + | "name": "Newmarket" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a batch hydration.kt new file mode 100644 index 000000000..f5faccddb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a batch hydration.kt @@ -0,0 +1,141 @@ +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `some object fields in the result are backed a batch hydration` : NadelLegacyIntegrationTest( + query = """ + { + activity { + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [IActivity] + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + user: User + @hydrated( + service: "users" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.userId"}] + inputIdentifiedBy: [{sourceId: "userId" resultId: "id"}] + ) + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + } + type User { + id: ID! + name: String + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + userId: ID + user: User @deprecated(reason: "Fake") + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_SingleActivity(user = Activity_User(name = "John")), + Activity_Activity(userId = "user-100"), + Activity_Activity(userId = "user-20"), + Activity_SingleActivity(user = Activity_User(name = "Mayor")), + ) + } + } + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + Users_User(id = "user-100", name = "Spaces"), + Users_User(id = "user-20", name = "Newmarket"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val userId: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private interface Activity_IActivity { + val user: Activity_User? + } + + private data class Activity_SingleActivity( + val id: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a hydration snapshot.kt new file mode 100644 index 000000000..89d54e62a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a hydration snapshot.kt @@ -0,0 +1,179 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`some object fields in the result are backed a hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `some object fields in the result are backed a hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | ... on Activity { + | __typename__hydration__user: __typename + | hydration__user__userId: userId + | } + | ... on SingleActivity { + | user { + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "hydration__user__userId": "user-100", + | "__typename__hydration__user": "Activity" + | }, + | { + | "hydration__user__userId": "user-20", + | "__typename__hydration__user": "Activity" + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | userById(id: "user-100") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "userById": { + | "name": "Hello" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | userById(id: "user-20") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "userById": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "user": { + * "name": "John" + * } + * }, + * { + * "user": { + * "name": "Hello" + * } + * }, + * { + * "user": { + * "name": "World" + * } + * }, + * { + * "user": { + * "name": "Mayor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Hello" + | } + | }, + | { + | "user": { + | "name": "World" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a hydration.kt new file mode 100644 index 000000000..f5cab8835 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some object fields in the result are backed a hydration.kt @@ -0,0 +1,141 @@ +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `some object fields in the result are backed a hydration` : NadelLegacyIntegrationTest( + query = """ + { + activity { + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [IActivity] + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + user: User + @hydrated( + service: "users" + field: "userById" + arguments: [{name: "id" value: "${'$'}source.userId"}] + ) + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + } + type User { + id: ID! + name: String + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + userId: ID + user: User @deprecated(reason: "Fake") + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_SingleActivity(user = Activity_User(name = "John")), + Activity_Activity(userId = "user-100"), + Activity_Activity(userId = "user-20"), + Activity_SingleActivity(user = Activity_User(name = "Mayor")), + ) + } + } + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("userById") { env -> + if (env.getArgument("id") == "user-100") { + Users_User(name = "Hello") + } else if (env.getArgument("id") == "user-20") { + Users_User(name = "World") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val userId: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private interface Activity_IActivity { + val user: Activity_User? + } + + private data class Activity_SingleActivity( + val id: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a batch hydration snapshot.kt new file mode 100644 index 000000000..493e66464 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a batch hydration snapshot.kt @@ -0,0 +1,167 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`some renamed object types have fields in the result are backed a batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `some renamed object types have fields in the result are backed a batch hydration snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | ... on Activity { + | __typename__batch_hydration__user: __typename + | batch_hydration__user__userId: userId + | } + | ... on SingleActivity { + | user { + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "batch_hydration__user__userId": "user-100", + | "__typename__batch_hydration__user": "Activity" + | }, + | { + | "batch_hydration__user__userId": "user-20", + | "__typename__batch_hydration__user": "Activity" + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | usersByIds(ids: ["user-100", "user-20"]) { + | batch_hydration__user__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "Spaces", + | "batch_hydration__user__id": "user-100" + | }, + | { + | "name": "Newmarket", + | "batch_hydration__user__id": "user-20" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "user": { + * "name": "John" + * } + * }, + * { + * "user": { + * "name": "Spaces" + * } + * }, + * { + * "user": { + * "name": "Newmarket" + * } + * }, + * { + * "user": { + * "name": "Mayor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Spaces" + | } + | }, + | { + | "user": { + | "name": "Newmarket" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a batch hydration.kt new file mode 100644 index 000000000..1d9beab0d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a batch hydration.kt @@ -0,0 +1,142 @@ +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `some renamed object types have fields in the result are backed a batch hydration` : + NadelLegacyIntegrationTest( + query = """ + { + activity { + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [IActivity] + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + user: User + @hydrated( + service: "users" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.userId"}] + inputIdentifiedBy: [{sourceId: "userId" resultId: "id"}] + ) + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + } + type User { + id: ID! + name: String + } + interface IActivity { + user: User + } + type Activity implements IActivity { + id: ID! + userId: ID + user: User @deprecated(reason: "Fake") + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_SingleActivity(user = Activity_User(name = "John")), + Activity_Activity(userId = "user-100"), + Activity_Activity(userId = "user-20"), + Activity_SingleActivity(user = Activity_User(name = "Mayor")), + ) + } + } + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + Users_User(id = "user-100", name = "Spaces"), + Users_User(id = "user-20", name = "Newmarket"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + ), + ) { + private data class Activity_Activity( + val id: String? = null, + val userId: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private interface Activity_IActivity { + val user: Activity_User? + } + + private data class Activity_SingleActivity( + val id: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a hydration snapshot.kt new file mode 100644 index 000000000..32758eaa8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a hydration snapshot.kt @@ -0,0 +1,180 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`some renamed object types have fields in the result are backed a hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `some renamed object types have fields in the result are backed a hydration snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | ... on SingleActivity { + | user { + | name + | } + | } + | ... on SomethingLame { + | __typename__hydration__user: __typename + | hydration__user__userId: userId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "hydration__user__userId": "user-100", + | "__typename__hydration__user": "SomethingLame" + | }, + | { + | "hydration__user__userId": "user-20", + | "__typename__hydration__user": "SomethingLame" + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | userById(id: "user-100") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "userById": { + | "name": "Hello" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | userById(id: "user-20") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "userById": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "user": { + * "name": "John" + * } + * }, + * { + * "user": { + * "name": "Hello" + * } + * }, + * { + * "user": { + * "name": "World" + * } + * }, + * { + * "user": { + * "name": "Mayor" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "user": { + | "name": "John" + | } + | }, + | { + | "user": { + | "name": "Hello" + | } + | }, + | { + | "user": { + | "name": "World" + | } + | }, + | { + | "user": { + | "name": "Mayor" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a hydration.kt new file mode 100644 index 000000000..e9377aefb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/abstract types/some renamed object types have fields in the result are backed a hydration.kt @@ -0,0 +1,143 @@ +package graphql.nadel.tests.legacy.`new hydration`.`abstract types` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `some renamed object types have fields in the result are backed a hydration` : NadelLegacyIntegrationTest( + query = """ + { + activity { + user { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [IActivity] + } + interface IActivity { + user: User + } + type Activity implements IActivity @renamed(from: "SomethingLame") { + id: ID! + user: User + @hydrated( + service: "users" + field: "userById" + arguments: [{name: "id" value: "${'$'}source.userId"}] + ) + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + } + type User { + id: ID! + name: String + } + interface IActivity { + user: User + } + type SomethingLame implements IActivity { + id: ID! + userId: ID + user: User @deprecated(reason: "Fake") + } + type SingleActivity implements IActivity { + id: ID! + user: User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_SingleActivity(user = Activity_User(name = "John")), + Activity_SomethingLame(userId = "user-100"), + Activity_SomethingLame( + userId = "user-20", + ), + Activity_SingleActivity(user = Activity_User(name = "Mayor")), + ) + } + } + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("userById") { env -> + if (env.getArgument("id") == "user-100") { + Users_User(name = "Hello") + } else if (env.getArgument("id") == "user-20") { + Users_User(name = "World") + } else { + null + } + } + } + }, + ), + ), +) { + private interface Activity_IActivity { + val user: Activity_User? + } + + private data class Activity_SingleActivity( + val id: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_SomethingLame( + val id: String? = null, + val userId: String? = null, + override val user: Activity_User? = null, + ) : Activity_IActivity + + private data class Activity_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/all hydration fields are seen by transformer snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/all hydration fields are seen by transformer snapshot.kt new file mode 100644 index 000000000..71b7946ab --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/all hydration fields are seen by transformer snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`all hydration fields are seen by transformer`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `all hydration fields are seen by transformer snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | bars { + | barById(id: "barId") { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bars": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/all hydration fields are seen by transformer.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/all hydration fields are seen by transformer.kt new file mode 100644 index 000000000..3e7d7bf86 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/all hydration fields are seen by transformer.kt @@ -0,0 +1,117 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `all hydration fields are seen by transformer` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + bars: BarQuery + } + type BarQuery { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + bars: BarQuery + } + type BarQuery { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bars") { + Unit + } + } + wiring.type("BarQuery") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "bars.barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_BarQuery( + val barById: Service2_Bar? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false equals condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false equals condition snapshot.kt new file mode 100644 index 000000000..0944fddf3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false equals condition snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic conditional hydration with false equals condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic conditional hydration with false equals condition snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "hydration__bar__type": "someType", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false equals condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false equals condition.kt new file mode 100644 index 000000000..6481cf191 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false equals condition.kt @@ -0,0 +1,100 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic conditional hydration with false equals condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "${'$'}source.barId" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "someOtherRandomTypeThatNobodyUses" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId", type = "someType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false matches condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false matches condition snapshot.kt new file mode 100644 index 000000000..cfe442d37 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false matches condition snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic conditional hydration with false matches condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic conditional hydration with false matches condition snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "hydration__bar__type": "someType", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false matches condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false matches condition.kt new file mode 100644 index 000000000..7afa9a849 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false matches condition.kt @@ -0,0 +1,100 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic conditional hydration with false matches condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "${'$'}source.barId" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "[A-Z]+Type" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId", type = "someType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false startsWith condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false startsWith condition snapshot.kt new file mode 100644 index 000000000..0284297b7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false startsWith condition snapshot.kt @@ -0,0 +1,77 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic conditional hydration with false startsWith condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic conditional hydration with false startsWith condition snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "hydration__bar__type": "someType", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false startsWith condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false startsWith condition.kt new file mode 100644 index 000000000..9b518606b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with false startsWith condition.kt @@ -0,0 +1,100 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic conditional hydration with false startsWith condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "${'$'}source.barId" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "hehe" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId", type = "someType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true equals condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true equals condition snapshot.kt new file mode 100644 index 000000000..91d1e5e32 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true equals condition snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic conditional hydration with true equals condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic conditional hydration with true equals condition snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "hydration__bar__type": "someType", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true equals condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true equals condition.kt new file mode 100644 index 000000000..010ecfb03 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true equals condition.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic conditional hydration with true equals condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "${'$'}source.barId" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "someType" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId", type = "someType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true matches condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true matches condition snapshot.kt new file mode 100644 index 000000000..d109f464c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true matches condition snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic conditional hydration with true matches condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic conditional hydration with true matches condition snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "hydration__bar__type": "someType", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true matches condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true matches condition.kt new file mode 100644 index 000000000..009607616 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true matches condition.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic conditional hydration with true matches condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "${'$'}source.barId" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "[a-z]+Type" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId", type = "someType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true startsWith condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true startsWith condition snapshot.kt new file mode 100644 index 000000000..e4e3253a9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true startsWith condition snapshot.kt @@ -0,0 +1,103 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic conditional hydration with true startsWith condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic conditional hydration with true startsWith condition snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "hydration__bar__type": "someType", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true startsWith condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true startsWith condition.kt new file mode 100644 index 000000000..1bb098572 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic conditional hydration with true startsWith condition.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic conditional hydration with true startsWith condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "${'$'}source.barId" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "some" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId", type = "someType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration directive based snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration directive based snapshot.kt new file mode 100644 index 000000000..33db8a5e8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration directive based snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration directive based`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration directive based snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration directive based.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration directive based.kt new file mode 100644 index 000000000..f8e6b8848 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration directive based.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration directive based` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + ] + ) + barLongerInput: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.fooDetails.externalBarId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration snapshot.kt new file mode 100644 index 000000000..3007e776c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with actor field rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with actor field rename snapshot.kt new file mode 100644 index 000000000..36f4d27ae --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with actor field rename snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with actor field rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with actor field rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | rename__barByIdOverall__barById: barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__barByIdOverall__barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with actor field rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with actor field rename.kt new file mode 100644 index 000000000..fff7bf778 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with actor field rename.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with actor field rename` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barByIdOverall(id: ID): Bar @renamed(from: "barById") + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barByIdOverall" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barByIdOverall" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default array argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default array argument values snapshot.kt new file mode 100644 index 000000000..716f0b6ef --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default array argument values snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with default array argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with default array argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId", test: ["Hello", "World"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default array argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default array argument values.kt new file mode 100644 index 000000000..8afca95b5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default array argument values.kt @@ -0,0 +1,99 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with default array argument values` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, test: [String]): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, test: [String]): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barById = listOf( + Service2_Bar(id = "barId", name = "Bar1"), + ).associateBy { it.id } + + type.dataFetcher("barById") { env -> + if (env.getArgument("test") == listOf("Hello", "World")) { + barById[env.getArgument("id")] + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar(test: [String] = ["Hello", "World"]): Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + {name: "test" value: "${'$'}argument.test"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default boolean argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default boolean argument values snapshot.kt new file mode 100644 index 000000000..5112eda70 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default boolean argument values snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with default boolean argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with default boolean argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId", test: false) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default boolean argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default boolean argument values.kt new file mode 100644 index 000000000..5703acae9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default boolean argument values.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with default boolean argument values` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, test: Boolean): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, test: Boolean): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId" && env.getArgument("test") == false) { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar(test: Boolean = false): Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + {name: "test" value: "${'$'}argument.test"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default int argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default int argument values snapshot.kt new file mode 100644 index 000000000..39f6a34f7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default int argument values snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with default int argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with default int argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId", test: 10) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default int argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default int argument values.kt new file mode 100644 index 000000000..5ab89e98d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default int argument values.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with default int argument values` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, test: Int): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, test: Int): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId" && env.getArgument("test") == 10) { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar(test: Int = 10): Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + {name: "test" value: "${'$'}argument.test"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default null argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default null argument values snapshot.kt new file mode 100644 index 000000000..045a8b011 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default null argument values snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with default null argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with default null argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId", test: null) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default null argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default null argument values.kt new file mode 100644 index 000000000..2bc1e5a7f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default null argument values.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with default null argument values` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, test: Boolean = true): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, test: Boolean = true): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId" && env.getArgument("test") == null) { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar(test: Boolean = null): Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + {name: "test" value: "${'$'}argument.test"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default object argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default object argument values snapshot.kt new file mode 100644 index 000000000..6a111f2c7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default object argument values snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with default object argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with default object argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId", test: {echo : "Hello World"}) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default object argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default object argument values.kt new file mode 100644 index 000000000..a97c0aeee --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default object argument values.kt @@ -0,0 +1,120 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with default object argument values` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, test: Test): Bar + } + type Bar { + id: ID + name: String + } + input Test { + string: String = "Test" + int: Int = 42 + bool: Boolean = false + number: Int + echo: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, test: Test = {}): Bar + } + input Test { + string: String = "Test" + int: Int = 42 + bool: Boolean = false + number: Int + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId" && + env.getArgument("test") == + mapOf("string" to "Test", "int" to 42, "bool" to false, "echo" to "Hello World") + ) { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar(test: Test = {echo: "Hello World"}): Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + {name: "test" value: "${'$'}argument.test"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_Test( + val string: String? = null, + val int: Int? = null, + val bool: Boolean? = null, + val number: Int? = null, + val echo: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default string argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default string argument values snapshot.kt new file mode 100644 index 000000000..a92db806d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default string argument values snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with default string argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with default string argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId", test: "Hello World") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default string argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default string argument values.kt new file mode 100644 index 000000000..5d0a85317 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with default string argument values.kt @@ -0,0 +1,98 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with default string argument values` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, test: String): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, test: String): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId" && + env.getArgument("test") == + "Hello World" + ) { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar(test: String = "Hello World"): Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + {name: "test" value: "${'$'}argument.test"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg array snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg array snapshot.kt new file mode 100644 index 000000000..5d9c49243 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg array snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static arg array`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static arg array snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__id": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(friendIds: ["barId2", "barId3", "barId4"], id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg array.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg array.kt new file mode 100644 index 000000000..5756e7746 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg array.kt @@ -0,0 +1,100 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static arg array` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, friendIds: [ID]): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, friendIds: [ID]): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barById = listOf( + Service2_Bar(id = "barId", name = "Bar1") + ).associateBy { it.id } + + type.dataFetcher("barById") { env -> + if (env.getArgument("friendIds") == listOf("barId2", "barId3", "barId4")) { + barById[env.getArgument("id")] + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { name: "id" value: "${'$'}source.id" } + { name: "friendIds" value: ["barId2", "barId3", "barId4"] } + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(id = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg boolean snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg boolean snapshot.kt new file mode 100644 index 000000000..d04e676f9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg boolean snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static arg boolean`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static arg boolean snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barWithSomeAttribute(someAttribute: true) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barWithSomeAttribute": { + | "name": "Bar12345" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar12345" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar12345" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg boolean.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg boolean.kt new file mode 100644 index 000000000..e229528d1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg boolean.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static arg boolean` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barWithSomeAttribute(someAttribute: Boolean): Bar + } + type Bar { + id: ID + name: String + someAttribute: Boolean + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + someAttribute: Boolean + } + type Query { + barWithSomeAttribute(someAttribute: Boolean): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barWithSomeAttribute") { env -> + if (env.getArgument("someAttribute") == true) { + Service2_Bar(name = "Bar12345") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barWithSomeAttribute" + arguments: [{name: "someAttribute" value: true}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo() + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val someAttribute: Boolean? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg float snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg float snapshot.kt new file mode 100644 index 000000000..829b0f49a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg float snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static arg float`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static arg float snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barWithSomeFloat(someFloat: 123.45) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barWithSomeFloat": { + | "name": "Bar12345" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar12345" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar12345" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg float.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg float.kt new file mode 100644 index 000000000..aa7cb4886 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg float.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static arg float` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barWithSomeFloat(someFloat: Float): Bar + } + type Bar { + id: ID + name: String + someFloat: Float + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + someFloat: Float + } + type Query { + barWithSomeFloat(someFloat: Float): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barWithSomeFloat") { env -> + if (env.getArgument("someFloat") == 123.45) { + Service2_Bar(name = "Bar12345") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barWithSomeFloat" + arguments: [{name: "someFloat" value: 123.45}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo() + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val someFloat: Double? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg integer snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg integer snapshot.kt new file mode 100644 index 000000000..a80ebb32d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg integer snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static arg integer`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static arg integer snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: 12345) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar12345" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar12345" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar12345" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg integer.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg integer.kt new file mode 100644 index 000000000..75948d0a5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg integer.kt @@ -0,0 +1,93 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static arg integer` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: Int): Bar + } + type Bar { + id: Int + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: Int + name: String + } + type Query { + barById(id: Int): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == 12_345) { + Service2_Bar(name = "Bar12345") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: 12345}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: Int + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo() + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: Int? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: Int? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object array snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object array snapshot.kt new file mode 100644 index 000000000..d5e106e1c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object array snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static arg object array`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static arg object array snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__id": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(friends: [{firstName : "first", lastName : "last"}, {firstName : "first2", lastName : "last2"}, {firstName : "first3", lastName : "last3"}], id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object array.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object array.kt new file mode 100644 index 000000000..e8fe1ec45 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object array.kt @@ -0,0 +1,134 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static arg object array` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, friends: [FullName]): Bar + } + type Bar { + id: ID + name: String + } + input FullName { + firstName: String + lastName: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, friends: [FullName]): Bar + } + input FullName { + firstName: String + lastName: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barById = listOf( + Service2_Bar(id = "barId", name = "Bar1") + ).associateBy { it.id } + + val secret = listOf( + mapOf("firstName" to "first", "lastName" to "last"), + mapOf("firstName" to "first2", "lastName" to "last2"), + mapOf("firstName" to "first3", "lastName" to "last3"), + ) + + type.dataFetcher("barById") { env -> + if (env.getArgument("friends") == secret) { + barById[env.getArgument("id")] + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + { name: "id" value: "${'$'}source.id" } + { + name: "friends" + value: [ + { + firstName: "first" + lastName: "last" + } + { + firstName: "first2" + lastName: "last2" + } + { + firstName: "first3" + lastName: "last3" + } + ] + } + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(id = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_FullName( + val firstName: String? = null, + val lastName: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object snapshot.kt new file mode 100644 index 000000000..50cd170b4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static arg object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static arg object snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__id": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(fullName: {firstName : "first", lastName : "last"}, id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object.kt new file mode 100644 index 000000000..9afc6cebb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static arg object.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static arg object` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID, fullName: FullName): Bar + } + type Bar { + id: ID + name: String + } + input FullName { + firstName: String + lastName: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID, fullName: FullName): Bar + } + input FullName { + firstName: String + lastName: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId" && + env.getArgument("fullName") == + mapOf("firstName" to "first", "lastName" to "last") + ) { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { name: "id" value: "${'$'}source.id" } + { + name: "fullName" + value: { + firstName: "first" + lastName: "last" + } + } + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(id = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_FullName( + val firstName: String? = null, + val lastName: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static args snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static args snapshot.kt new file mode 100644 index 000000000..19922fe35 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static args snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`basic hydration with static args`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `basic hydration with static args snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static args.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static args.kt new file mode 100644 index 000000000..5dbfdf499 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration with static args.kt @@ -0,0 +1,93 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration with static args` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo() + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration.kt new file mode 100644 index 000000000..0d7d598d5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/basic hydration.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `basic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is absent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is absent snapshot.kt new file mode 100644 index 000000000..a118154b1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is absent snapshot.kt @@ -0,0 +1,86 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch hydration input is absent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch hydration input is absent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authors: authors { + | id + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authors": [], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is absent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is absent.kt new file mode 100644 index 000000000..ff2fc0b4b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is absent.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch hydration input is absent` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "ids" value: "${'$'}source.authors.id"} + ] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authors: [UserRef] + id: ID + } + type UserRef { + id: ID! + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authors = listOf(), id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authors: List? = null, + val id: String? = null, + ) + + private data class Issues_UserRef( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is null snapshot.kt new file mode 100644 index 000000000..918022aa3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is null snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch hydration input is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch hydration input is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": null, + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": null + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": null + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is null.kt new file mode 100644 index 000000000..4c0ed96e6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration input is null.kt @@ -0,0 +1,87 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch hydration input is null` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorIds = null, id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration instruction hook returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration instruction hook returns null snapshot.kt new file mode 100644 index 000000000..5f0b1a3a5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration instruction hook returns null snapshot.kt @@ -0,0 +1,135 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch hydration instruction hook returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch hydration instruction hook returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issueById(id: "10000") { + | __typename__batch_hydration__collaborators: __typename + | batch_hydration__collaborators__collaboratorIds: collaboratorIds + | key + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "key": "GQLGW-1000", + | "batch_hydration__collaborators__collaboratorIds": [ + | "100", + | "NULL/1", + | "200" + | ], + | "__typename__batch_hydration__collaborators": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Users", + query = """ + | { + | usersByIds(ids: ["100", "200"]) { + | __typename + | batch_hydration__collaborators__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "__typename": "User", + | "name": "John Doe", + | "batch_hydration__collaborators__id": "100" + | }, + | { + | "__typename": "User", + | "name": "Joe", + | "batch_hydration__collaborators__id": "200" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issueById": { + * "key": "GQLGW-1000", + * "collaborators": [ + * { + * "__typename": "User", + * "name": "John Doe" + * }, + * null, + * { + * "__typename": "User", + * "name": "Joe" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issueById": { + | "key": "GQLGW-1000", + | "collaborators": [ + | { + | "__typename": "User", + | "name": "John Doe" + | }, + | null, + | { + | "__typename": "User", + | "name": "Joe" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration instruction hook returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration instruction hook returns null.kt new file mode 100644 index 000000000..e252ba4c9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration instruction hook returns null.kt @@ -0,0 +1,106 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch hydration instruction hook returns null` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "10000") { + key + collaborators { + __typename + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issueById(id: ID!): Issue! + } + type Issue { + id: ID! + key: String + collaborators: [User] + @hydrated( + service: "Users" + field: "usersByIds" + arguments: [ + {name: "ids", value: "${'$'}source.collaboratorIds"} + ] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID!): Issue! + } + type Issue { + id: ID! + key: String + collaboratorIds: [ID] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "10000") { + Issues_Issue(collaboratorIds = listOf("100", "NULL/1", "200"), key = "GQLGW-1000") + } else { + null + } + } + } + }, + ), + Service( + name = "Users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + Users_User(id = "100", name = "John Doe"), + Users_User(id = "200", name = "Joe"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val key: String? = null, + val collaboratorIds: List? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration null source object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration null source object snapshot.kt new file mode 100644 index 000000000..c78425e88 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration null source object snapshot.kt @@ -0,0 +1,117 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch hydration null source object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch hydration null source object snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "issues", + query = """ + | { + | myIssues { + | __typename__batch_hydration__assignee: __typename + | batch_hydration__assignee__assigneeId: assigneeId + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "myIssues": [ + | { + | "title": "Popular", + | "batch_hydration__assignee__assigneeId": "user-256", + | "__typename__batch_hydration__assignee": "Issue" + | }, + | null + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | usersByIds(ids: ["user-256"]) { + | batch_hydration__assignee__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "2^8", + | "batch_hydration__assignee__id": "user-256" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "myIssues": [ + * { + * "title": "Popular", + * "assignee": { + * "name": "2^8" + * } + * }, + * null + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "myIssues": [ + | { + | "title": "Popular", + | "assignee": { + | "name": "2^8" + | } + | }, + | null + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration null source object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration null source object.kt new file mode 100644 index 000000000..16f6e5547 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration null source object.kt @@ -0,0 +1,106 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch hydration null source object` : NadelLegacyIntegrationTest( + query = """ + query { + myIssues { + title + assignee { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "issues", + overallSchema = """ + type Query { + myIssues(n: Int! = 10): [Issue] + } + type Issue { + title: String + assigneeId: ID + assignee: User + @hydrated( + service: "users" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.assigneeId"}] + inputIdentifiedBy: [{sourceId: "assigneeId", resultId: "id"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + topIssue: Issue + myIssues(n: Int! = 10): [Issue] + } + type Issue { + title: String + assigneeId: ID + collaboratorIds: [ID!] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("myIssues") { env -> + if (env.getArgument("n") == 10) { + listOf(Issues_Issue(assigneeId = "user-256", title = "Popular"), null) + } else { + null + } + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + email: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + email: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + Users_User(id = "user-256", name = "2^8") + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val title: String? = null, + val assigneeId: String? = null, + val collaboratorIds: List? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + val email: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration with renamed actor field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration with renamed actor field snapshot.kt new file mode 100644 index 000000000..5a29f75c0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration with renamed actor field snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch hydration with renamed actor field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch hydration with renamed actor field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | rename__barsByIdOverall__barsById: barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__barsByIdOverall__barsById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | }, + | { + | "name": "Bar3", + | "batch_hydration__bar__id": "barId3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * }, + * { + * "name": "Bar3" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | }, + | { + | "name": "Bar3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration with renamed actor field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration with renamed actor field.kt new file mode 100644 index 000000000..84efe7808 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batch hydration with renamed actor field.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch hydration with renamed actor field` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsByIdOverall(id: [ID]): [Bar] @renamed(from: "barsById") + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + Service2_Bar(id = "barId3", name = "Bar3"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsByIdOverall" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration query with a synthetic field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration query with a synthetic field snapshot.kt new file mode 100644 index 000000000..2e910fa28 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration query with a synthetic field snapshot.kt @@ -0,0 +1,233 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration query with a synthetic field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration query with a synthetic field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | users { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"]) { + | id + | batch_hydration__authors__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | users { + | usersByIds(id: ["USER-4", "USER-5"]) { + | id + | batch_hydration__authors__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration query with a synthetic field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration query with a synthetic field.kt new file mode 100644 index 000000000..465972d8c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration query with a synthetic field.kt @@ -0,0 +1,125 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration query with a synthetic field` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + users: UsersQuery + } + type UsersQuery { + foo: String + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: UsersQuery + } + type User { + id: ID + name: String + } + type UsersQuery { + foo: String + usersByIds(id: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { + Unit + } + } + wiring.type("UsersQuery") { type -> + val usersByIds = listOf( + Service2_User(id = "USER-1"), + Service2_User(id = "USER-2"), + Service2_User(id = "USER-3"), + Service2_User(id = "USER-4"), + Service2_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "service2" + field: "users.usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Service1_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Service1_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Service1_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class Service2_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_UsersQuery( + val foo: String? = null, + val usersByIds: List? = null, + ) + + private data class Service1_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default array argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default array argument values snapshot.kt new file mode 100644 index 000000000..169583fe8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default array argument values snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration with default array argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration with default array argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"], test: ["Hello", "World"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"], test: ["Hello", "World"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default array argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default array argument values.kt new file mode 100644 index 000000000..5be7d2709 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default array argument values.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration with default array argument values` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID], test: [String]): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID], test: [String]): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("test") == listOf("Hello", "World")) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors(test: [String] = ["Hello", "World"]): [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + {name: "test" value: "${'$'}argument.test"} + ] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default boolean argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default boolean argument values snapshot.kt new file mode 100644 index 000000000..bd93da8e0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default boolean argument values snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration with default boolean argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration with default boolean argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"], test: true) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"], test: true) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default boolean argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default boolean argument values.kt new file mode 100644 index 000000000..8677de5f2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default boolean argument values.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration with default boolean argument values` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID], test: Boolean): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID], test: Boolean): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("test") == true) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors(test: Boolean = true): [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + {name: "test" value: "${'$'}argument.test"} + ] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default int argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default int argument values snapshot.kt new file mode 100644 index 000000000..bdf4346ed --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default int argument values snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration with default int argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration with default int argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"], test: 42) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"], test: 42) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default int argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default int argument values.kt new file mode 100644 index 000000000..8a743bcb1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default int argument values.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration with default int argument values` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID], test: Int): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID], test: Int): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("test") == 42) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors(test: Int = 42): [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + {name: "test" value: "${'$'}argument.test"} + ] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default null argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default null argument values snapshot.kt new file mode 100644 index 000000000..a3595ce57 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default null argument values snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration with default null argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration with default null argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"], test: null) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"], test: null) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default null argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default null argument values.kt new file mode 100644 index 000000000..a75edff76 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default null argument values.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration with default null argument values` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID], test: String = "Hello World"): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID], test: String = "Hello World"): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("test") == null) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors(test: String = null): [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + {name: "test" value: "${'$'}argument.test"} + ] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default object argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default object argument values snapshot.kt new file mode 100644 index 000000000..f12773372 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default object argument values snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration with default object argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration with default object argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"], test: {echo : "Hello World"}) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"], test: {echo : "Hello World"}) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default object argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default object argument values.kt new file mode 100644 index 000000000..7ad770c76 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default object argument values.kt @@ -0,0 +1,139 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration with default object argument values` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID], test: Test): [User] + } + type User { + id: ID + } + input Test { + string: String = "Test" + int: Int = 42 + bool: Boolean = false + number: Int + echo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID], test: Test): [User] + } + type User { + id: ID + } + input Test { + string: String = "Test" + int: Int = 42 + bool: Boolean = false + number: Int + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + val expectedTest = mapOf( + "string" to "Test", + "int" to 42, + "bool" to false, + "echo" to "Hello World", + ) + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("test") == expectedTest) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors(test: Test = {echo: "Hello World"}): [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + {name: "test" value: "${'$'}argument.test"} + ] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_Test( + val string: String? = null, + val int: Int? = null, + val bool: Boolean? = null, + val number: Int? = null, + val echo: String? = null, + ) + + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default string argument values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default string argument values snapshot.kt new file mode 100644 index 000000000..87f0bbfcd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default string argument values snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batched hydration with default string argument values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batched hydration with default string argument values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"], test: "Hello World") { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"], test: "Hello World") { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default string argument values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default string argument values.kt new file mode 100644 index 000000000..ded9899ec --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batched hydration with default string argument values.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batched hydration with default string argument values` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID], test: String): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID], test: String): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("test") == "Hello World") { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors(test: String = "Hello World"): [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + {name: "test" value: "${'$'}argument.test"} + ] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list snapshot.kt new file mode 100644 index 000000000..5c3b7633d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list snapshot.kt @@ -0,0 +1,225 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching of hydration list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching of hydration list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with flattened arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with flattened arguments snapshot.kt new file mode 100644 index 000000000..ff6ad1fdf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with flattened arguments snapshot.kt @@ -0,0 +1,239 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching of hydration list with flattened arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching of hydration list with flattened arguments snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authors: authors { + | authorId + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authors": [ + | { + | "authorId": "USER-1" + | }, + | { + | "authorId": "USER-2" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authors": [ + | { + | "authorId": "USER-3" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authors": [ + | { + | "authorId": "USER-2" + | }, + | { + | "authorId": "USER-4" + | }, + | { + | "authorId": "USER-5" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | }, + | { + | "id": "USER-3", + | "batch_hydration__authors__id": "USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-4", "USER-5"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-4", + | "batch_hydration__authors__id": "USER-4" + | }, + | { + | "id": "USER-5", + | "batch_hydration__authors__id": "USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1" + * }, + * { + * "id": "USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2" + * }, + * { + * "id": "USER-4" + * }, + * { + * "id": "USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1" + | }, + | { + | "id": "USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2" + | }, + | { + | "id": "USER-4" + | }, + | { + | "id": "USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with flattened arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with flattened arguments.kt new file mode 100644 index 000000000..6e7c0c4e0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with flattened arguments.kt @@ -0,0 +1,126 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching of hydration list with flattened arguments` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "id" value: "${'$'}source.authors.authorId"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + authors: [IssueUser] + id: ID + } + type IssueUser { + authorId: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authors = listOf( + Issues_IssueUser(authorId = "USER-1"), + Issues_IssueUser(authorId = "USER-2"), + ), + id = "ISSUE-1", + ), + Issues_Issue( + authors = listOf(Issues_IssueUser(authorId = "USER-3")), + id = "ISSUE-2", + ), + Issues_Issue( + authors = listOf( + Issues_IssueUser(authorId = "USER-2"), + Issues_IssueUser(authorId = "USER-4"), + Issues_IssueUser(authorId = "USER-5"), + ), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val authors: List? = null, + val id: String? = null, + ) + + private data class Issues_IssueUser( + val authorId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with partition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with partition snapshot.kt new file mode 100644 index 000000000..1b7df6e10 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with partition snapshot.kt @@ -0,0 +1,240 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching of hydration list with partition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching of hydration list with partition snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "CLOUD-ID-1/USER-1", + | "CLOUD-ID-2/USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "CLOUD-ID-1/USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "CLOUD-ID-2/USER-4", + | "CLOUD-ID-1/USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["CLOUD-ID-1/USER-1", "CLOUD-ID-1/USER-3"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "CLOUD-ID-1/USER-1", + | "batch_hydration__authors__id": "CLOUD-ID-1/USER-1" + | }, + | { + | "id": "CLOUD-ID-1/USER-3", + | "batch_hydration__authors__id": "CLOUD-ID-1/USER-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["CLOUD-ID-1/USER-5"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "CLOUD-ID-1/USER-5", + | "batch_hydration__authors__id": "CLOUD-ID-1/USER-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["CLOUD-ID-2/USER-2", "CLOUD-ID-2/USER-4"]) { + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "CLOUD-ID-2/USER-2", + | "batch_hydration__authors__id": "CLOUD-ID-2/USER-2" + | }, + | { + | "id": "CLOUD-ID-2/USER-4", + | "batch_hydration__authors__id": "CLOUD-ID-2/USER-4" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "CLOUD-ID-1/USER-1" + * }, + * { + * "id": "CLOUD-ID-2/USER-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "CLOUD-ID-1/USER-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "CLOUD-ID-2/USER-4" + * }, + * { + * "id": "CLOUD-ID-1/USER-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "CLOUD-ID-1/USER-1" + | }, + | { + | "id": "CLOUD-ID-2/USER-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "CLOUD-ID-1/USER-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "CLOUD-ID-2/USER-4" + | }, + | { + | "id": "CLOUD-ID-1/USER-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with partition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with partition.kt new file mode 100644 index 000000000..3f890d40e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list with partition.kt @@ -0,0 +1,114 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching of hydration list with partition` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "CLOUD-ID-1/USER-1"), + UserService_User(id = "CLOUD-ID-1/USER-3"), + UserService_User(id = "CLOUD-ID-1/USER-5"), + UserService_User(id = "CLOUD-ID-2/USER-2"), + UserService_User(id = "CLOUD-ID-2/USER-4"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + val ids = env.getArgument>("id") + if (ids != null) { + val uniqueCloudIds = ids.mapTo(mutableSetOf()) { it.substringBefore("/") } + if (uniqueCloudIds.size > 1) { + throw IllegalArgumentException("Cannot query multiple cloud IDs at once") + } + } + ids?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorIds = listOf("CLOUD-ID-1/USER-1", "CLOUD-ID-2/USER-2"), + id = "ISSUE-1", + ), + Issues_Issue(authorIds = listOf("CLOUD-ID-1/USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("CLOUD-ID-2/USER-4", "CLOUD-ID-1/USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list.kt new file mode 100644 index 000000000..9b65fe4bc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching of hydration list.kt @@ -0,0 +1,104 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching of hydration list` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1"), + UserService_User(id = "USER-2"), + UserService_User(id = "USER-3"), + UserService_User(id = "USER-4"), + UserService_User(id = "USER-5"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Issues_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching absent source input snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching absent source input snapshot.kt new file mode 100644 index 000000000..c32f6c22b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching absent source input snapshot.kt @@ -0,0 +1,148 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching absent source input`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching absent source input snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "comments", + query = """ + | { + | commentsByIds(ids: ["comment/9001"]) { + | __typename + | content + | id + | batch_hydration__content__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "commentsByIds": [ + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000", + | "batch_hydration__content__id": "comment/9001" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issuesByIds(ids: ["issue/1234"]) { + | __typename + | id + | batch_hydration__content__id: id + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "__typename": "Issue", + | "id": "issue/1234", + | "title": "One Two Three Four", + | "batch_hydration__content__id": "issue/1234" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "content": null + * }, + * { + * "content": null + * }, + * { + * "content": { + * "__typename": "Comment", + * "id": "comment/9001", + * "content": "It's over 9000" + * } + * }, + * { + * "content": { + * "__typename": "Issue", + * "id": "issue/1234", + * "title": "One Two Three Four" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "content": null + | }, + | { + | "content": null + | }, + | { + | "content": { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000" + | } + | }, + | { + | "content": { + | "__typename": "Issue", + | "id": "issue/1234", + | "title": "One Two Three Four" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching absent source input.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching absent source input.kt new file mode 100644 index 000000000..502a381d4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching absent source input.kt @@ -0,0 +1,209 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.language.AstPrinter +import graphql.language.AstSorter +import graphql.nadel.NadelServiceExecutionResultImpl +import graphql.nadel.ServiceExecution +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import java.security.MessageDigest +import java.util.concurrent.CompletableFuture +import kotlin.test.assertTrue + +class `batching absent source input` : NadelLegacyIntegrationTest( + query = """ + { + activity { + content { + __typename + ... on Issue { + id + title + } + ... on Comment { + id + content + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [Activity] + } + union ActivityContent = Issue | Comment + type Activity { + id: ID! + contentId: ID + content: ActivityContent + @hydrated( + service: "comments" + field: "commentsByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentId"} + ] + ) + @hydrated( + service: "issues" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [Activity] + } + type Activity { + id: ID! + contentId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_Activity(contentId = null), + Activity_Activity(contentId = ""), + Activity_Activity(contentId = "comment/9001"), + Activity_Activity( + contentId = "issue/1234", + ), + ) + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + Issues_Issue( + id = "issue/1234", + title = "One Two Three Four", + ), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("ids")?.map(issuesByIds::get) + } + } + }, + ), + Service( + name = "comments", + overallSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val commentsById = listOf( + Comments_Comment(content = "It's over 9000", id = "comment/9001"), + ).associateBy { it.id } + + type.dataFetcher("commentsByIds") { env -> + env.getArgument>("ids")?.map(commentsById::get) + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val contentId: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + ) + + private data class Comments_Comment( + val id: String? = null, + val content: String? = null, + ) + + override fun makeServiceExecution(service: Service): ServiceExecution { + if (service.name == "activity") { + // This test returns data that normal GraphQL can't i.e. it's illegal response missing fields + return ServiceExecution { + val query = AstPrinter.printAstCompact(AstSorter().sort(it.query)) + + @OptIn(ExperimentalStdlibApi::class) + val queryHash = MessageDigest + .getInstance("SHA-1") + .digest(query.toByteArray(Charsets.UTF_8)) + .toHexString() + + assertTrue(queryHash == "c123547d3405f8b721b5ed0802570f034cfaa9a7") + + CompletableFuture.completedFuture( + NadelServiceExecutionResultImpl( + data = mutableMapOf( + "activity" to mutableListOf( + mutableMapOf( + "__typename__batch_hydration__content" to "Activity", + ), + mutableMapOf( + "__typename__batch_hydration__content" to "Activity", + "batch_hydration__content__contentId" to "", + ), + mutableMapOf( + "__typename__batch_hydration__content" to "Activity", + "batch_hydration__content__contentId" to "comment/9001", + ), + mutableMapOf( + "__typename__batch_hydration__content" to "Activity", + "batch_hydration__content__contentId" to "issue/1234", + ), + ), + ), + ), + ) + } + } + + return super.makeServiceExecution(service) + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration accepts true condition after a false condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration accepts true condition after a false condition snapshot.kt new file mode 100644 index 000000000..793b01e94 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration accepts true condition after a false condition snapshot.kt @@ -0,0 +1,127 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration accepts true condition after a false condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `batching conditional hydration accepts true condition after a false condition snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": "thisType", + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | othersById(ids: ["barId1", "barId2"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "othersById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration accepts true condition after a false condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration accepts true condition after a false condition.kt new file mode 100644 index 000000000..931c1172b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration accepts true condition after a false condition.kt @@ -0,0 +1,130 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration accepts true condition after a false condition` : + NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val othersById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + ).associateBy { it.id } + + type.dataFetcher("othersById") { env -> + env.getArgument>("ids")?.map(othersById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thatType" } + } + } + ) + @hydrated( + service: "service2" + field: "othersById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thisType" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = "thisType") + } + } + }, + ), + ), + ) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration in abstract type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration in abstract type snapshot.kt new file mode 100644 index 000000000..20a10ac65 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration in abstract type snapshot.kt @@ -0,0 +1,301 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration in abstract type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots] + */ +@Suppress("unused") +public class `batching conditional hydration in abstract type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "monolith", + query = """ + | { + | activity { + | __typename__batch_hydration__content: __typename + | ... on Activity { + | batch_hydration__content__contentIds: contentIds + | batch_hydration__content__contentIds: contentIds + | } + | ... on SingleActivity { + | batch_hydration__content__contentId: contentId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "__typename__batch_hydration__content": "Activity", + | "batch_hydration__content__contentIds": [ + | "issue/4000", + | "comment/5000", + | "comment/6000" + | ] + | }, + | { + | "__typename__batch_hydration__content": "SingleActivity", + | "batch_hydration__content__contentId": "issue/8080" + | }, + | { + | "__typename__batch_hydration__content": "Activity", + | "batch_hydration__content__contentIds": [ + | "comment/1234", + | "comment/9001" + | ] + | }, + | { + | "__typename__batch_hydration__content": "SingleActivity", + | "batch_hydration__content__contentId": "issue/7496" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "monolith", + query = """ + | { + | commentsByIds(ids: ["comment/5000", "comment/6000", "comment/1234", "comment/9001"]) { + | __typename + | content + | id + | batch_hydration__content__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "commentsByIds": [ + | { + | "__typename": "Comment", + | "id": "comment/5000", + | "content": "Five Thousand", + | "batch_hydration__content__id": "comment/5000" + | }, + | { + | "__typename": "Comment", + | "id": "comment/6000", + | "content": "Six Thousand", + | "batch_hydration__content__id": "comment/6000" + | }, + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four", + | "batch_hydration__content__id": "comment/1234" + | }, + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000", + | "batch_hydration__content__id": "comment/9001" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "monolith", + query = """ + | { + | issuesByIds(ids: ["issue/4000"]) { + | __typename + | id + | batch_hydration__content__id: id + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "__typename": "Issue", + | "id": "issue/4000", + | "title": "Four Thousand", + | "batch_hydration__content__id": "issue/4000" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "monolith", + query = """ + | { + | issuesByIds(ids: ["issue/8080", "issue/7496"]) { + | __typename + | id + | batch_hydration__content__id: id + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six", + | "batch_hydration__content__id": "issue/7496" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/4000", + * "title": "Four Thousand" + * }, + * { + * "__typename": "Comment", + * "id": "comment/5000", + * "content": "Five Thousand" + * }, + * { + * "__typename": "Comment", + * "id": "comment/6000", + * "content": "Six Thousand" + * } + * ] + * }, + * { + * "content": [ + * null + * ] + * }, + * { + * "content": [ + * { + * "__typename": "Comment", + * "id": "comment/1234", + * "content": "One Two Three Four" + * }, + * { + * "__typename": "Comment", + * "id": "comment/9001", + * "content": "It's over 9000" + * } + * ] + * }, + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/7496", + * "title": "Seven Four Nine Six" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/4000", + | "title": "Four Thousand" + | }, + | { + | "__typename": "Comment", + | "id": "comment/5000", + | "content": "Five Thousand" + | }, + | { + | "__typename": "Comment", + | "id": "comment/6000", + | "content": "Six Thousand" + | } + | ] + | }, + | { + | "content": [ + | null + | ] + | }, + | { + | "content": [ + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four" + | }, + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000" + | } + | ] + | }, + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration in abstract type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration in abstract type.kt new file mode 100644 index 000000000..64a578ea0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration in abstract type.kt @@ -0,0 +1,185 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration in abstract type` : NadelLegacyIntegrationTest( + query = """ + { + activity { + content { + __typename + ... on Issue { + id + title + } + ... on Comment { + id + content + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "monolith", + overallSchema = """ + type Query { + activity: [IActivity] + issuesByIds(ids: [ID!]!): [Issue!] + commentsByIds(ids: [ID!]!): [Comment!] + } + interface IActivity { + content: [ActivityContent] + } + union ActivityContent = Issue | Comment + type Activity implements IActivity { + id: ID! + content: [ActivityContent] + @hydrated( + service: "monolith" + field: "commentsByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentIds"} + ] + ) + @hydrated( + service: "monolith" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentIds"} + ] + ) + } + type SingleActivity implements IActivity { + id: ID! + content: [ActivityContent] + @hydrated( + service: "monolith" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentId"} + ] + ) + } + type Issue { + id: ID! + title: String + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [IActivity] + commentsByIds(ids: [ID!]!): [Comment!] + issuesByIds(ids: [ID!]!): [Issue!] + } + interface IActivity { + content: [ActivityContent] + } + union ActivityContent = Issue | Comment + type Activity implements IActivity { + id: ID! + content: [ActivityContent] + contentIds: [ID!] + } + type SingleActivity implements IActivity { + id: ID! + content: [ActivityContent] + contentId: ID! + } + type Issue { + id: ID! + title: String + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesById = listOf( + Monolith_Issue(id = "issue/4000", title = "Four Thousand"), + Monolith_Issue(id = "issue/7496", title = "Seven Four Nine Six"), + ).associateBy { it.id } + val commentsById = listOf( + Monolith_Comment(content = "Five Thousand", id = "comment/5000"), + Monolith_Comment(content = "Six Thousand", id = "comment/6000"), + Monolith_Comment(content = "It's over 9000", id = "comment/9001"), + Monolith_Comment(content = "One Two Three Four", id = "comment/1234"), + ).associateBy { it.id } + + type + .dataFetcher("activity") { env -> + listOf( + Monolith_Activity( + contentIds = listOf( + "issue/4000", + "comment/5000", + "comment/6000", + ), + ), + Monolith_SingleActivity(contentId = "issue/8080"), + Monolith_Activity(contentIds = listOf("comment/1234", "comment/9001")), + Monolith_SingleActivity(contentId = "issue/7496"), + ) + } + .dataFetcher("issuesByIds") { env -> + env.getArgument>("ids")?.mapNotNull(issuesById::get) + } + .dataFetcher("commentsByIds") { env -> + env.getArgument>("ids")?.map(commentsById::get) + } + } + wiring.type("ActivityContent") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("IActivity") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Monolith_Activity( + val id: String? = null, + override val content: List? = null, + val contentIds: List? = null, + ) : Monolith_IActivity + + private sealed interface Monolith_ActivityContent + + private data class Monolith_Comment( + val id: String? = null, + val content: String? = null, + ) : Monolith_ActivityContent + + private interface Monolith_IActivity { + val content: List? + } + + private data class Monolith_Issue( + val id: String? = null, + val title: String? = null, + ) : Monolith_ActivityContent + + private data class Monolith_SingleActivity( + val id: String? = null, + override val content: List? = null, + val contentId: String? = null, + ) : Monolith_IActivity +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with false conditions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with false conditions snapshot.kt new file mode 100644 index 000000000..9ee6a535a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with false conditions snapshot.kt @@ -0,0 +1,87 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration with false conditions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration with false conditions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": "thatOtherType", + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with false conditions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with false conditions.kt new file mode 100644 index 000000000..88d89e8e3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with false conditions.kt @@ -0,0 +1,117 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration with false conditions` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thatType" } + } + } + ) + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thisType" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = "thatOtherType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with list condition field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with list condition field snapshot.kt new file mode 100644 index 000000000..ce9d7b5ff --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with list condition field snapshot.kt @@ -0,0 +1,116 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration with list condition field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration with list condition field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(ids: ["barId2"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * { + * "name": "Bar2" + * }, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | { + | "name": "Bar2" + | }, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with list condition field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with list condition field.kt new file mode 100644 index 000000000..73b74ba63 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with list condition field.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration with list condition field` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = "barId2", name = "Bar2"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("ids")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + barIds: [ID] @hidden + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "barIds" + predicate: { equals: "barId2" } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with multiple true conditions takes first snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with multiple true conditions takes first snapshot.kt new file mode 100644 index 000000000..71be58355 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with multiple true conditions takes first snapshot.kt @@ -0,0 +1,126 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration with multiple true conditions takes first`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration with multiple true conditions takes first snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": "thisType", + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(ids: ["barId1", "barId2"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with multiple true conditions takes first.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with multiple true conditions takes first.kt new file mode 100644 index 000000000..a58faf099 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration with multiple true conditions takes first.kt @@ -0,0 +1,129 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration with multiple true conditions takes first` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("ids")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "this" } + } + } + ) + @hydrated( + service: "service2" + field: "othersById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thisType" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = "thisType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when equals condition field is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when equals condition field is null snapshot.kt new file mode 100644 index 000000000..3502c7055 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when equals condition field is null snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration works when equals condition field is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration works when equals condition field is null snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": null, + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when equals condition field is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when equals condition field is null.kt new file mode 100644 index 000000000..becfc088f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when equals condition field is null.kt @@ -0,0 +1,117 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration works when equals condition field is null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thatType" } + } + } + ) + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "thisType" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = null) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when matches condition field is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when matches condition field is null snapshot.kt new file mode 100644 index 000000000..b80b382d5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when matches condition field is null snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration works when matches condition field is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration works when matches condition field is null snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": null, + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when matches condition field is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when matches condition field is null.kt new file mode 100644 index 000000000..3bbe3d535 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when matches condition field is null.kt @@ -0,0 +1,117 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration works when matches condition field is null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "that.*" } + } + } + ) + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "this.*" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = null) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when startsWith condition field is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when startsWith condition field is null snapshot.kt new file mode 100644 index 000000000..f6769c4be --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when startsWith condition field is null snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration works when startsWith condition field is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration works when startsWith condition field is null snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": null, + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when startsWith condition field is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when startsWith condition field is null.kt new file mode 100644 index 000000000..e960ca20a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works when startsWith condition field is null.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration works when startsWith condition field is null` : + NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "that" } + } + } + ) + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "this" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = null) + } + } + }, + ), + ), + ) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with int type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with int type snapshot.kt new file mode 100644 index 000000000..68eca2841 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with int type snapshot.kt @@ -0,0 +1,116 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration works with int type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration works with int type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | 1, + | 2, + | 3 + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(ids: [2]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar2", + | "batch_hydration__bar__id": 2 + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * { + * "name": "Bar2" + * }, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | { + | "name": "Bar2" + | }, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with int type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with int type.kt new file mode 100644 index 000000000..f5538f914 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with int type.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration works with int type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [Int]): [Bar] + } + type Bar { + id: Int + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: Int + name: String + } + type Query { + barsById(ids: [Int]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = 2, name = "Bar2"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("ids")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: Int + barIds: [Int] @hidden + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "barIds" + predicate: { equals: 2 } + } + } + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [Int] + id: Int + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf(1, 2, 3)) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: Int? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with matches condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with matches condition snapshot.kt new file mode 100644 index 000000000..615477d62 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with matches condition snapshot.kt @@ -0,0 +1,126 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration works with matches condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration works with matches condition snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": "thisType", + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | othersById(ids: ["barId1", "barId2"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "othersById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with matches condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with matches condition.kt new file mode 100644 index 000000000..075e249a4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with matches condition.kt @@ -0,0 +1,129 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration works with matches condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val othersById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + ).associateBy { it.id } + + type.dataFetcher("othersById") { env -> + env.getArgument>("ids")?.map(othersById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "that[a-zA-Z]+" } + } + } + ) + @hydrated( + service: "service2" + field: "othersById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "this[a-zA-Z]+" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = "thisType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with startsWith condition snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with startsWith condition snapshot.kt new file mode 100644 index 000000000..996405bb5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with startsWith condition snapshot.kt @@ -0,0 +1,126 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching conditional hydration works with startsWith condition`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching conditional hydration works with startsWith condition snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__barIds: barIds + | batch_hydration__bar__type: type + | batch_hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barIds": [ + | "barId1", + | "barId2" + | ], + | "batch_hydration__bar__type": "thisType", + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | othersById(ids: ["barId1", "barId2"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "othersById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with startsWith condition.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with startsWith condition.kt new file mode 100644 index 000000000..98b95ac31 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching conditional hydration works with startsWith condition.kt @@ -0,0 +1,129 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching conditional hydration works with startsWith condition` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(ids: [ID]): [Bar] + othersById(ids: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val othersById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + ).associateBy { it.id } + + type.dataFetcher("othersById") { env -> + env.getArgument>("ids")?.map(othersById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: [Bars] + @hydrated( + service: "service2" + field: "barsById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "that" } + } + } + ) + @hydrated( + service: "service2" + field: "othersById" + arguments: [ + { + name: "ids" + value: "${'$'}source.barIds" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "this" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2"), type = "thisType") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching multiple source ids going to different services snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching multiple source ids going to different services snapshot.kt new file mode 100644 index 000000000..2e6947c75 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching multiple source ids going to different services snapshot.kt @@ -0,0 +1,307 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching multiple source ids going to different services`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching multiple source ids going to different services snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | __typename__batch_hydration__content: __typename + | batch_hydration__content__contentIds: contentIds + | batch_hydration__content__contentIds: contentIds + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "batch_hydration__content__contentIds": [ + | "issue/4000", + | "comment/5000", + | "comment/6000" + | ], + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentIds": [ + | "issue/8080" + | ], + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentIds": [ + | "issue/7496", + | "comment/9001" + | ], + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentIds": [ + | "issue/1234", + | "comment/1234" + | ], + | "__typename__batch_hydration__content": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "comments", + query = """ + | { + | commentsByIds(ids: ["comment/5000", "comment/6000", "comment/9001", "comment/1234"]) { + | __typename + | content + | id + | batch_hydration__content__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "commentsByIds": [ + | { + | "__typename": "Comment", + | "id": "comment/5000", + | "content": "Five Thousand", + | "batch_hydration__content__id": "comment/5000" + | }, + | { + | "__typename": "Comment", + | "id": "comment/6000", + | "content": "Six Thousand", + | "batch_hydration__content__id": "comment/6000" + | }, + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000", + | "batch_hydration__content__id": "comment/9001" + | }, + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four", + | "batch_hydration__content__id": "comment/1234" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issuesByIds(ids: ["issue/4000", "issue/8080", "issue/7496", "issue/1234"]) { + | __typename + | id + | batch_hydration__content__id: id + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "__typename": "Issue", + | "id": "issue/4000", + | "title": "Four Thousand", + | "batch_hydration__content__id": "issue/4000" + | }, + | { + | "__typename": "Issue", + | "id": "issue/8080", + | "title": "Eighty Eighty", + | "batch_hydration__content__id": "issue/8080" + | }, + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six", + | "batch_hydration__content__id": "issue/7496" + | }, + | { + | "__typename": "Issue", + | "id": "issue/1234", + | "title": "One Two Three Four", + | "batch_hydration__content__id": "issue/1234" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/4000", + * "title": "Four Thousand" + * }, + * { + * "__typename": "Comment", + * "id": "comment/5000", + * "content": "Five Thousand" + * }, + * { + * "__typename": "Comment", + * "id": "comment/6000", + * "content": "Six Thousand" + * } + * ] + * }, + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/8080", + * "title": "Eighty Eighty" + * } + * ] + * }, + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/7496", + * "title": "Seven Four Nine Six" + * }, + * { + * "__typename": "Comment", + * "id": "comment/9001", + * "content": "It's over 9000" + * } + * ] + * }, + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/1234", + * "title": "One Two Three Four" + * }, + * { + * "__typename": "Comment", + * "id": "comment/1234", + * "content": "One Two Three Four" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/4000", + | "title": "Four Thousand" + | }, + | { + | "__typename": "Comment", + | "id": "comment/5000", + | "content": "Five Thousand" + | }, + | { + | "__typename": "Comment", + | "id": "comment/6000", + | "content": "Six Thousand" + | } + | ] + | }, + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/8080", + | "title": "Eighty Eighty" + | } + | ] + | }, + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six" + | }, + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000" + | } + | ] + | }, + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/1234", + | "title": "One Two Three Four" + | }, + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching multiple source ids going to different services.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching multiple source ids going to different services.kt new file mode 100644 index 000000000..f4f53ee90 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching multiple source ids going to different services.kt @@ -0,0 +1,187 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching multiple source ids going to different services` : NadelLegacyIntegrationTest( + query = """ + { + activity { + content { + __typename + ... on Issue { + id + title + } + ... on Comment { + id + content + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [Activity] + } + union ActivityContent = Issue | Comment + type Activity { + id: ID! + contentIds: [ID!]! + content: [ActivityContent] + @hydrated( + service: "comments" + field: "commentsByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentIds"} + ] + ) + @hydrated( + service: "issues" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentIds"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [Activity] + } + type Activity { + id: ID! + contentIds: [ID!]! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_Activity( + contentIds = listOf( + "issue/4000", + "comment/5000", + "comment/6000", + ), + ), + Activity_Activity(contentIds = listOf("issue/8080")), + Activity_Activity(contentIds = listOf("issue/7496", "comment/9001")), + Activity_Activity(contentIds = listOf("issue/1234", "comment/1234")), + ) + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesById = listOf( + Issues_Issue( + id = "issue/4000", + title = "Four Thousand", + ), + Issues_Issue( + id = "issue/8080", + title = "Eighty Eighty", + ), + Issues_Issue( + id = "issue/7496", + title = "Seven Four Nine Six", + ), + Issues_Issue( + id = "issue/1234", + title = "One Two Three Four", + ), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("ids")?.mapNotNull(issuesById::get) + } + } + }, + ), + Service( + name = "comments", + overallSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("commentsByIds") { env -> + if (env.getArgument("ids") == + listOf( + "comment/5000", + "comment/6000", + "comment/9001", + "comment/1234", + ) + ) { + listOf( + Comments_Comment(content = "Five Thousand", id = "comment/5000"), + Comments_Comment(content = "Six Thousand", id = "comment/6000"), + Comments_Comment(content = "It's over 9000", id = "comment/9001"), + Comments_Comment(content = "One Two Three Four", id = "comment/1234"), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val contentIds: List? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + ) + + private data class Comments_Comment( + val id: String? = null, + val content: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching no source inputs snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching no source inputs snapshot.kt new file mode 100644 index 000000000..8e9d57cb6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching no source inputs snapshot.kt @@ -0,0 +1,233 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching no source inputs`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots] + */ +@Suppress("unused") +public class `batching no source inputs snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | __typename__batch_hydration__content: __typename + | batch_hydration__content__contentIds: contentIds + | batch_hydration__content__contentIds: contentIds + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "batch_hydration__content__contentIds": [], + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentIds": [], + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentIds": [ + | "issue/7496", + | "comment/9001" + | ], + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentIds": [ + | "issue/1234", + | "comment/1234" + | ], + | "__typename__batch_hydration__content": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "comments", + query = """ + | { + | commentsByIds(ids: ["comment/9001", "comment/1234"]) { + | __typename + | content + | id + | batch_hydration__content__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "commentsByIds": [ + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000", + | "batch_hydration__content__id": "comment/9001" + | }, + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four", + | "batch_hydration__content__id": "comment/1234" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issuesByIds(ids: ["issue/7496", "issue/1234"]) { + | __typename + | id + | batch_hydration__content__id: id + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six", + | "batch_hydration__content__id": "issue/7496" + | }, + | { + | "__typename": "Issue", + | "id": "issue/1234", + | "title": "One Two Three Four", + | "batch_hydration__content__id": "issue/1234" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "content": [] + * }, + * { + * "content": [] + * }, + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/7496", + * "title": "Seven Four Nine Six" + * }, + * { + * "__typename": "Comment", + * "id": "comment/9001", + * "content": "It's over 9000" + * } + * ] + * }, + * { + * "content": [ + * { + * "__typename": "Issue", + * "id": "issue/1234", + * "title": "One Two Three Four" + * }, + * { + * "__typename": "Comment", + * "id": "comment/1234", + * "content": "One Two Three Four" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "content": [] + | }, + | { + | "content": [] + | }, + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six" + | }, + | { + | "__typename": "Comment", + | "id": "comment/9001", + | "content": "It's over 9000" + | } + | ] + | }, + | { + | "content": [ + | { + | "__typename": "Issue", + | "id": "issue/1234", + | "title": "One Two Three Four" + | }, + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching no source inputs.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching no source inputs.kt new file mode 100644 index 000000000..956d427ed --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching no source inputs.kt @@ -0,0 +1,158 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching no source inputs` : NadelLegacyIntegrationTest( + query = """ + { + activity { + content { + __typename + ... on Issue { + id + title + } + ... on Comment { + id + content + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [Activity] + } + union ActivityContent = Issue | Comment + type Activity { + id: ID! + contentIds: [ID!]! + content: [ActivityContent] + @hydrated( + service: "comments" + field: "commentsByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentIds"} + ] + ) + @hydrated( + service: "issues" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentIds"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [Activity] + } + type Activity { + id: ID! + contentIds: [ID!]! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_Activity(contentIds = emptyList()), + Activity_Activity( + contentIds = emptyList(), + ), + Activity_Activity(contentIds = listOf("issue/7496", "comment/9001")), + Activity_Activity(contentIds = listOf("issue/1234", "comment/1234")), + ) + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + Issues_Issue(id = "issue/7496", title = "Seven Four Nine Six"), + Issues_Issue(id = "issue/1234", title = "One Two Three Four"), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("ids")?.map(issuesByIds::get) + } + } + }, + ), + Service( + name = "comments", + overallSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val commentsById = listOf( + Comments_Comment(content = "One Two Three Four", id = "comment/1234"), + Comments_Comment(content = "It's over 9000", id = "comment/9001"), + ).associateBy { it.id } + + type.dataFetcher("commentsByIds") { env -> + env.getArgument>("ids")?.map(commentsById::get) + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val contentIds: List? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + ) + + private data class Comments_Comment( + val id: String? = null, + val content: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching null source input object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching null source input object snapshot.kt new file mode 100644 index 000000000..ed439d677 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching null source input object snapshot.kt @@ -0,0 +1,82 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching null source input object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching null source input object snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | __typename__batch_hydration__content: __typename + | batch_hydration__content__reference: reference { + | issueId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "batch_hydration__content__reference": null, + | "__typename__batch_hydration__content": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "content": null + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "content": null + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching null source input object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching null source input object.kt new file mode 100644 index 000000000..2aa7913a2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching null source input object.kt @@ -0,0 +1,97 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching null source input object` : NadelLegacyIntegrationTest( + query = """ + { + activity { + content { + __typename + ... on Issue { + id + title + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [Activity] + } + type Activity { + id: ID! + content: Issue + @hydrated( + service: "issues" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.reference.issueId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [Activity] + } + type Activity { + id: ID! + reference: ActivityReference + } + type ActivityReference { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf(Activity_Activity(reference = null)) + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val reference: Activity_ActivityReference? = null, + ) + + private data class Activity_ActivityReference( + val issueId: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching single source id snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching single source id snapshot.kt new file mode 100644 index 000000000..3391ac6e9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching single source id snapshot.kt @@ -0,0 +1,215 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batching single source id`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batching single source id snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "activity", + query = """ + | { + | activity { + | __typename__batch_hydration__content: __typename + | batch_hydration__content__contentId: contentId + | batch_hydration__content__contentId: contentId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activity": [ + | { + | "batch_hydration__content__contentId": "issue/4000", + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentId": "issue/8080", + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentId": "issue/7496", + | "__typename__batch_hydration__content": "Activity" + | }, + | { + | "batch_hydration__content__contentId": "comment/1234", + | "__typename__batch_hydration__content": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "comments", + query = """ + | { + | commentsByIds(ids: ["comment/1234"]) { + | __typename + | content + | id + | batch_hydration__content__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "commentsByIds": [ + | { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four", + | "batch_hydration__content__id": "comment/1234" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issuesByIds(ids: ["issue/4000", "issue/8080", "issue/7496"]) { + | __typename + | id + | batch_hydration__content__id: id + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "__typename": "Issue", + | "id": "issue/4000", + | "title": "Four Thousand", + | "batch_hydration__content__id": "issue/4000" + | }, + | { + | "__typename": "Issue", + | "id": "issue/8080", + | "title": "Eighty Eighty", + | "batch_hydration__content__id": "issue/8080" + | }, + | { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six", + | "batch_hydration__content__id": "issue/7496" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activity": [ + * { + * "content": { + * "__typename": "Issue", + * "id": "issue/4000", + * "title": "Four Thousand" + * } + * }, + * { + * "content": { + * "__typename": "Issue", + * "id": "issue/8080", + * "title": "Eighty Eighty" + * } + * }, + * { + * "content": { + * "__typename": "Issue", + * "id": "issue/7496", + * "title": "Seven Four Nine Six" + * } + * }, + * { + * "content": { + * "__typename": "Comment", + * "id": "comment/1234", + * "content": "One Two Three Four" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activity": [ + | { + | "content": { + | "__typename": "Issue", + | "id": "issue/4000", + | "title": "Four Thousand" + | } + | }, + | { + | "content": { + | "__typename": "Issue", + | "id": "issue/8080", + | "title": "Eighty Eighty" + | } + | }, + | { + | "content": { + | "__typename": "Issue", + | "id": "issue/7496", + | "title": "Seven Four Nine Six" + | } + | }, + | { + | "content": { + | "__typename": "Comment", + | "id": "comment/1234", + | "content": "One Two Three Four" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching single source id.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching single source id.kt new file mode 100644 index 000000000..7a11a5e1f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/batching/batching single source id.kt @@ -0,0 +1,167 @@ +package graphql.nadel.tests.legacy.`new hydration`.batching + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batching single source id` : NadelLegacyIntegrationTest( + query = """ + { + activity { + content { + __typename + ... on Issue { + id + title + } + ... on Comment { + id + content + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "activity", + overallSchema = """ + type Query { + activity: [Activity] + } + union ActivityContent = Issue | Comment + type Activity { + id: ID! + contentId: ID! + content: ActivityContent + @hydrated( + service: "comments" + field: "commentsByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentId"} + ] + ) + @hydrated( + service: "issues" + field: "issuesByIds" + arguments: [ + {name: "ids" value: "${'$'}source.contentId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activity: [Activity] + } + type Activity { + id: ID! + contentId: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activity") { env -> + listOf( + Activity_Activity(contentId = "issue/4000"), + Activity_Activity( + contentId = "issue/8080", + ), + Activity_Activity(contentId = "issue/7496"), + Activity_Activity(contentId = "comment/1234"), + ) + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issuesByIds(ids: [ID!]!): [Issue!] + } + type Issue { + id: ID! + title: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + Issues_Issue( + id = "issue/4000", + title = "Four Thousand", + ), + Issues_Issue( + id = "issue/8080", + title = "Eighty Eighty", + ), + Issues_Issue( + id = "issue/7496", + title = "Seven Four Nine Six", + ), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("ids")?.map(issuesByIds::get) + } + } + }, + ), + Service( + name = "comments", + overallSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + commentsByIds(ids: [ID!]!): [Comment!] + } + type Comment { + id: ID! + content: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val commentsById = listOf( + Comments_Comment(content = "One Two Three Four", id = "comment/1234") + ).associateBy { it.id } + + type.dataFetcher("commentsByIds") { env -> + env.getArgument>("ids")?.map(commentsById::get) + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val contentId: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + ) + + private data class Comments_Comment( + val id: String? = null, + val content: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration for specific service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration for specific service snapshot.kt new file mode 100644 index 000000000..735b33441 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration for specific service snapshot.kt @@ -0,0 +1,133 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can generate legacy operation name on batch hydration for specific service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can generate legacy operation name on batch hydration for specific service snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | query nadel_2_service2 { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | }, + | { + | "name": "Bar3", + | "batch_hydration__bar__id": "barId3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * }, + * { + * "name": "Bar3" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | }, + | { + | "name": "Bar3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration for specific service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration for specific service.kt new file mode 100644 index 000000000..5e92ad504 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration for specific service.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can generate legacy operation name on batch hydration for specific service` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + Service2_Bar(id = "barId3", name = "Bar3"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration snapshot.kt new file mode 100644 index 000000000..492a46e85 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can generate legacy operation name on batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can generate legacy operation name on batch hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | query nadel_2_service1 { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | query nadel_2_service2 { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | }, + | { + | "name": "Bar3", + | "batch_hydration__bar__id": "barId3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * }, + * { + * "name": "Bar3" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | }, + | { + | "name": "Bar3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration.kt new file mode 100644 index 000000000..a5bfb9b90 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on batch hydration.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can generate legacy operation name on batch hydration` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + Service2_Bar(id = "barId3", name = "Bar3"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on hydration snapshot.kt new file mode 100644 index 000000000..05570a433 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on hydration snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can generate legacy operation name on hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can generate legacy operation name on hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | query nadel_2_service1_TestFoo { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | query nadel_2_service2_TestFoo { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on hydration.kt new file mode 100644 index 000000000..b96ad29d8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/can generate legacy operation name on hydration.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can generate legacy operation name on hydration` : NadelLegacyIntegrationTest( + query = """ + query TestFoo { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by doesnt use all input fields in the inputIdentifiedBy argument snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by doesnt use all input fields in the inputIdentifiedBy argument snapshot.kt new file mode 100644 index 000000000..0015c2721 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by doesnt use all input fields in the inputIdentifiedBy argument snapshot.kt @@ -0,0 +1,221 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by doesnt use all input fields in the inputIdentifiedBy argument`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `complex identified by doesnt use all input fields in the inputIdentifiedBy argument snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Activity", + query = """ + | { + | activities { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__context: context { + | issueHydrationInput { + | id + | } + | } + | batch_hydration__issue__context: context { + | issueHydrationInput { + | site + | } + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activities": [ + | { + | "id": "ACTIVITY-0", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-0", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-1", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-1", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-2", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-2", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-3", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-3", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issue", + query = """ + | { + | issues(issuesInput: [{id : "ISSUE-0", site : "CLOUD-0"}, {id : "ISSUE-1", site : "CLOUD-0"}, {id : "ISSUE-2", site : "CLOUD-0"}, {id : "ISSUE-3", site : "CLOUD-0"}]) { + | description + | issueId + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "issueId": "ISSUE-0", + | "description": "fix A", + | "batch_hydration__issue__issueId": "ISSUE-0" + | }, + | { + | "issueId": "ISSUE-1", + | "description": "fix B", + | "batch_hydration__issue__issueId": "ISSUE-1" + | }, + | { + | "issueId": "ISSUE-2", + | "description": "fix C", + | "batch_hydration__issue__issueId": "ISSUE-2" + | }, + | { + | "issueId": "ISSUE-3", + | "description": "fix D", + | "batch_hydration__issue__issueId": "ISSUE-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activities": [ + * { + * "id": "ACTIVITY-0", + * "issue": { + * "issueId": "ISSUE-0", + * "description": "fix A" + * } + * }, + * { + * "id": "ACTIVITY-1", + * "issue": { + * "issueId": "ISSUE-1", + * "description": "fix B" + * } + * }, + * { + * "id": "ACTIVITY-2", + * "issue": { + * "issueId": "ISSUE-2", + * "description": "fix C" + * } + * }, + * { + * "id": "ACTIVITY-3", + * "issue": { + * "issueId": "ISSUE-3", + * "description": "fix D" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activities": [ + | { + | "id": "ACTIVITY-0", + | "issue": { + | "issueId": "ISSUE-0", + | "description": "fix A" + | } + | }, + | { + | "id": "ACTIVITY-1", + | "issue": { + | "issueId": "ISSUE-1", + | "description": "fix B" + | } + | }, + | { + | "id": "ACTIVITY-2", + | "issue": { + | "issueId": "ISSUE-2", + | "description": "fix C" + | } + | }, + | { + | "id": "ACTIVITY-3", + | "issue": { + | "issueId": "ISSUE-3", + | "description": "fix D" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by doesnt use all input fields in the inputIdentifiedBy argument.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by doesnt use all input fields in the inputIdentifiedBy argument.kt new file mode 100644 index 000000000..50f5600e5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by doesnt use all input fields in the inputIdentifiedBy argument.kt @@ -0,0 +1,182 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by doesnt use all input fields in the inputIdentifiedBy argument` : + NadelLegacyIntegrationTest( + query = """ + query { + activities { + id + issue { + issueId + description + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Activity", + overallSchema = """ + type Query { + activities: [Activity] + } + type Activity { + id: ID + issue: Issue @hydrated( + service: "Issue" + field: "issues" + arguments: [{name: "issuesInput" value: "${'$'}source.context.issueHydrationInput"}] + inputIdentifiedBy: [ + {sourceId: "context.issueHydrationInput.id" resultId: "issueId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activities: [Activity] + } + type Activity { + id: ID + context: HydrationContext + } + type HydrationContext { + issueHydrationInput: IssueHydrationInput + } + type IssueHydrationInput { + id: ID! + site: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activities") { env -> + listOf( + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-0", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-0", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-1", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-1", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-2", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-2", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-3", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-3", + ), + ) + } + } + }, + ), + Service( + name = "Issue", + overallSchema = """ + type Query { + issues(issuesInput: [IssueInput!]): [Issue] + } + type Issue { + issueId: ID + description: String + } + input IssueInput { + id: ID! + site: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues(issuesInput: [IssueInput!]): [Issue] + } + type Issue { + issueId: ID + description: String + } + input IssueInput { + id: ID! + site: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + if (env.getArgument("issuesInput") == + listOf( + mapOf("id" to "ISSUE-0", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-1", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-2", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-3", "site" to "CLOUD-0"), + ) + ) { + listOf( + Issue_Issue(description = "fix A", issueId = "ISSUE-0"), + Issue_Issue( + description = "fix B", + issueId = "ISSUE-1", + ), + Issue_Issue( + description = "fix C", + issueId = "ISSUE-2", + ), + Issue_Issue(description = "fix D", issueId = "ISSUE-3"), + ) + } else { + null + } + } + } + }, + ), + ), + ) { + private data class Activity_Activity( + val id: String? = null, + val context: Activity_HydrationContext? = null, + ) + + private data class Activity_HydrationContext( + val issueHydrationInput: Activity_IssueHydrationInput? = null, + ) + + private data class Activity_IssueHydrationInput( + val id: String? = null, + val site: String? = null, + ) + + private data class Issue_Issue( + val issueId: String? = null, + val description: String? = null, + ) + + private data class Issue_IssueInput( + val id: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by hydration batching returns null batch snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by hydration batching returns null batch snapshot.kt new file mode 100644 index 000000000..03ffbc62b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by hydration batching returns null batch snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by hydration batching returns null batch`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by hydration batching returns null batch snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by hydration batching returns null batch.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by hydration batching returns null batch.kt new file mode 100644 index 000000000..0693f1347 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by hydration batching returns null batch.kt @@ -0,0 +1,89 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by hydration batching returns null batch` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsById") { env -> + null + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] @hydrated( + service: "service2" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + inputIdentifiedBy: [{sourceId: "barId" resultId: "id"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is absent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is absent snapshot.kt new file mode 100644 index 000000000..3a429c31b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is absent snapshot.kt @@ -0,0 +1,86 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by input is absent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by input is absent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authors: authors { + | id + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authors": [], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is absent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is absent.kt new file mode 100644 index 000000000..770a66db0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is absent.kt @@ -0,0 +1,97 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by input is absent` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "ids" value: "${'$'}source.authors.id"} + ] + inputIdentifiedBy: [ + {sourceId: "authors.id" resultId: "id"} + ] + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authors: [UserRef] + id: ID + } + type UserRef { + id: ID! + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authors = listOf(), id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authors: List? = null, + val id: String? = null, + ) + + private data class Issues_UserRef( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is null snapshot.kt new file mode 100644 index 000000000..fd8ff52df --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is null snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by input is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by input is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": null, + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": null + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": null + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is null.kt new file mode 100644 index 000000000..bd2099403 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by input is null.kt @@ -0,0 +1,90 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by input is null` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "ids" value: "${'$'}source.authorIds"} + ] + inputIdentifiedBy: [ + {sourceId: "authorIds" resultId: "id"} + ] + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorIds = null, id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by snapshot.kt new file mode 100644 index 000000000..79f843c42 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by snapshot.kt @@ -0,0 +1,314 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__author: __typename + | batch_hydration__author__authorId: authorId { + | userId + | } + | batch_hydration__author__authorId: authorId { + | site + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__author__authorId": { + | "userId": "USER-1", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__author__authorId": { + | "userId": "USER-3", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__author__authorId": { + | "userId": "USER-2", + | "site": "jdog" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-4", + | "batch_hydration__author__authorId": { + | "userId": "USER-4", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-5", + | "batch_hydration__author__authorId": { + | "userId": "USER-5", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-6", + | "batch_hydration__author__authorId": { + | "userId": "USER-2", + | "site": "jdog" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-7", + | "batch_hydration__author__authorId": { + | "userId": "USER-2", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users(id: [{site : "hello", userId : "USER-1"}, {site : "hello", userId : "USER-3"}, {site : "jdog", userId : "USER-2"}, {site : "hello", userId : "USER-4"}]) { + | id + | batch_hydration__author__id: id + | name + | batch_hydration__author__siteId: siteId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-1", + | "name": "H-One", + | "batch_hydration__author__id": "USER-1", + | "batch_hydration__author__siteId": "hello" + | }, + | { + | "id": "USER-3", + | "name": "H-Three", + | "batch_hydration__author__id": "USER-3", + | "batch_hydration__author__siteId": "hello" + | }, + | { + | "id": "USER-2", + | "name": "J-Two", + | "batch_hydration__author__id": "USER-2", + | "batch_hydration__author__siteId": "jdog" + | }, + | { + | "id": "USER-4", + | "name": "H-Four", + | "batch_hydration__author__id": "USER-4", + | "batch_hydration__author__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users(id: [{site : "hello", userId : "USER-5"}, {site : "hello", userId : "USER-2"}]) { + | id + | batch_hydration__author__id: id + | name + | batch_hydration__author__siteId: siteId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-5", + | "name": "H-Five", + | "batch_hydration__author__id": "USER-5", + | "batch_hydration__author__siteId": "hello" + | }, + | { + | "id": "USER-2", + | "name": "H-Two", + | "batch_hydration__author__id": "USER-2", + | "batch_hydration__author__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": { + * "id": "USER-1", + * "name": "H-One" + * } + * }, + * { + * "id": "ISSUE-2", + * "author": { + * "id": "USER-3", + * "name": "H-Three" + * } + * }, + * { + * "id": "ISSUE-3", + * "author": { + * "id": "USER-2", + * "name": "J-Two" + * } + * }, + * { + * "id": "ISSUE-4", + * "author": { + * "id": "USER-4", + * "name": "H-Four" + * } + * }, + * { + * "id": "ISSUE-5", + * "author": { + * "id": "USER-5", + * "name": "H-Five" + * } + * }, + * { + * "id": "ISSUE-6", + * "author": { + * "id": "USER-2", + * "name": "J-Two" + * } + * }, + * { + * "id": "ISSUE-7", + * "author": { + * "id": "USER-2", + * "name": "H-Two" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": { + | "id": "USER-1", + | "name": "H-One" + | } + | }, + | { + | "id": "ISSUE-2", + | "author": { + | "id": "USER-3", + | "name": "H-Three" + | } + | }, + | { + | "id": "ISSUE-3", + | "author": { + | "id": "USER-2", + | "name": "J-Two" + | } + | }, + | { + | "id": "ISSUE-4", + | "author": { + | "id": "USER-4", + | "name": "H-Four" + | } + | }, + | { + | "id": "ISSUE-5", + | "author": { + | "id": "USER-5", + | "name": "H-Five" + | } + | }, + | { + | "id": "ISSUE-6", + | "author": { + | "id": "USER-2", + | "name": "J-Two" + | } + | }, + | { + | "id": "ISSUE-7", + | "author": { + | "id": "USER-2", + | "name": "H-Two" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations and a deep rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations and a deep rename snapshot.kt new file mode 100644 index 000000000..a6f2f8290 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations and a deep rename snapshot.kt @@ -0,0 +1,273 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by uses same source for hydrations and a deep rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by uses same source for hydrations and a deep rename snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | details(detailIds: ["Foo-1", "Foo-2"]) { + | batch_hydration__detail__detailId: detailId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "details": [ + | { + | "name": "apple", + | "batch_hydration__detail__detailId": "Foo-1" + | }, + | { + | "name": "Foo 2 Electric Boogaloo", + | "batch_hydration__detail__detailId": "Foo-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | details(detailIds: ["Foo-3"]) { + | batch_hydration__detail__detailId: detailId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "details": [ + | { + | "name": "Three Apples", + | "batch_hydration__detail__detailId": "Foo-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foos { + | __typename__deep_rename__renamedField: __typename + | __typename__batch_hydration__issue: __typename + | __typename__batch_hydration__detail: __typename + | batch_hydration__issue__fooId: fooId + | batch_hydration__detail__fooId: fooId + | deep_rename__renamedField__issue: issue { + | field + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "deep_rename__renamedField__issue": { + | "field": "hmm-1" + | }, + | "__typename__deep_rename__renamedField": "Foo", + | "batch_hydration__issue__fooId": "Foo-1", + | "__typename__batch_hydration__issue": "Foo", + | "batch_hydration__detail__fooId": "Foo-1", + | "__typename__batch_hydration__detail": "Foo" + | }, + | { + | "deep_rename__renamedField__issue": { + | "field": "hmm-2" + | }, + | "__typename__deep_rename__renamedField": "Foo", + | "batch_hydration__issue__fooId": "Foo-2", + | "__typename__batch_hydration__issue": "Foo", + | "batch_hydration__detail__fooId": "Foo-2", + | "__typename__batch_hydration__detail": "Foo" + | }, + | { + | "deep_rename__renamedField__issue": { + | "field": "hmm-3" + | }, + | "__typename__deep_rename__renamedField": "Foo", + | "batch_hydration__issue__fooId": "Foo-3", + | "__typename__batch_hydration__issue": "Foo", + | "batch_hydration__detail__fooId": "Foo-3", + | "__typename__batch_hydration__detail": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issues(issueIds: ["Foo-1", "Foo-2"]) { + | field + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "field": "field_name", + | "batch_hydration__issue__issueId": "Foo-1" + | }, + | { + | "field": "field_name-2", + | "batch_hydration__issue__issueId": "Foo-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issues(issueIds: ["Foo-3"]) { + | field + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "field": "field-3", + | "batch_hydration__issue__issueId": "Foo-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "renamedField": "hmm-1", + * "issue": { + * "field": "field_name" + * }, + * "detail": { + * "name": "apple" + * } + * }, + * { + * "renamedField": "hmm-2", + * "issue": { + * "field": "field_name-2" + * }, + * "detail": { + * "name": "Foo 2 Electric Boogaloo" + * } + * }, + * { + * "renamedField": "hmm-3", + * "issue": { + * "field": "field-3" + * }, + * "detail": { + * "name": "Three Apples" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "renamedField": "hmm-1", + | "issue": { + | "field": "field_name" + | }, + | "detail": { + | "name": "apple" + | } + | }, + | { + | "renamedField": "hmm-2", + | "issue": { + | "field": "field_name-2" + | }, + | "detail": { + | "name": "Foo 2 Electric Boogaloo" + | } + | }, + | { + | "renamedField": "hmm-3", + | "issue": { + | "field": "field-3" + | }, + | "detail": { + | "name": "Three Apples" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations and a deep rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations and a deep rename.kt new file mode 100644 index 000000000..3d5ecd4d6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations and a deep rename.kt @@ -0,0 +1,133 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by uses same source for hydrations and a deep rename` : NadelLegacyIntegrationTest( + query = """ + query { + foos { + renamedField + issue { + field + } + detail { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foos: [Foo] + details(detailIds: [ID]): [Detail] + issues(issueIds: [ID]): [Issue] + } + type Foo { + renamedField: String @renamed(from: "issue.field") + issue: Issue @hydrated( + service: "Foo" + field: "issues" + arguments: [{name: "issueIds" value: "${'$'}source.fooId"}] + inputIdentifiedBy: [{sourceId: "fooId" resultId: "issueId"}] + batchSize: 2 + ) + detail: Detail @hydrated( + service: "Foo" + field: "details" + arguments: [{name: "detailIds" value: "${'$'}source.fooId"}] + inputIdentifiedBy: [{sourceId: "fooId" resultId: "detailId"}] + batchSize: 2 + ) + } + type Detail { + detailId: ID! + name: String + } + type Issue { + fooId: ID + field: String + } + """.trimIndent(), + underlyingSchema = """ + type Detail { + detailId: ID! + name: String + } + type Foo { + field: String + fooId: ID + issue: Issue + } + type Issue { + issueId: ID + field: String + fooId: ID + } + type Query { + details(detailIds: [ID]): [Detail] + foos: [Foo] + issues(issueIds: [ID]): [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + Foo_Issue(`field` = "field_name", issueId = "Foo-1"), + Foo_Issue(`field` = "field_name-2", issueId = "Foo-2"), + Foo_Issue(`field` = "field-3", issueId = "Foo-3"), + ).associateBy { it.issueId } + val detailsByIds = listOf( + Foo_Detail(detailId = "Foo-2", name = "Foo 2 Electric Boogaloo"), + Foo_Detail(detailId = "Foo-1", name = "apple"), + Foo_Detail(detailId = "Foo-3", name = "Three Apples"), + ).associateBy { it.detailId } + + type + .dataFetcher("foos") { env -> + listOf( + Foo_Foo( + fooId = "Foo-1", + issue = Foo_Issue(`field` = "hmm-1"), + ), + Foo_Foo( + fooId = "Foo-2", + issue = Foo_Issue(`field` = "hmm-2"), + ), + Foo_Foo( + fooId = "Foo-3", + issue = Foo_Issue(`field` = "hmm-3"), + ), + ) + } + .dataFetcher("issues") { env -> + env.getArgument>("issueIds")?.map(issuesByIds::get) + } + .dataFetcher("details") { env -> + env.getArgument>("detailIds")?.map(detailsByIds::get) + } + } + }, + ), + ), +) { + private data class Foo_Detail( + val detailId: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val `field`: String? = null, + val fooId: String? = null, + val issue: Foo_Issue? = null, + ) + + private data class Foo_Issue( + val issueId: String? = null, + val `field`: String? = null, + val fooId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations snapshot.kt new file mode 100644 index 000000000..4b941b037 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations snapshot.kt @@ -0,0 +1,250 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by uses same source for hydrations`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by uses same source for hydrations snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | details(detailIds: ["Foo-1", "Foo-2"]) { + | batch_hydration__detail__detailId: detailId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "details": [ + | { + | "name": "apple", + | "batch_hydration__detail__detailId": "Foo-1" + | }, + | { + | "name": "Foo 2 Electric Boogaloo", + | "batch_hydration__detail__detailId": "Foo-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | details(detailIds: ["Foo-3"]) { + | batch_hydration__detail__detailId: detailId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "details": [ + | { + | "name": "Three Apples", + | "batch_hydration__detail__detailId": "Foo-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foos { + | __typename__batch_hydration__issue: __typename + | __typename__batch_hydration__detail: __typename + | batch_hydration__issue__fooId: fooId + | batch_hydration__detail__fooId: fooId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "batch_hydration__issue__fooId": "Foo-1", + | "__typename__batch_hydration__issue": "Foo", + | "batch_hydration__detail__fooId": "Foo-1", + | "__typename__batch_hydration__detail": "Foo" + | }, + | { + | "batch_hydration__issue__fooId": "Foo-2", + | "__typename__batch_hydration__issue": "Foo", + | "batch_hydration__detail__fooId": "Foo-2", + | "__typename__batch_hydration__detail": "Foo" + | }, + | { + | "batch_hydration__issue__fooId": "Foo-3", + | "__typename__batch_hydration__issue": "Foo", + | "batch_hydration__detail__fooId": "Foo-3", + | "__typename__batch_hydration__detail": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issues(issueIds: ["Foo-1", "Foo-2"]) { + | field + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "field": "field_name", + | "batch_hydration__issue__issueId": "Foo-1" + | }, + | { + | "field": "field_name-2", + | "batch_hydration__issue__issueId": "Foo-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issues(issueIds: ["Foo-3"]) { + | field + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "field": "field-3", + | "batch_hydration__issue__issueId": "Foo-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "issue": { + * "field": "field_name" + * }, + * "detail": { + * "name": "apple" + * } + * }, + * { + * "issue": { + * "field": "field_name-2" + * }, + * "detail": { + * "name": "Foo 2 Electric Boogaloo" + * } + * }, + * { + * "issue": { + * "field": "field-3" + * }, + * "detail": { + * "name": "Three Apples" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "issue": { + | "field": "field_name" + | }, + | "detail": { + | "name": "apple" + | } + | }, + | { + | "issue": { + | "field": "field_name-2" + | }, + | "detail": { + | "name": "Foo 2 Electric Boogaloo" + | } + | }, + | { + | "issue": { + | "field": "field-3" + | }, + | "detail": { + | "name": "Three Apples" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations.kt new file mode 100644 index 000000000..ad044a76f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by uses same source for hydrations.kt @@ -0,0 +1,122 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by uses same source for hydrations` : NadelLegacyIntegrationTest( + query = """ + query { + foos { + issue { + field + } + detail { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foos: [Foo] + details(detailIds: [ID]): [Detail] + issues(issueIds: [ID]): [Issue] + } + type Foo { + issue: Issue @hydrated( + service: "Foo" + field: "issues" + arguments: [{name: "issueIds" value: "${'$'}source.fooId"}] + inputIdentifiedBy: [{sourceId: "fooId" resultId: "issueId"}] + batchSize: 2 + ) + detail: Detail @hydrated( + service: "Foo" + field: "details" + arguments: [{name: "detailIds" value: "${'$'}source.fooId"}] + inputIdentifiedBy: [{sourceId: "fooId" resultId: "detailId"}] + batchSize: 2 + ) + } + type Detail { + detailId: ID! + name: String + } + type Issue { + fooId: ID + field: String + } + """.trimIndent(), + underlyingSchema = """ + type Detail { + detailId: ID! + name: String + } + type Foo { + field: String + fooId: ID + issue: Issue + } + type Issue { + issueId: ID + field: String + fooId: ID + } + type Query { + details(detailIds: [ID]): [Detail] + foos: [Foo] + issues(issueIds: [ID]): [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + Foo_Issue(`field` = "field_name", issueId = "Foo-1"), + Foo_Issue(`field` = "field_name-2", issueId = "Foo-2"), + Foo_Issue(`field` = "field-3", issueId = "Foo-3"), + ).associateBy { it.issueId } + val detailsByIds = listOf( + Foo_Detail(detailId = "Foo-2", name = "Foo 2 Electric Boogaloo"), + Foo_Detail(detailId = "Foo-1", name = "apple"), + Foo_Detail(detailId = "Foo-3", name = "Three Apples"), + ).associateBy { it.detailId } + + type + .dataFetcher("foos") { env -> + listOf( + Foo_Foo(fooId = "Foo-1"), + Foo_Foo(fooId = "Foo-2"), + Foo_Foo(fooId = "Foo-3") + ) + } + .dataFetcher("issues") { env -> + env.getArgument>("issueIds")?.map(issuesByIds::get) + } + .dataFetcher("details") { env -> + env.getArgument>("detailIds")?.map(detailsByIds::get) + } + } + }, + ), + ), +) { + private data class Foo_Detail( + val detailId: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val `field`: String? = null, + val fooId: String? = null, + val issue: Foo_Issue? = null, + ) + + private data class Foo_Issue( + val issueId: String? = null, + val `field`: String? = null, + val fooId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with indexed hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with indexed hydration snapshot.kt new file mode 100644 index 000000000..ccf3daef0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with indexed hydration snapshot.kt @@ -0,0 +1,214 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by with indexed hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by with indexed hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Activity", + query = """ + | { + | activities { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__context: context { + | issueHydrationInput { + | id + | } + | } + | batch_hydration__issue__context: context { + | issueHydrationInput { + | site + | } + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activities": [ + | { + | "id": "ACTIVITY-0", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-0", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-1", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-1", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-2", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-2", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-3", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-3", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issue", + query = """ + | { + | issues(issuesInput: [{id : "ISSUE-0", site : "CLOUD-0"}, {id : "ISSUE-1", site : "CLOUD-0"}, {id : "ISSUE-2", site : "CLOUD-0"}, {id : "ISSUE-3", site : "CLOUD-0"}]) { + | description + | issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "issueId": "ISSUE-0", + | "description": "fix A" + | }, + | { + | "issueId": "ISSUE-1", + | "description": "fix B" + | }, + | { + | "issueId": "ISSUE-2", + | "description": "fix C" + | }, + | { + | "issueId": "ISSUE-3", + | "description": "fix D" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activities": [ + * { + * "id": "ACTIVITY-0", + * "issue": { + * "issueId": "ISSUE-0", + * "description": "fix A" + * } + * }, + * { + * "id": "ACTIVITY-1", + * "issue": { + * "issueId": "ISSUE-1", + * "description": "fix B" + * } + * }, + * { + * "id": "ACTIVITY-2", + * "issue": { + * "issueId": "ISSUE-2", + * "description": "fix C" + * } + * }, + * { + * "id": "ACTIVITY-3", + * "issue": { + * "issueId": "ISSUE-3", + * "description": "fix D" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activities": [ + | { + | "id": "ACTIVITY-0", + | "issue": { + | "issueId": "ISSUE-0", + | "description": "fix A" + | } + | }, + | { + | "id": "ACTIVITY-1", + | "issue": { + | "issueId": "ISSUE-1", + | "description": "fix B" + | } + | }, + | { + | "id": "ACTIVITY-2", + | "issue": { + | "issueId": "ISSUE-2", + | "description": "fix C" + | } + | }, + | { + | "id": "ACTIVITY-3", + | "issue": { + | "issueId": "ISSUE-3", + | "description": "fix D" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with indexed hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with indexed hydration.kt new file mode 100644 index 000000000..5fadbbc70 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with indexed hydration.kt @@ -0,0 +1,179 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by with indexed hydration` : NadelLegacyIntegrationTest( + query = """ + query { + activities { + id + issue { + issueId + description + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Activity", + overallSchema = """ + type Query { + activities: [Activity] + } + type Activity { + id: ID + issue: Issue @hydrated( + service: "Issue" + field: "issues" + arguments: [{name: "issuesInput" value: "${'$'}source.context.issueHydrationInput"}] + indexed: true + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activities: [Activity] + } + type Activity { + id: ID + context: HydrationContext + } + type HydrationContext { + issueHydrationInput: IssueHydrationInput + } + type IssueHydrationInput { + id: ID! + site: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activities") { env -> + listOf( + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-0", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-0", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-1", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-1", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-2", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-2", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-3", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-3", + ), + ) + } + } + }, + ), + Service( + name = "Issue", + overallSchema = """ + type Query { + issues(issuesInput: [IssueInput!]): [Issue] + } + type Issue { + issueId: ID + description: String + } + input IssueInput { + id: ID! + site: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues(issuesInput: [IssueInput!]): [Issue] + } + type Issue { + issueId: ID + description: String + } + input IssueInput { + id: ID! + site: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + if (env.getArgument("issuesInput") == + listOf( + mapOf("id" to "ISSUE-0", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-1", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-2", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-3", "site" to "CLOUD-0"), + ) + ) { + listOf( + Issue_Issue(description = "fix A", issueId = "ISSUE-0"), + Issue_Issue( + description = "fix B", + issueId = "ISSUE-1", + ), + Issue_Issue( + description = "fix C", + issueId = "ISSUE-2", + ), + Issue_Issue(description = "fix D", issueId = "ISSUE-3"), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val context: Activity_HydrationContext? = null, + ) + + private data class Activity_HydrationContext( + val issueHydrationInput: Activity_IssueHydrationInput? = null, + ) + + private data class Activity_IssueHydrationInput( + val id: String? = null, + val site: String? = null, + ) + + private data class Issue_Issue( + val issueId: String? = null, + val description: String? = null, + ) + + private data class Issue_IssueInput( + val id: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with list source id snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with list source id snapshot.kt new file mode 100644 index 000000000..94ff1e61b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with list source id snapshot.kt @@ -0,0 +1,280 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by with list source id`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by with list source id snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds { + | userId + | } + | batch_hydration__authors__authorIds: authorIds { + | site + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | { + | "userId": "USER-1", + | "site": "hello" + | }, + | { + | "userId": "USER-2", + | "site": "hello" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | { + | "userId": "USER-3", + | "site": "hello" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | { + | "userId": "USER-2", + | "site": "jdog" + | }, + | { + | "userId": "USER-4", + | "site": "hello" + | }, + | { + | "userId": "USER-5", + | "site": "hello" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users(id: [{site : "hello", userId : "USER-1"}, {site : "hello", userId : "USER-2"}, {site : "hello", userId : "USER-3"}]) { + | id + | batch_hydration__authors__id: id + | name + | batch_hydration__authors__siteId: siteId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-1", + | "name": "H-One", + | "batch_hydration__authors__id": "USER-1", + | "batch_hydration__authors__siteId": "hello" + | }, + | { + | "id": "USER-2", + | "name": "H-Two", + | "batch_hydration__authors__id": "USER-2", + | "batch_hydration__authors__siteId": "hello" + | }, + | { + | "id": "USER-3", + | "name": "H-Three", + | "batch_hydration__authors__id": "USER-3", + | "batch_hydration__authors__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users(id: [{site : "jdog", userId : "USER-2"}, {site : "hello", userId : "USER-4"}, {site : "hello", userId : "USER-5"}]) { + | id + | batch_hydration__authors__id: id + | name + | batch_hydration__authors__siteId: siteId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-2", + | "name": "J-Two", + | "batch_hydration__authors__id": "USER-2", + | "batch_hydration__authors__siteId": "jdog" + | }, + | { + | "id": "USER-4", + | "name": "H-Four", + | "batch_hydration__authors__id": "USER-4", + | "batch_hydration__authors__siteId": "hello" + | }, + | { + | "id": "USER-5", + | "name": "H-Five", + | "batch_hydration__authors__id": "USER-5", + | "batch_hydration__authors__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1", + * "name": "H-One" + * }, + * { + * "id": "USER-2", + * "name": "H-Two" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3", + * "name": "H-Three" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2", + * "name": "J-Two" + * }, + * { + * "id": "USER-4", + * "name": "H-Four" + * }, + * { + * "id": "USER-5", + * "name": "H-Five" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1", + | "name": "H-One" + | }, + | { + | "id": "USER-2", + | "name": "H-Two" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3", + | "name": "H-Three" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2", + | "name": "J-Two" + | }, + | { + | "id": "USER-4", + | "name": "H-Four" + | }, + | { + | "id": "USER-5", + | "name": "H-Five" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with list source id.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with list source id.kt new file mode 100644 index 000000000..2817417ad --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with list source id.kt @@ -0,0 +1,171 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by with list source id` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput { + userId: ID + site: String + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput { + userId: ID + site: String + } + type User { + id: ID + name: String + siteId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-1", "site" to "hello"), + mapOf("userId" to "USER-2", "site" to "hello"), + mapOf("userId" to "USER-3", "site" to "hello"), + ) + ) { + listOf( + UserService_User(id = "USER-1", name = "H-One", siteId = "hello"), + UserService_User(id = "USER-2", name = "H-Two", siteId = "hello"), + UserService_User(id = "USER-3", name = "H-Three", siteId = "hello"), + ) + } else if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-2", "site" to "jdog"), + mapOf("userId" to "USER-4", "site" to "hello"), + mapOf("userId" to "USER-5", "site" to "hello"), + ) + ) { + listOf( + UserService_User(id = "USER-2", name = "J-Two", siteId = "jdog"), + UserService_User(id = "USER-4", name = "H-Four", siteId = "hello"), + UserService_User(id = "USER-5", name = "H-Five", siteId = "hello"), + ) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] @hydrated( + service: "UserService" + field: "users" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + inputIdentifiedBy: [ + {sourceId: "authorIds.userId" resultId: "id"} + {sourceId: "authorIds.site" resultId: "siteId"} + ] + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues: [Issue] + } + type UserRef { + userId: ID + site: String + } + type Issue { + authorIds: [UserRef] + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorIds = listOf( + Issues_UserRef(userId = "USER-1", site = "hello"), + Issues_UserRef(userId = "USER-2", site = "hello"), + ), + id = "ISSUE-1", + ), + Issues_Issue( + authorIds = listOf(Issues_UserRef(userId = "USER-3", site = "hello")), + id = "ISSUE-2", + ), + Issues_Issue( + authorIds = listOf( + Issues_UserRef( + userId = "USER-2", + site = "jdog", + ), + Issues_UserRef(userId = "USER-4", site = "hello"), + Issues_UserRef( + userId = "USER-5", + site = "hello", + ), + ), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + val siteId: String? = null, + ) + + private data class UserService_UserInput( + val userId: String? = null, + val site: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) + + private data class Issues_UserRef( + val userId: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with rename snapshot.kt new file mode 100644 index 000000000..47a79ad50 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with rename snapshot.kt @@ -0,0 +1,348 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by with rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by with rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__author: __typename + | batch_hydration__author__authorId: authorId { + | userId + | } + | batch_hydration__author__authorId: authorId { + | site + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__author__authorId": { + | "userId": "USER-1", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__author__authorId": { + | "userId": "USER-3", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__author__authorId": { + | "userId": "USER-2", + | "site": "jdog" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-4", + | "batch_hydration__author__authorId": { + | "userId": "USER-4", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-5", + | "batch_hydration__author__authorId": { + | "userId": "USER-5", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-6", + | "batch_hydration__author__authorId": { + | "userId": "USER-2", + | "site": "jdog" + | }, + | "__typename__batch_hydration__author": "Issue" + | }, + | { + | "id": "ISSUE-7", + | "batch_hydration__author__authorId": { + | "userId": "USER-2", + | "site": "hello" + | }, + | "__typename__batch_hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | query (${'$'}v0: [UserInputUnderlying]) { + | users(id: ${'$'}v0) { + | id + | batch_hydration__author__id: id + | name + | batch_hydration__author__siteId: siteId + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": [ + | { + | "userId": "USER-1", + | "site": "hello" + | }, + | { + | "userId": "USER-3", + | "site": "hello" + | }, + | { + | "userId": "USER-2", + | "site": "jdog" + | }, + | { + | "userId": "USER-4", + | "site": "hello" + | } + | ] + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-1", + | "name": "H-One", + | "batch_hydration__author__id": "USER-1", + | "batch_hydration__author__siteId": "hello" + | }, + | { + | "id": "USER-3", + | "name": "H-Three", + | "batch_hydration__author__id": "USER-3", + | "batch_hydration__author__siteId": "hello" + | }, + | { + | "id": "USER-2", + | "name": "J-Two", + | "batch_hydration__author__id": "USER-2", + | "batch_hydration__author__siteId": "jdog" + | }, + | { + | "id": "USER-4", + | "name": "H-Four", + | "batch_hydration__author__id": "USER-4", + | "batch_hydration__author__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | query (${'$'}v0: [UserInputUnderlying]) { + | users(id: ${'$'}v0) { + | id + | batch_hydration__author__id: id + | name + | batch_hydration__author__siteId: siteId + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": [ + | { + | "userId": "USER-5", + | "site": "hello" + | }, + | { + | "userId": "USER-2", + | "site": "hello" + | } + | ] + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-5", + | "name": "H-Five", + | "batch_hydration__author__id": "USER-5", + | "batch_hydration__author__siteId": "hello" + | }, + | { + | "id": "USER-2", + | "name": "H-Two", + | "batch_hydration__author__id": "USER-2", + | "batch_hydration__author__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": { + * "id": "USER-1", + * "name": "H-One" + * } + * }, + * { + * "id": "ISSUE-2", + * "author": { + * "id": "USER-3", + * "name": "H-Three" + * } + * }, + * { + * "id": "ISSUE-3", + * "author": { + * "id": "USER-2", + * "name": "J-Two" + * } + * }, + * { + * "id": "ISSUE-4", + * "author": { + * "id": "USER-4", + * "name": "H-Four" + * } + * }, + * { + * "id": "ISSUE-5", + * "author": { + * "id": "USER-5", + * "name": "H-Five" + * } + * }, + * { + * "id": "ISSUE-6", + * "author": { + * "id": "USER-2", + * "name": "J-Two" + * } + * }, + * { + * "id": "ISSUE-7", + * "author": { + * "id": "USER-2", + * "name": "H-Two" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": { + | "id": "USER-1", + | "name": "H-One" + | } + | }, + | { + | "id": "ISSUE-2", + | "author": { + | "id": "USER-3", + | "name": "H-Three" + | } + | }, + | { + | "id": "ISSUE-3", + | "author": { + | "id": "USER-2", + | "name": "J-Two" + | } + | }, + | { + | "id": "ISSUE-4", + | "author": { + | "id": "USER-4", + | "name": "H-Four" + | } + | }, + | { + | "id": "ISSUE-5", + | "author": { + | "id": "USER-5", + | "name": "H-Five" + | } + | }, + | { + | "id": "ISSUE-6", + | "author": { + | "id": "USER-2", + | "name": "J-Two" + | } + | }, + | { + | "id": "ISSUE-7", + | "author": { + | "id": "USER-2", + | "name": "H-Two" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with rename.kt new file mode 100644 index 000000000..7b9eb15a8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with rename.kt @@ -0,0 +1,183 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by with rename` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput @renamed(from: "UserInputUnderlying") { + userId: ID + site: String + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users(id: [UserInputUnderlying]): [User] + } + input UserInputUnderlying { + userId: ID + site: String + } + type User { + id: ID + siteId: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-5", "site" to "hello"), + mapOf("userId" to "USER-2", "site" to "hello"), + ) + ) { + listOf( + UserService_User(id = "USER-5", name = "H-Five", siteId = "hello"), + UserService_User(id = "USER-2", name = "H-Two", siteId = "hello"), + ) + } else if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-1", "site" to "hello"), + mapOf("userId" to "USER-3", "site" to "hello"), + mapOf("userId" to "USER-2", "site" to "jdog"), + mapOf("userId" to "USER-4", "site" to "hello"), + ) + ) { + listOf( + UserService_User(id = "USER-1", name = "H-One", siteId = "hello"), + UserService_User(id = "USER-3", name = "H-Three", siteId = "hello"), + UserService_User(id = "USER-2", name = "J-Two", siteId = "jdog"), + UserService_User(id = "USER-4", name = "H-Four", siteId = "hello"), + ) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author: User @hydrated( + service: "UserService" + field: "users" + arguments: [{name: "id" value: "${'$'}source.authorId"}] + inputIdentifiedBy: [ + {sourceId: "authorId.userId" resultId: "id"} + {sourceId: "authorId.site" resultId: "siteId"} + ] + batchSize: 4 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues: [Issue] + } + type UserRef { + userId: ID + site: String + } + type Issue { + authorId: UserRef + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-1", site = "hello"), + id = "ISSUE-1", + ), + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-3", site = "hello"), + id = "ISSUE-2", + ), + Issues_Issue( + authorId = Issues_UserRef( + userId = "USER-2", + site = "jdog", + ), + id = "ISSUE-3", + ), + Issues_Issue( + authorId = Issues_UserRef( + userId = "USER-4", + site = "hello", + ), + id = "ISSUE-4", + ), + Issues_Issue( + authorId = Issues_UserRef( + userId = "USER-5", + site = "hello", + ), + id = "ISSUE-5", + ), + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-2", site = "jdog"), + id = "ISSUE-6", + ), + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-2", site = "hello"), + id = "ISSUE-7", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val siteId: String? = null, + val name: String? = null, + ) + + private data class UserService_UserInputUnderlying( + val userId: String? = null, + val site: String? = null, + ) + + private data class Issues_Issue( + val authorId: Issues_UserRef? = null, + val id: String? = null, + ) + + private data class Issues_UserRef( + val userId: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with some null source ids snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with some null source ids snapshot.kt new file mode 100644 index 000000000..49cdda1b3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with some null source ids snapshot.kt @@ -0,0 +1,246 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex identified by with some null source ids`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex identified by with some null source ids snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds { + | userId + | } + | batch_hydration__authors__authorIds: authorIds { + | site + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | null, + | { + | "userId": "USER-2", + | "site": "hello" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | { + | "userId": "USER-3", + | "site": "hello" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | { + | "userId": "USER-2", + | "site": "jdog" + | }, + | null, + | { + | "userId": "USER-5", + | "site": "hello" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users(id: [{site : "hello", userId : "USER-2"}, {site : "hello", userId : "USER-3"}, {site : "jdog", userId : "USER-2"}]) { + | id + | batch_hydration__authors__id: id + | name + | batch_hydration__authors__siteId: siteId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-2", + | "name": "H-Two", + | "batch_hydration__authors__id": "USER-2", + | "batch_hydration__authors__siteId": "hello" + | }, + | { + | "id": "USER-3", + | "name": "H-Three", + | "batch_hydration__authors__id": "USER-3", + | "batch_hydration__authors__siteId": "hello" + | }, + | { + | "id": "USER-2", + | "name": "J-Two", + | "batch_hydration__authors__id": "USER-2", + | "batch_hydration__authors__siteId": "jdog" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users(id: [{site : "hello", userId : "USER-5"}]) { + | id + | batch_hydration__authors__id: id + | name + | batch_hydration__authors__siteId: siteId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "id": "USER-5", + | "name": "H-Five", + | "batch_hydration__authors__id": "USER-5", + | "batch_hydration__authors__siteId": "hello" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-2", + * "name": "H-Two" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "USER-3", + * "name": "H-Three" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "USER-2", + * "name": "J-Two" + * }, + * { + * "id": "USER-5", + * "name": "H-Five" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-2", + | "name": "H-Two" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "USER-3", + | "name": "H-Three" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "USER-2", + | "name": "J-Two" + | }, + | { + | "id": "USER-5", + | "name": "H-Five" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with some null source ids.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with some null source ids.kt new file mode 100644 index 000000000..329c5f42e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by with some null source ids.kt @@ -0,0 +1,170 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by with some null source ids` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput { + userId: ID + site: String + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput { + userId: ID + site: String + } + type User { + id: ID + name: String + siteId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-2", "site" to "hello"), + mapOf("userId" to "USER-3", "site" to "hello"), + mapOf("userId" to "USER-2", "site" to "jdog"), + ) + ) { + listOf( + UserService_User(id = "USER-2", name = "H-Two", siteId = "hello"), + UserService_User(id = "USER-3", name = "H-Three", siteId = "hello"), + UserService_User(id = "USER-2", name = "J-Two", siteId = "jdog"), + ) + } else if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-5", "site" to "hello"), + ) + ) { + listOf(UserService_User(id = "USER-5", name = "H-Five", siteId = "hello")) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] @hydrated( + service: "UserService" + field: "users" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + inputIdentifiedBy: [ + {sourceId: "authorIds.userId" resultId: "id"} + {sourceId: "authorIds.site" resultId: "siteId"} + ] + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues: [Issue] + } + type UserRef { + userId: ID + site: String + } + type Issue { + authorIds: [UserRef] + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorIds = listOf( + null, + Issues_UserRef( + userId = "USER-2", + site = "hello", + ), + ), + id = "ISSUE-1", + ), + Issues_Issue( + authorIds = listOf( + Issues_UserRef( + userId = "USER-3", + site = "hello", + ), + ), + id = "ISSUE-2", + ), + Issues_Issue( + authorIds = listOf( + Issues_UserRef(userId = "USER-2", site = "jdog"), + null, + Issues_UserRef( + userId = "USER-5", + site = "hello", + ), + ), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + val siteId: String? = null, + ) + + private data class UserService_UserInput( + val userId: String? = null, + val site: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) + + private data class Issues_UserRef( + val userId: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by.kt new file mode 100644 index 000000000..7665dabc7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex identified by.kt @@ -0,0 +1,189 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex identified by` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput { + userId: ID + site: String + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users(id: [UserInput]): [User] + } + input UserInput { + userId: ID + site: String + } + type User { + id: ID + siteId: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + if (env.getArgument("id") == + listOf( + mapOf("userId" to "USER-5", "site" to "hello"), + mapOf("userId" to "USER-2", "site" to "hello"), + ) + ) { + listOf( + UserService_User(id = "USER-5", name = "H-Five", siteId = "hello"), + UserService_User(id = "USER-2", name = "H-Two", siteId = "hello"), + ) + } else if (env.getArgument("id") == + listOf( + mapOf( + "userId" to "USER-1", + "site" to "hello", + ), + mapOf("userId" to "USER-3", "site" to "hello"), + mapOf( + "userId" to "USER-2", + "site" to "jdog", + ), + mapOf("userId" to "USER-4", "site" to "hello"), + ) + ) { + listOf( + UserService_User(id = "USER-1", name = "H-One", siteId = "hello"), + UserService_User(id = "USER-3", name = "H-Three", siteId = "hello"), + UserService_User(id = "USER-2", name = "J-Two", siteId = "jdog"), + UserService_User(id = "USER-4", name = "H-Four", siteId = "hello"), + ) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author: User @hydrated( + service: "UserService" + field: "users" + arguments: [{name: "id" value: "${'$'}source.authorId"}] + inputIdentifiedBy: [ + {sourceId: "authorId.userId" resultId: "id"} + {sourceId: "authorId.site" resultId: "siteId"} + ] + batchSize: 4 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues: [Issue] + } + type UserRef { + userId: ID + site: String + } + type Issue { + authorId: UserRef + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-1", site = "hello"), + id = "ISSUE-1", + ), + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-3", site = "hello"), + id = "ISSUE-2", + ), + Issues_Issue( + authorId = Issues_UserRef( + userId = "USER-2", + site = "jdog", + ), + id = "ISSUE-3", + ), + Issues_Issue( + authorId = Issues_UserRef( + userId = "USER-4", + site = "hello", + ), + id = "ISSUE-4", + ), + Issues_Issue( + authorId = Issues_UserRef( + userId = "USER-5", + site = "hello", + ), + id = "ISSUE-5", + ), + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-2", site = "jdog"), + id = "ISSUE-6", + ), + Issues_Issue( + authorId = Issues_UserRef(userId = "USER-2", site = "hello"), + id = "ISSUE-7", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val siteId: String? = null, + val name: String? = null, + ) + + private data class UserService_UserInput( + val userId: String? = null, + val site: String? = null, + ) + + private data class Issues_Issue( + val authorId: Issues_UserRef? = null, + val id: String? = null, + ) + + private data class Issues_UserRef( + val userId: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex input object with indexed hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex input object with indexed hydration snapshot.kt new file mode 100644 index 000000000..714fd482a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex input object with indexed hydration snapshot.kt @@ -0,0 +1,214 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`complex input object with indexed hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `complex input object with indexed hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Activity", + query = """ + | { + | activities { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__context: context { + | issueHydrationInput { + | id + | } + | } + | batch_hydration__issue__context: context { + | issueHydrationInput { + | site + | } + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "activities": [ + | { + | "id": "ACTIVITY-0", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-0", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-1", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-1", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-2", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-2", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | }, + | { + | "id": "ACTIVITY-3", + | "batch_hydration__issue__context": { + | "issueHydrationInput": { + | "id": "ISSUE-3", + | "site": "CLOUD-0" + | } + | }, + | "__typename__batch_hydration__issue": "Activity" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issue", + query = """ + | { + | issues(issuesInput: [{id : "ISSUE-0", site : "CLOUD-0"}, {id : "ISSUE-1", site : "CLOUD-0"}, {id : "ISSUE-2", site : "CLOUD-0"}, {id : "ISSUE-3", site : "CLOUD-0"}]) { + | description + | issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "issueId": "ISSUE-0", + | "description": "fix A" + | }, + | { + | "issueId": "ISSUE-1", + | "description": "fix B" + | }, + | { + | "issueId": "ISSUE-2", + | "description": "fix C" + | }, + | { + | "issueId": "ISSUE-3", + | "description": "fix D" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "activities": [ + * { + * "id": "ACTIVITY-0", + * "issue": { + * "issueId": "ISSUE-0", + * "description": "fix A" + * } + * }, + * { + * "id": "ACTIVITY-1", + * "issue": { + * "issueId": "ISSUE-1", + * "description": "fix B" + * } + * }, + * { + * "id": "ACTIVITY-2", + * "issue": { + * "issueId": "ISSUE-2", + * "description": "fix C" + * } + * }, + * { + * "id": "ACTIVITY-3", + * "issue": { + * "issueId": "ISSUE-3", + * "description": "fix D" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "activities": [ + | { + | "id": "ACTIVITY-0", + | "issue": { + | "issueId": "ISSUE-0", + | "description": "fix A" + | } + | }, + | { + | "id": "ACTIVITY-1", + | "issue": { + | "issueId": "ISSUE-1", + | "description": "fix B" + | } + | }, + | { + | "id": "ACTIVITY-2", + | "issue": { + | "issueId": "ISSUE-2", + | "description": "fix C" + | } + | }, + | { + | "id": "ACTIVITY-3", + | "issue": { + | "issueId": "ISSUE-3", + | "description": "fix D" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex input object with indexed hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex input object with indexed hydration.kt new file mode 100644 index 000000000..071cecef6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/complex identified by/complex input object with indexed hydration.kt @@ -0,0 +1,173 @@ +package graphql.nadel.tests.legacy.`new hydration`.`complex identified by` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `complex input object with indexed hydration` : NadelLegacyIntegrationTest( + query = """ + query { + activities { + id + issue { + issueId + description + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Activity", + overallSchema = """ + type Query { + activities: [Activity] + } + type Activity { + id: ID + issue: Issue @hydrated( + service: "Issue" + field: "issues" + arguments: [{name: "issuesInput" value: "${'$'}source.context.issueHydrationInput"}] + indexed: true + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + activities: [Activity] + } + type Activity { + id: ID + context: HydrationContext + } + type HydrationContext { + issueHydrationInput: IssueHydrationInput + } + type IssueHydrationInput { + id: ID! + site: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("activities") { env -> + listOf( + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-0", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-0", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-1", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-1", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-2", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-2", + ), + Activity_Activity( + context = Activity_HydrationContext( + issueHydrationInput = Activity_IssueHydrationInput( + id = "ISSUE-3", + site = "CLOUD-0" + ), + ), + id = "ACTIVITY-3", + ), + ) + } + } + }, + ), + Service( + name = "Issue", + overallSchema = """ + type Query { + issues(issuesInput: [IssueInput!]): [Issue] + } + type Issue { + issueId: ID + description: String + } + input IssueInput { + id: ID! + site: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues(issuesInput: [IssueInput!]): [Issue] + } + type Issue { + issueId: ID + description: String + } + input IssueInput { + id: ID! + site: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + if (env.getArgument("issuesInput") == + listOf( + mapOf("id" to "ISSUE-0", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-1", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-2", "site" to "CLOUD-0"), + mapOf("id" to "ISSUE-3", "site" to "CLOUD-0"), + ) + ) { + listOf( + Issue_Issue(description = "fix A", issueId = "ISSUE-0"), + Issue_Issue(description = "fix B", issueId = "ISSUE-1"), + Issue_Issue(description = "fix C", issueId = "ISSUE-2"), + Issue_Issue(description = "fix D", issueId = "ISSUE-3"), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Activity_Activity( + val id: String? = null, + val context: Activity_HydrationContext? = null, + ) + + private data class Activity_HydrationContext( + val issueHydrationInput: Activity_IssueHydrationInput? = null, + ) + + private data class Activity_IssueHydrationInput( + val id: String? = null, + val site: String? = null, + ) + + private data class Issue_Issue( + val issueId: String? = null, + val description: String? = null, + ) + + private data class Issue_IssueInput( + val id: String? = null, + val site: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration equals predicate works with integer type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration equals predicate works with integer type snapshot.kt new file mode 100644 index 000000000..514665b55 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration equals predicate works with integer type snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`conditional hydration equals predicate works with integer type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `conditional hydration equals predicate works with integer type snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": 2, + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "BAR_B") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar B" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar B" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar B" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration equals predicate works with integer type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration equals predicate works with integer type.kt new file mode 100644 index 000000000..ecbbb7283 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration equals predicate works with integer type.kt @@ -0,0 +1,139 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `conditional hydration equals predicate works with integer type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: Int + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: Int + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "BAR_B") { + Service2_Bar(name = "Bar B") + } else { + null + } + } + } + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: Int + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: 1 } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: 2 } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: Int + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = 2) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: Int? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration matches predicate works with id type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration matches predicate works with id type snapshot.kt new file mode 100644 index 000000000..549f7eb06 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration matches predicate works with id type snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`conditional hydration matches predicate works with id type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `conditional hydration matches predicate works with id type snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": "type_B", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "BAR_B") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar B" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar B" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar B" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration matches predicate works with id type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration matches predicate works with id type.kt new file mode 100644 index 000000000..8f412b0ef --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration matches predicate works with id type.kt @@ -0,0 +1,139 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `conditional hydration matches predicate works with id type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: ID + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: ID + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "BAR_B") { + Service2_Bar(name = "Bar B") + } else { + null + } + } + } + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: ID + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "nope" } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "[a-z]+_B"} + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = "type_B") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration startsWith predicate works with id type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration startsWith predicate works with id type snapshot.kt new file mode 100644 index 000000000..6744b272e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration startsWith predicate works with id type snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`conditional hydration startsWith predicate works with id type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `conditional hydration startsWith predicate works with id type snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": "type_B", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "BAR_B") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar B" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar B" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar B" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration startsWith predicate works with id type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration startsWith predicate works with id type.kt new file mode 100644 index 000000000..315e1e95a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/conditional hydration startsWith predicate works with id type.kt @@ -0,0 +1,139 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `conditional hydration startsWith predicate works with id type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: ID + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: ID + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "BAR_B") { + Service2_Bar(name = "Bar B") + } else { + null + } + } + } + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: ID + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "nope" } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "type" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = "type_B") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to hydration snapshot.kt new file mode 100644 index 000000000..9c7093581 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to hydration snapshot.kt @@ -0,0 +1,187 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`expecting one child error on extensive field argument passed to hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `expecting one child error on extensive field argument passed to hydration snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "TestBoard", + query = """ + | { + | board(id: 1) { + | __typename__rename__cardChildren: __typename + | id + | rename__cardChildren__issueChildren: issueChildren { + | __typename__batch_hydration__assignee: __typename + | id + | batch_hydration__assignee__issue: issue { + | assignee { + | accountId + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "board": { + | "id": "1", + | "rename__cardChildren__issueChildren": [ + | { + | "id": "a1", + | "batch_hydration__assignee__issue": { + | "assignee": { + | "accountId": "1" + | } + | }, + | "__typename__batch_hydration__assignee": "Card" + | }, + | { + | "id": "a2", + | "batch_hydration__assignee__issue": { + | "assignee": { + | "accountId": "2" + | } + | }, + | "__typename__batch_hydration__assignee": "Card" + | }, + | { + | "id": "a3", + | "batch_hydration__assignee__issue": { + | "assignee": { + | "accountId": "3" + | } + | }, + | "__typename__batch_hydration__assignee": "Card" + | } + | ], + | "__typename__rename__cardChildren": "Board" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Users", + query = """ + | { + | users(accountIds: ["1", "2", "3"]) { + | accountId + | batch_hydration__assignee__accountId: accountId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "accountId": "1", + | "batch_hydration__assignee__accountId": "1" + | }, + | { + | "accountId": "2", + | "batch_hydration__assignee__accountId": "2" + | }, + | { + | "accountId": "3", + | "batch_hydration__assignee__accountId": "3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "board": { + * "id": "1", + * "cardChildren": [ + * { + * "id": "a1", + * "assignee": { + * "accountId": "1" + * } + * }, + * { + * "id": "a2", + * "assignee": { + * "accountId": "2" + * } + * }, + * { + * "id": "a3", + * "assignee": { + * "accountId": "3" + * } + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "board": { + | "id": "1", + | "cardChildren": [ + | { + | "id": "a1", + | "assignee": { + | "accountId": "1" + | } + | }, + | { + | "id": "a2", + | "assignee": { + | "accountId": "2" + | } + | }, + | { + | "id": "a3", + | "assignee": { + | "accountId": "3" + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to hydration.kt new file mode 100644 index 000000000..ccaec3857 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to hydration.kt @@ -0,0 +1,149 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `expecting one child error on extensive field argument passed to hydration` : NadelLegacyIntegrationTest( + query = """ + query { + board(id: 1) { + id + cardChildren { + id + assignee { + accountId + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "TestBoard", + overallSchema = """ + type Query { + board(id: ID): SoftwareBoard + } + type SoftwareBoard @renamed(from: "Board") { + id: ID + cardChildren: [SoftwareCard] @renamed(from: "issueChildren") + } + type SoftwareCard @renamed(from: "Card") { + id: ID + assignee: User + @hydrated( + service: "Users" + field: "users" + arguments: [{name: "accountIds" value: "${'$'}source.issue.assignee.accountId"}] + identifiedBy: "accountId" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Board { + id: ID + issueChildren: [Card] + } + type Card { + id: ID + issue: Issue + } + type Issue { + assignee: TestUser + id: ID + } + type Query { + board(id: ID): Board + } + type TestUser { + accountId: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("board") { env -> + if (env.getArgument("id") == "1") { + TestBoard_Board( + id = "1", + issueChildren = listOf( + TestBoard_Card( + id = "a1", + issue = TestBoard_Issue(assignee = TestBoard_TestUser(accountId = "1")), + ), + TestBoard_Card( + id = "a2", + issue = TestBoard_Issue(assignee = TestBoard_TestUser(accountId = "2")), + ), + TestBoard_Card( + id = "a3", + issue = TestBoard_Issue( + assignee = TestBoard_TestUser(accountId = "3"), + ), + ), + ), + ) + } else { + null + } + } + } + }, + ), + Service( + name = "Users", + overallSchema = """ + type Query { + users(accountIds: [ID]): [User] + } + type User { + accountId: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users(accountIds: [ID]): [User] + } + type User { + accountId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersById = listOf( + Users_User(accountId = "1"), + Users_User(accountId = "2"), + Users_User(accountId = "3"), + ).associateBy { it.accountId } + + type.dataFetcher("users") { env -> + env.getArgument>("accountIds")?.map(usersById::get) + } + } + }, + ), + ), +) { + private data class TestBoard_Board( + val id: String? = null, + val issueChildren: List? = null, + ) + + private data class TestBoard_Card( + val id: String? = null, + val issue: TestBoard_Issue? = null, + ) + + private data class TestBoard_Issue( + val assignee: TestBoard_TestUser? = null, + val id: String? = null, + ) + + private data class TestBoard_TestUser( + val accountId: String? = null, + ) + + private data class Users_User( + val accountId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to synthetic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to synthetic hydration snapshot.kt new file mode 100644 index 000000000..d1a1510e8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to synthetic hydration snapshot.kt @@ -0,0 +1,182 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`expecting one child error on extensive field argument passed to synthetic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `expecting one child error on extensive field argument passed to synthetic hydration snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "TestBoard", + query = """ + | { + | board(id: 1) { + | __typename__rename__cardChildren: __typename + | id + | rename__cardChildren__issueChildren: issueChildren { + | __typename__batch_hydration__assignee: __typename + | batch_hydration__assignee__issue: issue { + | assignee { + | accountId + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "board": { + | "id": "1", + | "rename__cardChildren__issueChildren": [ + | { + | "batch_hydration__assignee__issue": { + | "assignee": { + | "accountId": "1" + | } + | }, + | "__typename__batch_hydration__assignee": "Card" + | }, + | { + | "batch_hydration__assignee__issue": { + | "assignee": { + | "accountId": "2" + | } + | }, + | "__typename__batch_hydration__assignee": "Card" + | }, + | { + | "batch_hydration__assignee__issue": { + | "assignee": { + | "accountId": "3" + | } + | }, + | "__typename__batch_hydration__assignee": "Card" + | } + | ], + | "__typename__rename__cardChildren": "Board" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Users", + query = """ + | { + | usersQuery { + | users(accountIds: ["1", "2", "3"]) { + | accountId + | batch_hydration__assignee__accountId: accountId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersQuery": { + | "users": [ + | { + | "accountId": "1", + | "batch_hydration__assignee__accountId": "1" + | }, + | { + | "accountId": "2", + | "batch_hydration__assignee__accountId": "2" + | }, + | { + | "accountId": "3", + | "batch_hydration__assignee__accountId": "3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "board": { + * "id": "1", + * "cardChildren": [ + * { + * "assignee": { + * "accountId": "1" + * } + * }, + * { + * "assignee": { + * "accountId": "2" + * } + * }, + * { + * "assignee": { + * "accountId": "3" + * } + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "board": { + | "id": "1", + | "cardChildren": [ + | { + | "assignee": { + | "accountId": "1" + | } + | }, + | { + | "assignee": { + | "accountId": "2" + | } + | }, + | { + | "assignee": { + | "accountId": "3" + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to synthetic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to synthetic hydration.kt new file mode 100644 index 000000000..b3de8ba1a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/expecting one child error on extensive field argument passed to synthetic hydration.kt @@ -0,0 +1,165 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `expecting one child error on extensive field argument passed to synthetic hydration` : + NadelLegacyIntegrationTest( + query = """ + query { + board(id: 1) { + id + cardChildren { + assignee { + accountId + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "TestBoard", + overallSchema = """ + type Query { + board(id: ID): SoftwareBoard + } + type SoftwareBoard @renamed(from: "Board") { + id: ID + cardChildren: [SoftwareCard] @renamed(from: "issueChildren") + } + type SoftwareCard @renamed(from: "Card") { + id: ID + assignee: User + @hydrated( + service: "Users" + field: "usersQuery.users" + arguments: [{name: "accountIds" value: "${'$'}source.issue.assignee.accountId"}] + identifiedBy: "accountId" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Board { + id: ID + issueChildren: [Card] + } + type Card { + id: ID + issue: Issue + } + type Issue { + assignee: TestUser + id: ID + } + type Query { + board(id: ID): Board + } + type TestUser { + accountId: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("board") { env -> + if (env.getArgument("id") == "1") { + TestBoard_Board( + id = "1", + issueChildren = listOf( + TestBoard_Card( + issue = TestBoard_Issue(assignee = TestBoard_TestUser(accountId = "1")), + ), + TestBoard_Card( + issue = TestBoard_Issue( + assignee = TestBoard_TestUser( + accountId = "2", + ), + ), + ), + TestBoard_Card( + issue = TestBoard_Issue( + assignee = TestBoard_TestUser(accountId = "3"), + ), + ), + ), + ) + } else { + null + } + } + } + }, + ), + Service( + name = "Users", + overallSchema = """ + type Query { + usersQuery: UserQuery + } + type UserQuery { + users(accountIds: [ID]): [User] + } + type User { + accountId: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersQuery: UserQuery + } + type User { + accountId: ID + } + type UserQuery { + users(accountIds: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("usersQuery") { + Unit + } + } + wiring.type("UserQuery") { type -> + val usersById = listOf( + Users_User(accountId = "1"), + Users_User(accountId = "2"), + Users_User(accountId = "3"), + ).associateBy { it.accountId } + + type.dataFetcher("users") { env -> + env.getArgument>("accountIds")?.map(usersById::get) + } + } + }, + ), + ), + ) { + private data class TestBoard_Board( + val id: String? = null, + val issueChildren: List? = null, + ) + + private data class TestBoard_Card( + val id: String? = null, + val issue: TestBoard_Issue? = null, + ) + + private data class TestBoard_Issue( + val assignee: TestBoard_TestUser? = null, + val id: String? = null, + ) + + private data class TestBoard_TestUser( + val accountId: String? = null, + ) + + private data class Users_User( + val accountId: String? = null, + ) + + private data class Users_UserQuery( + val users: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration batching returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration batching returns null snapshot.kt new file mode 100644 index 000000000..f0f9e31f8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration batching returns null snapshot.kt @@ -0,0 +1,107 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration batching returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration batching returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration batching returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration batching returns null.kt new file mode 100644 index 000000000..79b08aefb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration batching returns null.kt @@ -0,0 +1,89 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration batching returns null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsById") { env -> + null + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call forwards error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call forwards error snapshot.kt new file mode 100644 index 000000000..c870216e0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call forwards error snapshot.kt @@ -0,0 +1,154 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration call forwards error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration call forwards error snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId1", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId1") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Some error with extension occurred", + | "locations": [], + | "path": [ + | "barById", + | "name" + | ], + | "extensions": { + | "classification": "SomeCustomError" + | } + | } + | ], + | "data": { + | "barById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Some error occurred", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * }, + * { + * "message": "Some error with extension occurred", + * "locations": [], + * "path": [ + * "barById", + * "name" + * ], + * "extensions": { + * "classification": "SomeCustomError" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | }, + | { + | "message": "Some error with extension occurred", + | "locations": [], + | "path": [ + | "barById", + | "name" + | ], + | "extensions": { + | "classification": "SomeCustomError" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call forwards error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call forwards error.kt new file mode 100644 index 000000000..78ef2c32c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call forwards error.kt @@ -0,0 +1,113 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration call forwards error` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId1") { + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Some error occurred", + ), + ), + toGraphQLError( + mapOf( + "message" to "Some error with extension occurred", + "path" to listOf("barById", "name"), + "extensions" to mapOf("classification" to "SomeCustomError"), + ), + ), + ), + ).build() + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId1") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call over itself with renamed types snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call over itself with renamed types snapshot.kt new file mode 100644 index 000000000..b1838fd85 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call over itself with renamed types snapshot.kt @@ -0,0 +1,201 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration call over itself with renamed types`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration call over itself with renamed types snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "testing", + query = """ + | { + | characters(ids: ["C1", "C2", "C3"]) { + | id + | batch_hydration__characters__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "characters": [ + | { + | "id": "C1", + | "name": "Luke", + | "batch_hydration__characters__id": "C1" + | }, + | { + | "id": "C2", + | "name": "Leia", + | "batch_hydration__characters__id": "C2" + | }, + | { + | "id": "C3", + | "name": "Anakin", + | "batch_hydration__characters__id": "C3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "testing", + query = """ + | { + | testing { + | movies { + | __typename__batch_hydration__characters: __typename + | batch_hydration__characters__characterIds: characterIds + | id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "testing": { + | "movies": [ + | { + | "id": "M1", + | "name": "Movie 1", + | "batch_hydration__characters__characterIds": [ + | "C1", + | "C2" + | ], + | "__typename__batch_hydration__characters": "Movie" + | }, + | { + | "id": "M2", + | "name": "Movie 2", + | "batch_hydration__characters__characterIds": [ + | "C1", + | "C2", + | "C3" + | ], + | "__typename__batch_hydration__characters": "Movie" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "testing": { + * "movies": [ + * { + * "id": "M1", + * "name": "Movie 1", + * "characters": [ + * { + * "id": "C1", + * "name": "Luke" + * }, + * { + * "id": "C2", + * "name": "Leia" + * } + * ] + * }, + * { + * "id": "M2", + * "name": "Movie 2", + * "characters": [ + * { + * "id": "C1", + * "name": "Luke" + * }, + * { + * "id": "C2", + * "name": "Leia" + * }, + * { + * "id": "C3", + * "name": "Anakin" + * } + * ] + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "testing": { + | "movies": [ + | { + | "id": "M1", + | "name": "Movie 1", + | "characters": [ + | { + | "id": "C1", + | "name": "Luke" + | }, + | { + | "id": "C2", + | "name": "Leia" + | } + | ] + | }, + | { + | "id": "M2", + | "name": "Movie 2", + | "characters": [ + | { + | "id": "C1", + | "name": "Luke" + | }, + | { + | "id": "C2", + | "name": "Leia" + | }, + | { + | "id": "C3", + | "name": "Anakin" + | } + | ] + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call over itself with renamed types.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call over itself with renamed types.kt new file mode 100644 index 000000000..c18cd6911 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call over itself with renamed types.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration call over itself with renamed types` : NadelLegacyIntegrationTest( + query = """ + query { + testing { + movies { + id + name + characters { + id + name + } + ...F1 + } + } + } + fragment F1 on TestingMovie { + name + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "testing", + overallSchema = """ + type Query { + testing: Testing + characters(ids: [ID!]!): [TestingCharacter] + } + type Testing { + movies: [TestingMovie] + } + type TestingCharacter @renamed(from: "Character") { + id: ID! + name: String + } + type TestingMovie @renamed(from: "Movie") { + id: ID! + name: String + characters: [TestingCharacter] + @hydrated( + service: "testing" + field: "characters" + arguments: [{name: "ids" value: "${'$'}source.characterIds"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Character { + id: ID! + name: String + } + type Movie { + characterIds: [ID] + id: ID! + name: String + } + type Query { + characters(ids: [ID!]!): [Character] + testing: Testing + } + type Testing { + movies: [Movie] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val charactersById = listOf( + Testing_Character(id = "C1", name = "Luke"), + Testing_Character(id = "C2", name = "Leia"), + Testing_Character(id = "C3", name = "Anakin"), + ).associateBy { it.id } + + type + .dataFetcher("testing") { env -> + Testing_Testing( + movies = listOf( + Testing_Movie( + characterIds = listOf("C1", "C2"), + id = "M1", + name = "Movie 1", + ), + Testing_Movie( + characterIds = listOf("C1", "C2", "C3"), + id = "M2", + name = "Movie 2", + ), + ), + ) + } + .dataFetcher("characters") { env -> + env.getArgument>("ids")?.map(charactersById::get) + } + } + }, + ), + ), +) { + private data class Testing_Character( + val id: String? = null, + val name: String? = null, + ) + + private data class Testing_Movie( + val characterIds: List? = null, + val id: String? = null, + val name: String? = null, + ) + + private data class Testing_Testing( + val movies: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with argument value from original field argument snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with argument value from original field argument snapshot.kt new file mode 100644 index 000000000..abc200093 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with argument value from original field argument snapshot.kt @@ -0,0 +1,115 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration call with argument value from original field argument`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration call with argument value from original field argument snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__author: __typename + | batch_hydration__author__authorId: authorId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__author__authorId": "USER-1", + | "__typename__batch_hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(extraArg: "extraArg", id: ["USER-1"]) { + | batch_hydration__author__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "User 1", + | "batch_hydration__author__id": "USER-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": { + * "name": "User 1" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": { + | "name": "User 1" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with argument value from original field argument.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with argument value from original field argument.kt new file mode 100644 index 000000000..4ea440584 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with argument value from original field argument.kt @@ -0,0 +1,102 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration call with argument value from original field argument` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author(extraArg: "extraArg") { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(extraArg: String, id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(extraArg: String, id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1", name = "User 1"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("extraArg") == "extraArg") { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author(extraArg: String): User @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "extraArg" value: "${'$'}argument.extraArg"} + {name: "id" value: "${'$'}source.authorId"} + ] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorId: ID + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorId = "USER-1", id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part and synthetic field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part and synthetic field snapshot.kt new file mode 100644 index 000000000..acb687d37 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part and synthetic field snapshot.kt @@ -0,0 +1,195 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration call with fragments in the hydrated part and synthetic field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration call with fragments in the hydrated part and synthetic field snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorDetails: authorDetails { + | authorId + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorDetails": [ + | { + | "authorId": "USER-1" + | }, + | { + | "authorId": "USER-2" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | userQuery { + | usersByIds(id: ["USER-1", "USER-2"]) { + | id + | batch_hydration__authors__id: id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "userQuery": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "name": "User 1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "name": "User 2", + | "batch_hydration__authors__id": "USER-2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | userQuery { + | usersByIds(id: ["USER-1"]) { + | id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "userQuery": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "name": "User 1" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1", + * "name": "User 1" + * }, + * { + * "id": "USER-2", + * "name": "User 2" + * } + * ] + * } + * ], + * "userQuery": { + * "usersByIds": [ + * { + * "id": "USER-1", + * "name": "User 1" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1", + | "name": "User 1" + | }, + | { + | "id": "USER-2", + | "name": "User 2" + | } + | ] + | } + | ], + | "userQuery": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "name": "User 1" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part and synthetic field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part and synthetic field.kt new file mode 100644 index 000000000..475baf8c8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part and synthetic field.kt @@ -0,0 +1,150 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration call with fragments in the hydrated part and synthetic field` : NadelLegacyIntegrationTest( + query = """ + fragment IssueFragment on Issue { + id + } + query { + issues { + ...IssueFragment + id + authors { + id + ...UserFragment1 + } + } + userQuery { + usersByIds(id: ["USER-1"]) { + ...UserFragment1 + } + } + } + fragment UserFragment1 on User { + id + name + ...UserFragment2 + } + fragment UserFragment2 on User { + name + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + userQuery: UserQuery + } + type UserQuery { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userQuery: UserQuery + } + type User { + id: ID + name: String + } + type UserQuery { + usersByIds(id: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("userQuery") { + Unit + } + } + wiring.type("UserQuery") { type -> + val usersById = listOf( + UserService_User(id = "USER-1", name = "User 1"), + UserService_User(id = "USER-2", name = "User 2"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersById::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authorDetails: [AuthorDetail] + authors: [User] + @hydrated( + service: "UserService" + field: "userQuery.usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorDetails.authorId"}] + identifiedBy: "id" + ) + } + type AuthorDetail { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type AuthorDetail { + authorId: ID + name: String + } + type Issue { + authorDetails: [AuthorDetail] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorDetails = listOf( + Issues_AuthorDetail(authorId = "USER-1"), + Issues_AuthorDetail(authorId = "USER-2"), + ), + id = "ISSUE-1", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class UserService_UserQuery( + val usersByIds: List? = null, + ) + + private data class Issues_AuthorDetail( + val authorId: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorDetails: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part snapshot.kt new file mode 100644 index 000000000..e062d88d0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part snapshot.kt @@ -0,0 +1,182 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration call with fragments in the hydrated part`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration call with fragments in the hydrated part snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorDetails: authorDetails { + | authorId + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorDetails": [ + | { + | "authorId": "USER-1" + | }, + | { + | "authorId": "USER-2" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2"]) { + | id + | batch_hydration__authors__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "name": "User 1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "id": "USER-2", + | "name": "User 2", + | "batch_hydration__authors__id": "USER-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1"]) { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "USER-1", + | "name": "User 1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "USER-1", + * "name": "User 1" + * }, + * { + * "id": "USER-2", + * "name": "User 2" + * } + * ] + * } + * ], + * "usersByIds": [ + * { + * "id": "USER-1", + * "name": "User 1" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "USER-1", + | "name": "User 1" + | }, + | { + | "id": "USER-2", + | "name": "User 2" + | } + | ] + | } + | ], + | "usersByIds": [ + | { + | "id": "USER-1", + | "name": "User 1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part.kt new file mode 100644 index 000000000..1b6c025f9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with fragments in the hydrated part.kt @@ -0,0 +1,134 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration call with fragments in the hydrated part` : NadelLegacyIntegrationTest( + query = """ + fragment IssueFragment on Issue { + id + } + query { + issues { + ...IssueFragment + id + authors { + id + ...UserFragment1 + } + } + usersByIds(id: ["USER-1"]) { + ...UserFragment1 + } + } + fragment UserFragment1 on User { + id + name + ...UserFragment2 + } + fragment UserFragment2 on User { + name + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersById = listOf( + UserService_User(id = "USER-1", name = "User 1"), + UserService_User(id = "USER-2", name = "User 2"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersById::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authorDetails: [AuthorDetail] + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorDetails.authorId"}] + identifiedBy: "id" + batchSize: 2 + ) + } + type AuthorDetail { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type AuthorDetail { + authorId: ID + name: String + } + type Issue { + authorDetails: [AuthorDetail] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authorDetails = listOf( + Issues_AuthorDetail(authorId = "USER-1"), + Issues_AuthorDetail(authorId = "USER-2"), + ), + id = "ISSUE-1", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_AuthorDetail( + val authorId: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorDetails: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with two argument values from original field arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with two argument values from original field arguments snapshot.kt new file mode 100644 index 000000000..88f824922 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with two argument values from original field arguments snapshot.kt @@ -0,0 +1,115 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration call with two argument values from original field arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration call with two argument values from original field arguments snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__author: __typename + | batch_hydration__author__authorId: authorId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__author__authorId": "USER-1", + | "__typename__batch_hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(extraArg1: "extraArg1", extraArg2: 10, id: ["USER-1"]) { + | batch_hydration__author__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "User 1", + | "batch_hydration__author__id": "USER-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": { + * "name": "User 1" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": { + | "name": "User 1" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with two argument values from original field arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with two argument values from original field arguments.kt new file mode 100644 index 000000000..99269ae43 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration call with two argument values from original field arguments.kt @@ -0,0 +1,103 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration call with two argument values from original field arguments` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author(extraArg1: "extraArg1", extraArg2: 10) { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(extraArg1: String, extraArg2: Int, id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(extraArg1: String, extraArg2: Int, id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1", name = "User 1"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("extraArg1") == "extraArg1" && env.getArgument("extraArg2") == 10) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author(extraArg1: String, extraArg2: Int): User @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [ + {name: "extraArg1" value: "${'$'}argument.extraArg1"} + {name: "extraArg2" value: "${'$'}argument.extraArg2"} + {name: "id" value: "${'$'}source.authorId"} + ] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorId: ID + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorId = "USER-1", id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface snapshot.kt new file mode 100644 index 000000000..94e72a46e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration from field in interface`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration from field in interface snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issue(id: "1") { + | __typename__hydration__issueAuthor: __typename + | hydration__issueAuthor__author: author { + | userId + | } + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "title": "Issue 1", + | "hydration__issueAuthor__author": { + | "userId": "1001" + | }, + | "__typename__hydration__issueAuthor": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | user(id: "1001") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "user": { + | "name": "McUser Face" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "title": "Issue 1", + * "issueAuthor": { + * "name": "McUser Face" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "title": "Issue 1", + | "issueAuthor": { + | "name": "McUser Face" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface with type rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface with type rename snapshot.kt new file mode 100644 index 000000000..09d646733 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface with type rename snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration from field in interface with type rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration from field in interface with type rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issue(id: "1") { + | __typename__hydration__issueAuthor: __typename + | hydration__issueAuthor__author: author { + | userId + | } + | title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "title": "Issue 1", + | "hydration__issueAuthor__author": { + | "userId": "1001" + | }, + | "__typename__hydration__issueAuthor": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "users", + query = """ + | { + | user(id: "1001") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "user": { + | "name": "McUser Face" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "title": "Issue 1", + * "issueAuthor": { + * "name": "McUser Face" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "title": "Issue 1", + | "issueAuthor": { + | "name": "McUser Face" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface with type rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface with type rename.kt new file mode 100644 index 000000000..d009a8451 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface with type rename.kt @@ -0,0 +1,124 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration from field in interface with type rename` : NadelLegacyIntegrationTest( + query = """ + query { + issue(id: "1") { + title + issueAuthor { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "issues", + overallSchema = """ + type Query { + issue(id: ID): RenamedIssue + } + type RenamedIssue @renamed(from: "Issue") { + id: ID + title: String + issueAuthor: RenamedUser + @hydrated( + service: "users" + field: "user" + arguments: [{name: "id" value: "${'$'}source.author.userId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID! + title: String + author: User + } + interface User { + userId: ID! + } + type ProductUser implements User { + userId: ID! + email: String + } + type Query { + issue(id: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "1") { + Issues_Issue(author = Issues_ProductUser(userId = "1001"), title = "Issue 1") + } else { + null + } + } + } + wiring.type("User") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + user(id: ID!): RenamedUser + } + type RenamedUser @renamed(from: "User") { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type User { + id: ID! + name: String + } + type Query { + user(id: ID!): User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("user") { env -> + if (env.getArgument("id") == "1001") { + Users_User(name = "McUser Face") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + val author: Issues_User? = null, + ) + + private data class Issues_ProductUser( + override val userId: String? = null, + val email: String? = null, + ) : Issues_User + + private interface Issues_User { + val userId: String? + } + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface.kt new file mode 100644 index 000000000..bbe828633 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration from field in interface.kt @@ -0,0 +1,124 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration from field in interface` : NadelLegacyIntegrationTest( + query = """ + query { + issue(id: "1") { + title + issueAuthor { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "issues", + overallSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID + title: String + issueAuthor: User + @hydrated( + service: "users" + field: "user" + arguments: [{name: "id" value: "${'$'}source.author.userId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID! + title: String + author: User + } + interface User { + userId: ID! + } + type ProductUser implements User { + userId: ID! + email: String + } + type Query { + issue(id: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "1") { + Issues_Issue(author = Issues_ProductUser(userId = "1001"), title = "Issue 1") + } else { + null + } + } + } + wiring.type("User") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "users", + overallSchema = """ + type Query { + user(id: ID!): User + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type User { + id: ID! + name: String + } + type Query { + user(id: ID!): User + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("user") { env -> + if (env.getArgument("id") == "1001") { + Users_User(name = "McUser Face") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val title: String? = null, + val author: Issues_User? = null, + ) + + private data class Issues_ProductUser( + override val userId: String? = null, + val email: String? = null, + ) : Issues_User + + private interface Issues_User { + val userId: String? + } + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is absent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is absent snapshot.kt new file mode 100644 index 000000000..b2b230e9b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is absent snapshot.kt @@ -0,0 +1,86 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration input is absent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration input is absent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__hydration__authors: __typename + | hydration__authors__authors: authors { + | id + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "hydration__authors__authors": [], + | "__typename__hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is absent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is absent.kt new file mode 100644 index 000000000..2724ec0ed --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is absent.kt @@ -0,0 +1,93 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration input is absent` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] @hydrated( + service: "UserService" + field: "userById" + arguments: [ + {name: "id" value: "${'$'}source.authors.id"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID! + authors: [AuthorRef] + } + type AuthorRef { + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authors = listOf(), id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_AuthorRef( + val id: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val authors: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is empty list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is empty list snapshot.kt new file mode 100644 index 000000000..41f886da0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is empty list snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration input is empty list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration input is empty list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__hydration__author: __typename + | hydration__author__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "hydration__author__authorIds": null, + | "__typename__hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": [] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": [] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is empty list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is empty list.kt new file mode 100644 index 000000000..9b5dd55e9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is empty list.kt @@ -0,0 +1,86 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration input is empty list` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author: [User] @hydrated( + service: "UserService" + field: "userById" + arguments: [ + {name: "id" value: "${'$'}source.authorIds"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID! + authorIds: [ID] + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorIds = null, id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val authorIds: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is null snapshot.kt new file mode 100644 index 000000000..9950065b7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is null snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration input is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration input is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__hydration__author: __typename + | hydration__author__authorId: authorId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "hydration__author__authorId": null, + | "__typename__hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": null + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": null + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is null.kt new file mode 100644 index 000000000..717ff1b5b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration input is null.kt @@ -0,0 +1,86 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration input is null` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + userById(id: ID!): User + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author: User @hydrated( + service: "UserService" + field: "userById" + arguments: [ + {name: "id" value: "${'$'}source.authorId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID! + authorId: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorId = null, id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val authorId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration inside a renamed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration inside a renamed field snapshot.kt new file mode 100644 index 000000000..b4414c084 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration inside a renamed field snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration inside a renamed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration inside a renamed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barById(id: "hydrated-bar") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "hydrated-bar" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | rename__foo__fooOriginal: fooOriginal { + | __typename__hydration__fooBar: __typename + | hydration__fooBar__fooBarId: fooBarId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__foo__fooOriginal": { + | "id": "Foo", + | "hydration__fooBar__fooBarId": "hydrated-bar", + | "__typename__hydration__fooBar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "id": "Foo", + * "fooBar": { + * "id": "hydrated-bar" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "id": "Foo", + | "fooBar": { + | "id": "hydrated-bar" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration inside a renamed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration inside a renamed field.kt new file mode 100644 index 000000000..b759d2982 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration inside a renamed field.kt @@ -0,0 +1,91 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration inside a renamed field` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + id + fooBar { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + barById(id: ID!): RenamedBar + } + type RenamedBar @renamed(from: "Bar") { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID! + } + type Query { + barById(id: ID!): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "hydrated-bar") { + Bar_Bar(id = "hydrated-bar") + } else { + null + } + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo @renamed(from: "fooOriginal") + } + type Foo { + id: ID! + fooBar: RenamedBar + @hydrated( + service: "Bar" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + fooBarId: ID + id: ID! + } + type Query { + fooOriginal: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("fooOriginal") { env -> + Foo_Foo(fooBarId = "hydrated-bar", id = "Foo") + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val id: String? = null, + ) + + private data class Foo_Foo( + val fooBarId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list input snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list input snapshot.kt new file mode 100644 index 000000000..8cb1d6a34 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list input snapshot.kt @@ -0,0 +1,176 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration list input`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration list input snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barIds: barIds + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barIds": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId1") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "barId1", + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId2") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "barId2", + | "name": "Bar3" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId3") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "barId3", + | "name": "Bar4" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "id": "barId1", + * "name": "Bar1" + * }, + * { + * "id": "barId2", + * "name": "Bar3" + * }, + * { + * "id": "barId3", + * "name": "Bar4" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "id": "barId1", + | "name": "Bar1" + | }, + | { + | "id": "barId2", + | "name": "Bar3" + | }, + | { + | "id": "barId3", + | "name": "Bar4" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list input.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list input.kt new file mode 100644 index 000000000..b534b43e9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list input.kt @@ -0,0 +1,98 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration list input` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId1") { + Service2_Bar(id = "barId1", name = "Bar1") + } else if (env.getArgument("id") == "barId3") { + Service2_Bar(id = "barId3", name = "Bar4") + } else if (env.getArgument("id") == "barId2") { + Service2_Bar(id = "barId2", name = "Bar3") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barIds"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barIds: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barIds = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching forwards error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching forwards error snapshot.kt new file mode 100644 index 000000000..4ed2b56f0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching forwards error snapshot.kt @@ -0,0 +1,134 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration list with batching forwards error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration list with batching forwards error snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "barsById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Some error occurred", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": [ + * null, + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": [ + | null, + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching forwards error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching forwards error.kt new file mode 100644 index 000000000..567338b9d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching forwards error.kt @@ -0,0 +1,102 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration list with batching forwards error` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsById") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Some error occurred", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching snapshot.kt new file mode 100644 index 000000000..a65b30ef5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration list with batching`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration list with batching snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar1", + | "batch_hydration__bar__id": "barId1" + | }, + | { + | "name": "Bar2", + | "batch_hydration__bar__id": "barId2" + | }, + | { + | "name": "Bar3", + | "batch_hydration__bar__id": "barId3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "name": "Bar1" + * }, + * { + * "name": "Bar2" + * }, + * { + * "name": "Bar3" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "name": "Bar1" + | }, + | { + | "name": "Bar2" + | }, + | { + | "name": "Bar3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching.kt new file mode 100644 index 000000000..17f948759 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with batching.kt @@ -0,0 +1,96 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration list with batching` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Service2_Bar(id = "barId1", name = "Bar1"), + Service2_Bar(id = "barId2", name = "Bar2"), + Service2_Bar(id = "barId3", name = "Bar3"), + ).associateBy { it.id } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.map(barsById::get) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with one element snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with one element snapshot.kt new file mode 100644 index 000000000..1ac4827b7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with one element snapshot.kt @@ -0,0 +1,110 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration list with one element`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration list with one element snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": [ + | "barId1" + | ], + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId1") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "barId1", + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * { + * "id": "barId1", + * "name": "Bar1" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | { + | "id": "barId1", + | "name": "Bar1" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with one element.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with one element.kt new file mode 100644 index 000000000..8476e97ce --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration list with one element.kt @@ -0,0 +1,94 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration list with one element` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId1") { + Service2_Bar(id = "barId1", name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces asking typename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces asking typename snapshot.kt new file mode 100644 index 000000000..9d4da6fd4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces asking typename snapshot.kt @@ -0,0 +1,131 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration with interfaces asking typename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration with interfaces asking typename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | ariById(id: "ari:i-always-forget-the-format/1") + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "ariById": "Definitely an ARI" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | __typename + | ... on Issue { + | id + | } + | ... on User { + | __typename__hydration__id: __typename + | hydration__id__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "Issue", + | "id": "GQLGW-001" + | }, + | { + | "__typename": "Issue", + | "id": "GQLGW-1102" + | }, + | { + | "__typename": "User", + | "hydration__id__id": "ari:i-always-forget-the-format/1", + | "__typename__hydration__id": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "__typename": "JiraIssue", + * "id": "GQLGW-001" + * }, + * { + * "__typename": "JiraIssue", + * "id": "GQLGW-1102" + * }, + * { + * "__typename": "User", + * "id": "Definitely an ARI" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "JiraIssue", + | "id": "GQLGW-001" + | }, + | { + | "__typename": "JiraIssue", + | "id": "GQLGW-1102" + | }, + | { + | "__typename": "User", + | "id": "Definitely an ARI" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces asking typename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces asking typename.kt new file mode 100644 index 000000000..f5babcdd2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces asking typename.kt @@ -0,0 +1,97 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration with interfaces asking typename` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + __typename + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + ariById(id: ID!): ID + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID + } + interface Node { + id: ID + } + type User implements Node { + id: ID + @hydrated( + service: "Issues" + field: "ariById" + arguments: [{name: "id" value: "${'$'}source.id"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + ariById(id: ID!): ID + nodes: [Node] + } + interface Node { + id: ID + } + type Issue implements Node { + id: ID + } + type User implements Node { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("nodes") { env -> + listOf( + Issues_Issue(id = "GQLGW-001"), + Issues_Issue(id = "GQLGW-1102"), + Issues_User( + id = "ari:i-always-forget-the-format/1", + ), + ) + } + .dataFetcher("ariById") { env -> + if (env.getArgument("id") == "ari:i-always-forget-the-format/1") { + "Definitely an ARI" + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_User( + override val id: String? = null, + val name: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces no source id snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces no source id snapshot.kt new file mode 100644 index 000000000..5ed32bdda --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces no source id snapshot.kt @@ -0,0 +1,93 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration with interfaces no source id`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration with interfaces no source id snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | ... on Issue { + | id + | } + | ... on User { + | __typename__hydration__id: __typename + | hydration__id__ari: ari + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "id": "GQLGW-001" + * }, + * { + * "id": "GQLGW-1102" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces no source id.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces no source id.kt new file mode 100644 index 000000000..8759fb0aa --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces no source id.kt @@ -0,0 +1,84 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration with interfaces no source id` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + idByAri(id: ID!): ID + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID + } + interface Node { + id: ID + } + type User implements Node { + id: ID + @hydrated( + service: "Issues" + field: "idByAri" + arguments: [{name: "id" value: "${'$'}source.ari"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + idByAri(id: ID!): ID + } + interface Node { + id: ID + } + type Issue implements Node { + id: ID + } + type User implements Node { + id: ID + ari: ID! + name: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("nodes") { env -> + listOf(Issues_Issue(id = "GQLGW-001"), Issues_Issue(id = "GQLGW-1102")) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_User( + override val id: String? = null, + val ari: String? = null, + val name: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces snapshot.kt new file mode 100644 index 000000000..4dcbd3dcb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces snapshot.kt @@ -0,0 +1,121 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration with interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration with interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | idByAri(id: "ari:i-always-forget-the-format/1") + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "idByAri": "Hello World" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | ... on Issue { + | id + | } + | ... on User { + | __typename__hydration__id: __typename + | hydration__id__ari: ari + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "hydration__id__ari": "ari:i-always-forget-the-format/1", + | "__typename__hydration__id": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "id": "GQLGW-001" + * }, + * { + * "id": "GQLGW-1102" + * }, + * { + * "id": "Hello World" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "id": "Hello World" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces.kt new file mode 100644 index 000000000..c48564817 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with interfaces.kt @@ -0,0 +1,98 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration with interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + idByAri(id: ID!): ID + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID + } + interface Node { + id: ID + } + type User implements Node { + id: ID + @hydrated( + service: "Issues" + field: "idByAri" + arguments: [{name: "id" value: "${'$'}source.ari"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + idByAri(id: ID!): ID + } + interface Node { + id: ID + } + type Issue implements Node { + id: ID + } + type User implements Node { + id: ID + ari: ID! + name: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("nodes") { env -> + listOf( + Issues_Issue(id = "GQLGW-001"), + Issues_Issue(id = "GQLGW-1102"), + Issues_User( + ari = "ari:i-always-forget-the-format/1", + ), + ) + } + .dataFetcher("idByAri") { env -> + if (env.getArgument("id") == "ari:i-always-forget-the-format/1") { + "Hello World" + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_User( + override val id: String? = null, + val ari: String? = null, + val name: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with more interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with more interfaces snapshot.kt new file mode 100644 index 000000000..02edcdf85 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with more interfaces snapshot.kt @@ -0,0 +1,162 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration with more interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration with more interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | ariById(id: "Franklin") + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "ariById": "ari:user/Franklin" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | ... on Issue { + | id + | } + | ... on Troll { + | __typename__hydration__id: __typename + | hydration__id__id: id + | } + | ... on User { + | __typename__hydration__id: __typename + | hydration__id__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "hydration__id__id": "My Arm", + | "__typename__hydration__id": "Troll" + | }, + | { + | "hydration__id__id": "Franklin", + | "__typename__hydration__id": "User" + | }, + | { + | "id": "GQLGW-11" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | trollName(id: "My Arm") + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "trollName": "Troll" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "id": "GQLGW-001" + * }, + * { + * "id": "GQLGW-1102" + * }, + * { + * "id": "Troll" + * }, + * { + * "id": "ari:user/Franklin" + * }, + * { + * "id": "GQLGW-11" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "id": "Troll" + | }, + | { + | "id": "ari:user/Franklin" + | }, + | { + | "id": "GQLGW-11" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with more interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with more interfaces.kt new file mode 100644 index 000000000..04b21b75b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with more interfaces.kt @@ -0,0 +1,124 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration with more interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + trollName(id: ID!): String + ariById(id: ID!): ID + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID + } + type Troll implements Node { + id: ID + @hydrated( + service: "Issues" + field: "trollName" + arguments: [{name: "id" value: "${'$'}source.id"}] + ) + } + interface Node { + id: ID + } + type User implements Node { + id: ID + @hydrated( + service: "Issues" + field: "ariById" + arguments: [{name: "id" value: "${'$'}source.id"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + trollName(id: ID!): String + ariById(id: ID!): ID + nodes: [Node] + } + interface Node { + id: ID + } + type Troll implements Node { + id: ID + nameOfFirstThingEaten: String + } + type Issue implements Node { + id: ID + } + type User implements Node { + id: ID + ari: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("nodes") { env -> + listOf( + Issues_Issue(id = "GQLGW-001"), + Issues_Issue(id = "GQLGW-1102"), + Issues_Troll( + id = "My Arm", + ), + Issues_User(id = "Franklin"), + Issues_Issue(id = "GQLGW-11"), + ) + } + .dataFetcher("trollName") { env -> + if (env.getArgument("id") == "My Arm") { + "Troll" + } else { + null + } + } + .dataFetcher("ariById") { env -> + if (env.getArgument("id") == "Franklin") { + "ari:user/Franklin" + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_Troll( + override val id: String? = null, + val nameOfFirstThingEaten: String? = null, + ) : Issues_Node + + private data class Issues_User( + override val id: String? = null, + val ari: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple conditions ignores false conditions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple conditions ignores false conditions snapshot.kt new file mode 100644 index 000000000..28a894a91 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple conditions ignores false conditions snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration with multiple conditions ignores false conditions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration with multiple conditions ignores false conditions snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": "type_B", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "BAR_B") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar B" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar B" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar B" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple conditions ignores false conditions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple conditions ignores false conditions.kt new file mode 100644 index 000000000..525ebd096 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple conditions ignores false conditions.kt @@ -0,0 +1,139 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration with multiple conditions ignores false conditions` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "BAR_B") { + Service2_Bar(name = "Bar B") + } else { + null + } + } + } + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "type_A" } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "type_B" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = "type_B") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple true conditions takes first snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple true conditions takes first snapshot.kt new file mode 100644 index 000000000..8664de4b7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple true conditions takes first snapshot.kt @@ -0,0 +1,101 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration with multiple true conditions takes first`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration with multiple true conditions takes first snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": "type_B", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "BAR_A") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar A" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar A" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar A" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple true conditions takes first.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple true conditions takes first.kt new file mode 100644 index 000000000..da79e62b7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration with multiple true conditions takes first.kt @@ -0,0 +1,139 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration with multiple true conditions takes first` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "BAR_A") { + Service2_Bar(name = "Bar A") + } else { + null + } + } + } + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "type" } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "type_B" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = "type_B") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration within hydration with variables snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration within hydration with variables snapshot.kt new file mode 100644 index 000000000..0857e6691 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration within hydration with variables snapshot.kt @@ -0,0 +1,128 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration within hydration with variables`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration within hydration with variables snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "boards", + query = """ + | { + | board { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "board": { + | "hydration__issue__issueId": "ISSUE-1", + | "__typename__hydration__issue": "Board" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "comments", + query = """ + | { + | comments(cloudId: "CLOUD_ID-1", first: 10) { + | totalCount + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "comments": { + | "totalCount": 10 + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issue(id: "ISSUE-1") { + | __typename__hydration__comments: __typename + | hydration__comments__cloudId: cloudId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__comments__cloudId": "CLOUD_ID-1", + | "__typename__hydration__comments": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "board": { + * "issue": { + * "comments": { + * "totalCount": 10 + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "board": { + | "issue": { + | "comments": { + | "totalCount": 10 + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration within hydration with variables.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration within hydration with variables.kt new file mode 100644 index 000000000..4f56941d8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration within hydration with variables.kt @@ -0,0 +1,144 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration within hydration with variables` : NadelLegacyIntegrationTest( + query = """ + query(${'$'}first: Int) { + board { + issue { + comments(first: ${'$'}first) { + totalCount + } + } + } + } + """.trimIndent(), + variables = mapOf("first" to 10), + services = listOf( + Service( + name = "boards", + overallSchema = """ + type Query { + board: Board + } + type Board { + id: ID + title: String + issue: Issue + @hydrated( + service: "issues" + field: "issue" + arguments: [{name: "id" value: "${'$'}source.issueId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + board: Board + } + type Board { + id: ID + title: String + issueId: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("board") { env -> + Boards_Board(issueId = "ISSUE-1") + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issue(id: ID!): Issue + } + type Issue { + id: ID! + cloudId: ID! + comments(first: Int = 20): CommentConnection + @hydrated( + service: "comments" + field: "comments" + arguments: [ + {name: "cloudId" value: "${'$'}source.cloudId"} + {name: "first" value: "${'$'}argument.first"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue(id: ID!): Issue + } + type Issue { + id: ID! + cloudId: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "ISSUE-1") { + Issues_Issue(cloudId = "CLOUD_ID-1") + } else { + null + } + } + } + }, + ), + Service( + name = "comments", + overallSchema = """ + type Query { + comments(cloudId: ID!, first: Int): CommentConnection + } + type CommentConnection { + totalCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + comments(cloudId: ID!, first: Int): CommentConnection + } + type CommentConnection { + totalCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("comments") { env -> + if (env.getArgument("cloudId") == "CLOUD_ID-1" && + env.getArgument("first") == + 10 + ) { + Comments_CommentConnection(totalCount = 10) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Boards_Board( + val id: String? = null, + val title: String? = null, + val issueId: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val cloudId: String? = null, + ) + + private data class Comments_CommentConnection( + val totalCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when an ancestor field has been renamed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when an ancestor field has been renamed snapshot.kt new file mode 100644 index 000000000..c965c906b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when an ancestor field has been renamed snapshot.kt @@ -0,0 +1,114 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration works when an ancestor field has been renamed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration works when an ancestor field has been renamed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issue(id: "1") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "id": "1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | rename__devOpsRelationships__relationships: relationships { + | nodes { + | __typename__hydration__devOpsIssue: __typename + | hydration__devOpsIssue__issueId: issueId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__devOpsRelationships__relationships": { + | "nodes": [ + | { + | "hydration__devOpsIssue__issueId": "1", + | "__typename__hydration__devOpsIssue": "Relationship" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "devOpsRelationships": { + * "nodes": [ + * { + * "devOpsIssue": { + * "id": "1" + * } + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "devOpsRelationships": { + | "nodes": [ + | { + | "devOpsIssue": { + | "id": "1" + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when an ancestor field has been renamed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when an ancestor field has been renamed.kt new file mode 100644 index 000000000..b13f11596 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when an ancestor field has been renamed.kt @@ -0,0 +1,92 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration works when an ancestor field has been renamed` : NadelLegacyIntegrationTest( + query = """ + query { + devOpsRelationships { + nodes { + devOpsIssue { + id + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type DevOpsIssue @renamed(from: "Issue") { + id: ID + } + type DevOpsRelationship @renamed(from: "Relationship") { + devOpsIssue: DevOpsIssue + @hydrated( + service: "IssueService" + field: "issue" + arguments: [{name: "id" value: "${'$'}source.issueId"}] + ) + } + type DevOpsRelationshipConnection @renamed(from: "RelationshipConnection") { + nodes: [DevOpsRelationship] + } + type Query { + devOpsRelationships: DevOpsRelationshipConnection @renamed(from: "relationships") + devOpsIssue(id: ID): DevOpsIssue @renamed(from: "issue") + issue(id: ID): DevOpsIssue @hidden + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + issue(id: ID): Issue + relationships: RelationshipConnection + } + type Relationship { + issueId: ID + } + type RelationshipConnection { + nodes: [Relationship] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("relationships") { env -> + IssueService_RelationshipConnection( + nodes = listOf( + IssueService_Relationship( + issueId = "1", + ), + ), + ) + } + .dataFetcher("issue") { env -> + if (env.getArgument("id") == "1") { + IssueService_Issue(id = "1") + } else { + null + } + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + ) + + private data class IssueService_Relationship( + val issueId: String? = null, + ) + + private data class IssueService_RelationshipConnection( + val nodes: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when equals condition field is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when equals condition field is null snapshot.kt new file mode 100644 index 000000000..8acc6dcb6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when equals condition field is null snapshot.kt @@ -0,0 +1,75 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration works when equals condition field is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration works when equals condition field is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": null, + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when equals condition field is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when equals condition field is null.kt new file mode 100644 index 000000000..484f50093 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when equals condition field is null.kt @@ -0,0 +1,130 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration works when equals condition field is null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "type_A" } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: "type_B" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = null) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when matches condition field is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when matches condition field is null snapshot.kt new file mode 100644 index 000000000..d0173f161 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when matches condition field is null snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration works when matches condition field is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration works when matches condition field is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": null, + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when matches condition field is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when matches condition field is null.kt new file mode 100644 index 000000000..05ad56f3f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when matches condition field is null.kt @@ -0,0 +1,114 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration works when matches condition field is null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { matches: "type*" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = null) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when startswith condition field is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when startswith condition field is null snapshot.kt new file mode 100644 index 000000000..f8c8b0564 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when startswith condition field is null snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration works when startswith condition field is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration works when startswith condition field is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": null, + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when startswith condition field is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when startswith condition field is null.kt new file mode 100644 index 000000000..9aa0d4a05 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/hydration works when startswith condition field is null.kt @@ -0,0 +1,114 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration works when startswith condition field is null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: String + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: String + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { startsWith: "type" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(type = null) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration all null ids snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration all null ids snapshot.kt new file mode 100644 index 000000000..e346506f3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration all null ids snapshot.kt @@ -0,0 +1,81 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`index hydration all null ids`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `index hydration all null ids snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issueById(id: "10000") { + | __typename__batch_hydration__collaborators: __typename + | batch_hydration__collaborators__collaboratorIds: collaboratorIds + | key + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "key": "GQLGW-1000", + | "batch_hydration__collaborators__collaboratorIds": [ + | null, + | null + | ], + | "__typename__batch_hydration__collaborators": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issueById": { + * "key": "GQLGW-1000", + * "collaborators": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issueById": { + | "key": "GQLGW-1000", + | "collaborators": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration all null ids.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration all null ids.kt new file mode 100644 index 000000000..70da17819 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration all null ids.kt @@ -0,0 +1,97 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `index hydration all null ids` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "10000") { + key + collaborators { + __typename + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issueById(id: ID!): Issue! + } + type Issue { + id: ID! + key: String + collaborators: [User] + @hydrated( + service: "Users" + field: "usersByIds" + arguments: [ + {name: "ids", value: "${'$'}source.collaboratorIds"} + ] + identifiedBy: "id" + indexed: true + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID!): Issue! + } + type Issue { + id: ID! + key: String + collaboratorIds: [ID] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "10000") { + Issues_Issue(collaboratorIds = listOf(null, null), key = "GQLGW-1000") + } else { + null + } + } + } + }, + ), + Service( + name = "Users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val key: String? = null, + val collaboratorIds: List? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration with partitioned inputs snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration with partitioned inputs snapshot.kt new file mode 100644 index 000000000..9c96ec3ba --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration with partitioned inputs snapshot.kt @@ -0,0 +1,232 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`index hydration with partitioned inputs`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `index hydration with partitioned inputs snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "site-1/user-1", + | "site-2/user-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "site-1/user-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "site-2/user-4", + | "site-1/user-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["site-1/user-1", "site-1/user-3"]) { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "site-1/user-1" + | }, + | { + | "id": "site-1/user-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["site-1/user-5"]) { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "site-1/user-5" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["site-2/user-2", "site-2/user-4"]) { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "id": "site-2/user-2" + | }, + | { + | "id": "site-2/user-4" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "id": "site-1/user-1" + * }, + * { + * "id": "site-2/user-2" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "id": "site-1/user-3" + * } + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * { + * "id": "site-2/user-4" + * }, + * { + * "id": "site-1/user-5" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "id": "site-1/user-1" + | }, + | { + | "id": "site-2/user-2" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "id": "site-1/user-3" + | } + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | { + | "id": "site-2/user-4" + | }, + | { + | "id": "site-1/user-5" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration with partitioned inputs.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration with partitioned inputs.kt new file mode 100644 index 000000000..9185f1190 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index hydration with partitioned inputs.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `index hydration with partitioned inputs` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersById = listOf( + UserService_User(id = "site-1/user-1"), + UserService_User(id = "site-1/user-3"), + UserService_User(id = "site-1/user-5"), + UserService_User(id = "site-2/user-2"), + UserService_User(id = "site-2/user-4"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + val ids = env.getArgument>("id") + if (ids != null) { + val uniqueCloudIds = ids.mapTo(mutableSetOf()) { it.substringBefore("/") } + if (uniqueCloudIds.size > 1) { + throw IllegalArgumentException("Cannot query multiple cloud IDs at once") + } + } + ids?.map(usersById::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 2 + indexed: true + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("site-1/user-1", "site-2/user-2"), id = "ISSUE-1"), + Issues_Issue(authorIds = listOf("site-1/user-3"), id = "ISSUE-2"), + Issues_Issue(authorIds = listOf("site-2/user-4", "site-1/user-5"), id = "ISSUE-3"), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index one batch returns errors snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index one batch returns errors snapshot.kt new file mode 100644 index 000000000..1bcb78380 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index one batch returns errors snapshot.kt @@ -0,0 +1,214 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index one batch returns errors`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index one batch returns errors snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "1" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "1", + | "2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "2", + | "4" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["1", "2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "User-1" + | }, + | null + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["4"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Fail", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "usersByIds": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Fail", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "User-1" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "name": "User-1" + * }, + * null + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * null, + * null + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Fail", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "User-1" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "name": "User-1" + | }, + | null + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | null, + | null + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index one batch returns errors.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index one batch returns errors.kt new file mode 100644 index 000000000..d52cd571d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index one batch returns errors.kt @@ -0,0 +1,127 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index one batch returns errors` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User( + id = "1", + name = "User-1", + ), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + val ids = env.getArgument>("ids") + if (ids?.contains("4") == true) { + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Fail", + ), + ), + ), + ).build() + } else { + ids?.map(usersByIds::get) + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf("1", "2"), + id = "ISSUE-2", + ), + Issues_Issue( + authorIds = listOf("2", "4"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index result size invariant mismatch snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index result size invariant mismatch snapshot.kt new file mode 100644 index 000000000..7270bb9de --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index result size invariant mismatch snapshot.kt @@ -0,0 +1,92 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index result size invariant mismatch`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +class `hydration matching using index result size invariant mismatch snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + query { + issues { + __typename__batch_hydration__authors: __typename + batch_hydration__authors__authorIds: authorIds + id + } + } + """.trimIndent(), + variables = "{}", + result = """ + { + "data": { + "issues": [ + { + "__typename__batch_hydration__authors": "Issue", + "batch_hydration__authors__authorIds": [ + "1" + ], + "id": "ISSUE-1" + }, + { + "__typename__batch_hydration__authors": "Issue", + "batch_hydration__authors__authorIds": [ + "1", + "2" + ], + "id": "ISSUE-2" + } + ] + } + } + """.trimIndent(), + delayedResults = listOfJsonStrings(), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + query { + usersByIds(ids: ["1", "2"]) { + name + } + } + """.trimIndent(), + variables = "{}", + result = """ + { + "data": { + "usersByIds": [ + { + "name": "Name" + } + ] + } + } + """.trimIndent(), + delayedResults = listOfJsonStrings(), + ), + ) + + /** + * ```json + * {} + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = "{}", + delayedResults = listOfJsonStrings(), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index result size invariant mismatch.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index result size invariant mismatch.kt new file mode 100644 index 000000000..8bff145b4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index result size invariant mismatch.kt @@ -0,0 +1,105 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index result size invariant mismatch` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "1", name = "Name") + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.mapNotNull(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf("1", "2"), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) + + override fun assertFailure(e: Exception): Boolean = e.message == + "If you use indexed hydration then you MUST follow a contract where the resolved nodes matches the size of the input arguments" +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning errors snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning errors snapshot.kt new file mode 100644 index 000000000..2582c38c4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning errors snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index returning errors`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index returning errors snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "1" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "1", + | "2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["1", "2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * null + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * null, + * null + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | null + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | null, + | null + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning errors.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning errors.kt new file mode 100644 index 000000000..a1d1bf388 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning errors.kt @@ -0,0 +1,98 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index returning errors` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("usersByIds") { env -> + null + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf("1", "2"), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null elements snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null elements snapshot.kt new file mode 100644 index 000000000..e25d13c60 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null elements snapshot.kt @@ -0,0 +1,141 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index returning null elements`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index returning null elements snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "1" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "1", + | "2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["1", "2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | null, + | { + | "name": "Name 2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * null + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * null, + * { + * "name": "Name 2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | null + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | null, + | { + | "name": "Name 2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null elements.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null elements.kt new file mode 100644 index 000000000..0d04ae5d9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null elements.kt @@ -0,0 +1,102 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index returning null elements` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "2", name = "Name 2") + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf("1", "2"), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null snapshot.kt new file mode 100644 index 000000000..1a6c7e8bf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index returning null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index returning null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "1" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "1", + | "2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["1", "2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * null + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * null, + * null + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | null + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | null, + | null + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null.kt new file mode 100644 index 000000000..ad709b0ad --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index returning null.kt @@ -0,0 +1,98 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index returning null` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("usersByIds") { env -> + null + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf("1", "2"), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index snapshot.kt new file mode 100644 index 000000000..6cf274a12 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index snapshot.kt @@ -0,0 +1,151 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "1" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "1", + | "2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["1", "2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "Name" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "name": "Name" + * }, + * { + * "name": "Name 2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "Name" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists snapshot.kt new file mode 100644 index 000000000..bd11fe8b4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists snapshot.kt @@ -0,0 +1,153 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index with lists`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index with lists snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__id": "ISSUE-1", + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__id": "ISSUE-2", + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIssueIds(issueIds: ["ISSUE-1", "ISSUE-2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIssueIds": [ + | [ + | { + | "name": "Name" + | } + | ], + | [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "Name" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "name": "Name" + * }, + * { + * "name": "Name 2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "Name" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists with hydration field not exposed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists with hydration field not exposed snapshot.kt new file mode 100644 index 000000000..ce2b2e75e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists with hydration field not exposed snapshot.kt @@ -0,0 +1,154 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index with lists with hydration field not exposed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index with lists with hydration field not exposed snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | id + | batch_hydration__authors__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__id": "ISSUE-1", + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__id": "ISSUE-2", + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIssueIds(issueIds: ["ISSUE-1", "ISSUE-2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIssueIds": [ + | [ + | { + | "name": "Name" + | } + | ], + | [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "Name" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * { + * "name": "Name" + * }, + * { + * "name": "Name 2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "Name" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists with hydration field not exposed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists with hydration field not exposed.kt new file mode 100644 index 000000000..e59ee1b53 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists with hydration field not exposed.kt @@ -0,0 +1,102 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index with lists with hydration field not exposed` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + echo: String + usersByIssueIds(issueIds: [ID]): [[User]] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + usersByIssueIds(issueIds: [ID]): [[User]] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIssueId = mapOf( + "ISSUE-1" to listOf( + UserService_User(id = "1", name = "Name"), + ), + "ISSUE-2" to listOf( + UserService_User(id = "1", name = "Name"), + UserService_User(id = "2", name = "Name 2"), + ), + ) + + type.dataFetcher("usersByIssueIds") { env -> + env.getArgument>("issueIds")?.map(usersByIssueId::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIssueIds" + arguments: [{name: "issueIds" value: "${'$'}source.id"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(id = "ISSUE-1"), Issues_Issue(id = "ISSUE-2")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists.kt new file mode 100644 index 000000000..540daf628 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with lists.kt @@ -0,0 +1,100 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index with lists` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIssueIds(issueIds: [ID]): [[User]] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIssueIds(issueIds: [ID]): [[User]] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIssueId = mapOf( + "ISSUE-1" to listOf( + UserService_User(id = "1", name = "Name"), + ), + "ISSUE-2" to listOf( + UserService_User(id = "1", name = "Name"), + UserService_User(id = "2", name = "Name 2"), + ), + ) + + type.dataFetcher("usersByIssueIds") { env -> + env.getArgument>("issueIds")?.map(usersByIssueId::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIssueIds" + arguments: [{name: "issueIds" value: "${'$'}source.id"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(id = "ISSUE-1"), Issues_Issue(id = "ISSUE-2")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with null input nodes snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with null input nodes snapshot.kt new file mode 100644 index 000000000..2d2ab3d37 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with null input nodes snapshot.kt @@ -0,0 +1,147 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydration matching using index with null input nodes`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydration matching using index with null input nodes snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "1" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | null, + | "2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(ids: ["1", "2"]) { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "Name" + | }, + | { + | "name": "Name 2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "Name" + * } + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * null, + * { + * "name": "Name 2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "Name" + | } + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | null, + | { + | "name": "Name 2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with null input nodes.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with null input nodes.kt new file mode 100644 index 000000000..be5f76c44 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index with null input nodes.kt @@ -0,0 +1,103 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index with null input nodes` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "1", name = "Name"), + UserService_User(id = "2", name = "Name 2"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf(null, "2"), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index.kt new file mode 100644 index 000000000..64858bcec --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/index/hydration matching using index.kt @@ -0,0 +1,103 @@ +package graphql.nadel.tests.legacy.`new hydration`.index + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `hydration matching using index` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "1", name = "Name"), + UserService_User(id = "2", name = "Name 2"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + indexed: true + batchSize: 5 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(authorIds = listOf("1"), id = "ISSUE-1"), + Issues_Issue( + authorIds = listOf("1", "2"), + id = "ISSUE-2", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/multiple conditional hydrations with different source fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/multiple conditional hydrations with different source fields snapshot.kt new file mode 100644 index 000000000..ccda8529a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/multiple conditional hydrations with different source fields snapshot.kt @@ -0,0 +1,103 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`multiple conditional hydrations with different source fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `multiple conditional hydrations with different source fields snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__class: class + | hydration__bar__type: type + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__type": 2, + | "hydration__bar__class": "ABC_123", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "BAR_B") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar B" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar B" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar B" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/multiple conditional hydrations with different source fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/multiple conditional hydrations with different source fields.kt new file mode 100644 index 000000000..fb2ed0c1e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/multiple conditional hydrations with different source fields.kt @@ -0,0 +1,146 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `multiple conditional hydrations with different source fields` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + ... on Bar { + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + type: Int + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + type: Int + class: String + } + union Bars = Bar + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "BAR_A") { + Service2_Bar(name = "Bar A") + } else if (env.getArgument("id") == "BAR_B") { + Service2_Bar(name = "Bar B") + } else { + null + } + } + } + wiring.type("Bars") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + type: Int + class: String @hidden + bar: Bars + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_A" + } + ] + when: { + result: { + sourceField: "type" + predicate: { equals: 1 } + } + } + ) + @hydrated( + service: "service2" + field: "barById" + arguments: [ + { + name: "id" + value: "BAR_B" + } + ] + when: { + result: { + sourceField: "class" + predicate: { startsWith: "A" } + } + } + ) + } + union Bars = Bar + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + type: Int + class: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(`class` = "ABC_123", type = 2) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + val type: Int? = null, + val `class`: String? = null, + ) : Service2_Bars + + private sealed interface Service2_Bars + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val type: Int? = null, + val `class`: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nested list hydration under a renamed top level field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nested list hydration under a renamed top level field snapshot.kt new file mode 100644 index 000000000..cb10a5325 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nested list hydration under a renamed top level field snapshot.kt @@ -0,0 +1,166 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`nested list hydration under a renamed top level field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `nested list hydration under a renamed top level field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | connection(id: "ID") { + | __typename__hydration__nodes: __typename + | hydration__nodes__edges: edges { + | node + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "connection": { + | "hydration__nodes__edges": [ + | { + | "node": "1" + | } + | ], + | "__typename__hydration__nodes": "Connection" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | node(id: "1") { + | __typename__hydration__space: __typename + | hydration__space__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "hydration__space__id": "1a", + | "__typename__hydration__space": "Node" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | rename__fooService__service: service { + | __typename__hydration__otherServices: __typename + | hydration__otherServices__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__fooService__service": { + | "hydration__otherServices__id": "ID", + | "__typename__hydration__otherServices": "Service" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | space(id: "1a") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "space": { + | "id": "apple" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "fooService": { + * "otherServices": { + * "nodes": [ + * { + * "space": { + * "id": "apple" + * } + * } + * ] + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "fooService": { + | "otherServices": { + | "nodes": [ + | { + | "space": { + | "id": "apple" + | } + | } + | ] + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nested list hydration under a renamed top level field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nested list hydration under a renamed top level field.kt new file mode 100644 index 000000000..7e6afe67e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nested list hydration under a renamed top level field.kt @@ -0,0 +1,157 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `nested list hydration under a renamed top level field` : NadelLegacyIntegrationTest( + query = """ + query { + fooService { + otherServices { + nodes { + space { + id + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + fooService: FooService @renamed(from: "service") + connection(id: ID): Connection + node(id: ID): Node + space(id: ID): Space + } + type FooService @renamed(from: "Service") { + otherServices: Connection + @hydrated( + service: "Foo" + field: "connection" + arguments: [{name: "id" value: "${'$'}source.id"}] + ) + } + type Connection { + edges: [Edge] + nodes: [Node] + @hydrated( + service: "Foo" + field: "node" + arguments: [{name: "id" value: "${'$'}source.edges.node"}] + ) + } + type Node { + space: Space + @hydrated( + service: "Foo" + field: "space" + arguments: [{name: "id" value: "${'$'}source.id"}] + ) + id: ID + } + type Space { + id: ID + name: String + } + type Edge { + node: Node + @hydrated( + service: "Foo" + field: "node" + arguments: [{name: "id" value: "${'$'}source.node"}] + ) + name: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Connection { + edges: [Edge] + nodes: [ID] + } + type Edge { + id: ID + name: String + node: ID + } + type Node { + detailId: ID! + id: ID + name: String + } + type Query { + connection(id: ID): Connection + node(id: ID): Node + service: Service + space(id: ID): Space + } + type Service { + id: ID + } + type Space { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("service") { env -> + Foo_Service(id = "ID") + } + .dataFetcher("connection") { env -> + if (env.getArgument("id") == "ID") { + Foo_Connection(edges = listOf(Foo_Edge(node = "1"))) + } else { + null + } + } + .dataFetcher("node") { env -> + if (env.getArgument("id") == "1") { + Foo_Node(id = "1a") + } else { + null + } + } + .dataFetcher("space") { env -> + if (env.getArgument("id") == "1a") { + Foo_Space(id = "apple") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Connection( + val edges: List? = null, + val nodes: List? = null, + ) + + private data class Foo_Edge( + val id: String? = null, + val name: String? = null, + val node: String? = null, + ) + + private data class Foo_Node( + val detailId: String? = null, + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Service( + val id: String? = null, + ) + + private data class Foo_Space( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/new batched with null value in source array snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/new batched with null value in source array snapshot.kt new file mode 100644 index 000000000..86f6d4e6c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/new batched with null value in source array snapshot.kt @@ -0,0 +1,133 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`new batched with null value in source array`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `new batched with null value in source array snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issueById(id: "10000") { + | __typename__batch_hydration__collaborators: __typename + | batch_hydration__collaborators__collaboratorIds: collaboratorIds + | key + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "key": "GQLGW-1000", + | "batch_hydration__collaborators__collaboratorIds": [ + | "100", + | null, + | "200" + | ], + | "__typename__batch_hydration__collaborators": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Users", + query = """ + | { + | usersByIds(ids: ["100", "200"]) { + | __typename + | batch_hydration__collaborators__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "__typename": "User", + | "name": "John Doe", + | "batch_hydration__collaborators__id": "100" + | }, + | { + | "__typename": "User", + | "name": "Joe", + | "batch_hydration__collaborators__id": "200" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issueById": { + * "key": "GQLGW-1000", + * "collaborators": [ + * { + * "__typename": "User", + * "name": "John Doe" + * }, + * { + * "__typename": "User", + * "name": "Joe" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issueById": { + | "key": "GQLGW-1000", + | "collaborators": [ + | { + | "__typename": "User", + | "name": "John Doe" + | }, + | { + | "__typename": "User", + | "name": "Joe" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/new batched with null value in source array.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/new batched with null value in source array.kt new file mode 100644 index 000000000..ae4ad47b6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/new batched with null value in source array.kt @@ -0,0 +1,106 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `new batched with null value in source array` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "10000") { + key + collaborators { + __typename + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issueById(id: ID!): Issue! + } + type Issue { + id: ID! + key: String + collaborators: [User] + @hydrated( + service: "Users" + field: "usersByIds" + arguments: [ + {name: "ids", value: "${'$'}source.collaboratorIds"} + ] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issueById(id: ID!): Issue! + } + type Issue { + id: ID! + key: String + collaboratorIds: [ID] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "10000") { + Issues_Issue(collaboratorIds = listOf("100", null, "200"), key = "GQLGW-1000") + } else { + null + } + } + } + }, + ), + Service( + name = "Users", + overallSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(ids: [ID!]!): [User] + } + type User { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + Users_User(id = "100", name = "John Doe"), + Users_User(id = "200", name = "Joe") + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("ids")?.map(usersByIds::get) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val id: String? = null, + val key: String? = null, + val collaboratorIds: List? = null, + ) + + private data class Users_User( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nullable argument for hydration is missing snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nullable argument for hydration is missing snapshot.kt new file mode 100644 index 000000000..750f2a2ef --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nullable argument for hydration is missing snapshot.kt @@ -0,0 +1,128 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`nullable argument for hydration is missing`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `nullable argument for hydration is missing snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "boards", + query = """ + | { + | board { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "board": { + | "hydration__issue__issueId": "ISSUE-1", + | "__typename__hydration__issue": "Board" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "comments", + query = """ + | { + | comments(cloudId: "CLOUD_ID-1") { + | totalCount + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "comments": { + | "totalCount": 10 + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "issues", + query = """ + | { + | issue(id: "ISSUE-1") { + | __typename__hydration__comments: __typename + | hydration__comments__cloudId: cloudId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__comments__cloudId": "CLOUD_ID-1", + | "__typename__hydration__comments": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "board": { + * "issue": { + * "comments": { + * "totalCount": 10 + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "board": { + | "issue": { + | "comments": { + | "totalCount": 10 + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nullable argument for hydration is missing.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nullable argument for hydration is missing.kt new file mode 100644 index 000000000..312c9c19a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/nullable argument for hydration is missing.kt @@ -0,0 +1,138 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `nullable argument for hydration is missing` : NadelLegacyIntegrationTest( + query = """ + query { + board { + issue { + comments { + totalCount + } + } + } + } + """.trimIndent(), + variables = mapOf("first" to 10), + services = listOf( + Service( + name = "boards", + overallSchema = """ + type Query { + board: Board + } + type Board { + id: ID + issue: Issue + @hydrated( + service: "issues" + field: "issue" + arguments: [{ name: "id", value: "${'$'}source.issueId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + board: Board + } + type Board { + id: ID + issueId: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("board") { env -> + Boards_Board(issueId = "ISSUE-1") + } + } + }, + ), + Service( + name = "issues", + overallSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID! + cloudId: ID! + comments(after: String): CommentConnection + @hydrated( + service: "comments" + field: "comments" + arguments: [ + {name:"cloudId" value:"${'$'}source.cloudId"} + {name:"after" value:"${'$'}argument.after"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID! + cloudId: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "ISSUE-1") { + Issues_Issue(cloudId = "CLOUD_ID-1") + } else { + null + } + } + } + }, + ), + Service( + name = "comments", + overallSchema = """ + type Query { + comments(cloudId: ID!, after: String): CommentConnection + } + type CommentConnection { + totalCount: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + comments(cloudId: ID!, after: String): CommentConnection + } + type CommentConnection { + totalCount: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("comments") { env -> + if (env.getArgument("cloudId") == "CLOUD_ID-1") { + Comments_CommentConnection(totalCount = 10) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Boards_Board( + val id: String? = null, + val issueId: String? = null, + ) + + private data class Issues_Issue( + val id: String? = null, + val cloudId: String? = null, + ) + + private data class Comments_CommentConnection( + val totalCount: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with fragments defined snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with fragments defined snapshot.kt new file mode 100644 index 000000000..5a8a839f5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with fragments defined snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one hydration call with fragments defined`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one hydration call with fragments defined snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "barId", + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "id": "barId", + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "id": "barId", + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with fragments defined.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with fragments defined.kt new file mode 100644 index 000000000..42da62244 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with fragments defined.kt @@ -0,0 +1,112 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one hydration call with fragments defined` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + ...frag1 + } + } + fragment frag1 on Foo { + bar { + id + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(id = "barId", name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with input value having longer path snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with input value having longer path snapshot.kt new file mode 100644 index 000000000..4b0b4bd0c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with input value having longer path snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one hydration call with input value having longer path`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one hydration call with input value having longer path snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__barLongerInput: __typename + | hydration__barLongerInput__fooDetails: fooDetails { + | externalBarId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__barLongerInput__fooDetails": { + | "externalBarId": "barId" + | }, + | "__typename__hydration__barLongerInput": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "barLongerInput": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "barLongerInput": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with input value having longer path.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with input value having longer path.kt new file mode 100644 index 000000000..041010f92 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with input value having longer path.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one hydration call with input value having longer path` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + barLongerInput { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(fooDetails = Service1_FooDetails(externalBarId = "barId")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with longer path arguments and merged fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with longer path arguments and merged fields snapshot.kt new file mode 100644 index 000000000..ebc4e1138 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with longer path arguments and merged fields snapshot.kt @@ -0,0 +1,145 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one hydration call with longer path arguments and merged fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one hydration call with longer path arguments and merged fields snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authors: authors { + | authorId + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authors": [ + | { + | "authorId": "USER-1" + | }, + | { + | "authorId": "USER-2" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersByIds(id: ["USER-1", "USER-2"]) { + | id + | batch_hydration__authors__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersByIds": [ + | { + | "name": "User 1", + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "name": "User 2", + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "User 1", + * "id": "USER-1" + * }, + * { + * "name": "User 2", + * "id": "USER-2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "User 1", + | "id": "USER-1" + | }, + | { + | "name": "User 2", + | "id": "USER-2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with longer path arguments and merged fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with longer path arguments and merged fields.kt new file mode 100644 index 000000000..0545fd427 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with longer path arguments and merged fields.kt @@ -0,0 +1,115 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one hydration call with longer path arguments and merged fields` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1", name = "User 1"), + UserService_User(id = "USER-2", name = "User 2"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersByIds" + arguments: [{name: "id" value: "${'$'}source.authors.authorId"}] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + authors: [IssueUser] + id: ID + } + type IssueUser { + authorId: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authors = listOf( + Issues_IssueUser(authorId = "USER-1"), + Issues_IssueUser(authorId = "USER-2"), + ), + id = "ISSUE-1", + ), + ) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val authors: List? = null, + val id: String? = null, + ) + + private data class Issues_IssueUser( + val authorId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with variables defined snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with variables defined snapshot.kt new file mode 100644 index 000000000..b9b6c5190 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with variables defined snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one hydration call with variables defined`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `one hydration call with variables defined snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "id": "barId", + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "id": "barId", + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "id": "barId", + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with variables defined.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with variables defined.kt new file mode 100644 index 000000000..f7c7135cc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one hydration call with variables defined.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one hydration call with variables defined` : NadelLegacyIntegrationTest( + query = """ + query(${'$'}var: ID) { + foo(id: ${'$'}var) { + bar { + id + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(id = "barId", name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo(id: ID): Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo(id: ID): Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one synthetic hydration call with longer path arguments and merged fields and renamed type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one synthetic hydration call with longer path arguments and merged fields and renamed type snapshot.kt new file mode 100644 index 000000000..7a0d3220e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one synthetic hydration call with longer path arguments and merged fields and renamed type snapshot.kt @@ -0,0 +1,150 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`one synthetic hydration call with longer path arguments and merged fields and renamed type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `one synthetic hydration call with longer path arguments and merged fields and renamed type snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authors: authors { + | authorId + | } + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authors": [ + | { + | "authorId": "USER-1" + | }, + | { + | "authorId": "USER-2" + | } + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersQuery { + | usersByIds(id: ["USER-1", "USER-2"]) { + | id + | batch_hydration__authors__id: id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersQuery": { + | "usersByIds": [ + | { + | "name": "User 1", + | "id": "USER-1", + | "batch_hydration__authors__id": "USER-1" + | }, + | { + | "name": "User 2", + | "id": "USER-2", + | "batch_hydration__authors__id": "USER-2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * { + * "name": "User 1", + * "id": "USER-1" + * }, + * { + * "name": "User 2", + * "id": "USER-2" + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | { + | "name": "User 1", + | "id": "USER-1" + | }, + | { + | "name": "User 2", + | "id": "USER-2" + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one synthetic hydration call with longer path arguments and merged fields and renamed type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one synthetic hydration call with longer path arguments and merged fields and renamed type.kt new file mode 100644 index 000000000..e9928e32d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/one synthetic hydration call with longer path arguments and merged fields and renamed type.kt @@ -0,0 +1,131 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `one synthetic hydration call with longer path arguments and merged fields and renamed type` : + NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersQuery: RenamedUserQuery + } + type RenamedUserQuery @renamed(from: "UserQuery") { + usersByIds(id: [ID]): [RenamedUser] + } + type RenamedUser @renamed(from: "User") { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersQuery: UserQuery + } + type User { + id: ID + name: String + } + type UserQuery { + usersByIds(id: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("usersQuery") { + Unit + } + } + wiring.type("UserQuery") { type -> + val usersByIds = listOf( + UserService_User(id = "USER-1", name = "User 1"), + UserService_User(id = "USER-2", name = "User 2"), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + env.getArgument>("id")?.map(usersByIds::get) + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [RenamedUser] + @hydrated( + service: "UserService" + field: "usersQuery.usersByIds" + arguments: [{name: "id" value: "${'$'}source.authors.authorId"}] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + authors: [IssueUser] + id: ID + } + type IssueUser { + authorId: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue( + authors = listOf( + Issues_IssueUser(authorId = "USER-1"), + Issues_IssueUser(authorId = "USER-2"), + ), + id = "ISSUE-1", + ), + ) + } + } + }, + ), + ), + ) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class UserService_UserQuery( + val usersByIds: List? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val authors: List? = null, + val id: String? = null, + ) + + private data class Issues_IssueUser( + val authorId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service return types implement same interface snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service return types implement same interface snapshot.kt new file mode 100644 index 000000000..2941cf768 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service return types implement same interface snapshot.kt @@ -0,0 +1,243 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration actor fields are in the same service return types implement same interface`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `batch polymorphic hydration actor fields are in the same service return types implement same interface snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "bar", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "bar", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita", + | "batch_hydration__data__id": "PET-0" + | }, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service return types implement same interface.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service return types implement same interface.kt new file mode 100644 index 000000000..a16e68bc3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service return types implement same interface.kt @@ -0,0 +1,163 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration actor fields are in the same service return types implement same interface` : + NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "bar" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "bar" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + Service( + name = "bar", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + humanById(ids: [ID]): [Human] + } + interface Node { + id: ID + } + type Human implements Node { + id: ID + name: String + } + type Pet implements Node { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + humanById(ids: [ID]): [Human] + } + interface Node { + id: ID + } + type Human implements Node { + id: ID + name: String + } + type Pet implements Node { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Bar_Pet(breed = "Akita", id = "PET-0"), + Bar_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + val humanById = listOf( + Bar_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + Bar_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), + ) { + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) + + private data class Bar_Human( + override val id: String? = null, + val name: String? = null, + ) : Bar_Node + + private interface Bar_Node { + val id: String? + } + + private data class Bar_Pet( + override val id: String? = null, + val breed: String? = null, + ) : Bar_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service snapshot.kt new file mode 100644 index 000000000..c21116450 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service snapshot.kt @@ -0,0 +1,242 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration actor fields are in the same service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration actor fields are in the same service snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "bar", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "bar", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita", + | "batch_hydration__data__id": "PET-0" + | }, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service.kt new file mode 100644 index 000000000..3ba45422b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration actor fields are in the same service.kt @@ -0,0 +1,145 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration actor fields are in the same service` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "bar" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "bar" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + Service( + name = "bar", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + humanById(ids: [ID]): [Human] + } + type Pet { + id: ID + breed: String + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Bar_Pet(breed = "Akita", id = "PET-0"), + Bar_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + val humanById = listOf( + Bar_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + Bar_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + }, + ), + ), +) { + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) + + private data class Bar_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Bar_Pet( + val id: String? = null, + val breed: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array snapshot.kt new file mode 100644 index 000000000..aef1703c5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array snapshot.kt @@ -0,0 +1,228 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration return null in array`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration return null in array snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | null, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array with error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array with error snapshot.kt new file mode 100644 index 000000000..8aa844e99 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array with error snapshot.kt @@ -0,0 +1,256 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration return null in array with error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration return null in array with error snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "invalid id PET-0", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "petById": [ + | null, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "invalid id PET-0", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "invalid id PET-0", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array with error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array with error.kt new file mode 100644 index 000000000..f948b34fa --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array with error.kt @@ -0,0 +1,181 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration return null in array with error` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("petById") { env -> + if (env.getArgument("ids") == listOf("PET-0", "PET-1")) { + DataFetcherResult.newResult() + .data( + listOf( + null, + Pets_Pet(breed = "Labrador", id = "PET-1"), + ), + ) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "invalid id PET-0", + ), + ), + ), + ) + .build() + } else { + null + } + } + } + } + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humansById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe") + ).associateBy { it.id } + + type.dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humansById::get) + } + } + } + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), Foo_Foo(dataId = "HUMAN-1", id = "FOO-3") + ) + } + } + } + ) + ) +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array.kt new file mode 100644 index 000000000..e5df5bc5e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return null in array.kt @@ -0,0 +1,166 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration return null in array` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petsById = listOf( + Pets_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + type.dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petsById::get) + } + } + } + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("humanById") { env -> + if (env.getArgument("ids") == listOf("HUMAN-0", "HUMAN-1")) { + listOf( + People_Human( + id = "HUMAN-0", + name = "Fanny Longbottom" + ), + People_Human( + id = "HUMAN-1", + name = "John Doe", + ) + ) + } else { + null + } + } + } + } + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3") + ) + } + } + } + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null and error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null and error snapshot.kt new file mode 100644 index 000000000..3408fc5e4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null and error snapshot.kt @@ -0,0 +1,240 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration return top level null and error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration return top level null and error snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "something went wrong", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "petById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "something went wrong", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "something went wrong", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null and error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null and error.kt new file mode 100644 index 000000000..9ce632223 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null and error.kt @@ -0,0 +1,165 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration return top level null and error` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("petById") { env -> + DataFetcherResult.newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "something went wrong" + ), + ), + ), + ) + .build() + } + } + } + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humansById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type.dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humansById::get) + } + } + } + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), Foo_Foo(dataId = "HUMAN-1", id = "FOO-3") + ) + } + } + } + ) + ) +) { + private data class Pets_Pet( + public val id: String? = null, + public val breed: String? = null, + ) + + private data class People_Human( + public val id: String? = null, + public val name: String? = null, + ) + + private data class Foo_Foo( + public val id: String? = null, + public val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null snapshot.kt new file mode 100644 index 000000000..8c3532c31 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null snapshot.kt @@ -0,0 +1,212 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration return top level null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration return top level null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null.kt new file mode 100644 index 000000000..a97b4af0a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration return top level null.kt @@ -0,0 +1,152 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +public class `batch polymorphic hydration return top level null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("petById") { env -> + null + } + } + } + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humansById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe") + ).associateBy { it.id } + + type.dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humansById::get) + } + } + } + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), Foo_Foo(dataId = "HUMAN-1", id = "FOO-3") + ) + } + } + } + ) + ) +) { + private data class Pets_Pet( + public val id: String? = null, + public val breed: String? = null, + ) + + private data class People_Human( + public val id: String? = null, + public val name: String? = null, + ) + + private data class Foo_Foo( + public val id: String? = null, + public val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration snapshot.kt new file mode 100644 index 000000000..5a6a56ebf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration snapshot.kt @@ -0,0 +1,241 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita", + | "batch_hydration__data__id": "PET-0" + | }, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration when hook returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration when hook returns null snapshot.kt new file mode 100644 index 000000000..caca133d1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration when hook returns null snapshot.kt @@ -0,0 +1,227 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration when hook returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration when hook returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "NULL-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita", + | "batch_hydration__data__id": "PET-0" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration when hook returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration when hook returns null.kt new file mode 100644 index 000000000..a0dc28f96 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration when hook returns null.kt @@ -0,0 +1,160 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration when hook returns null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Pet(breed = "Akita", id = "PET-0"), + Pets_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humansById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe") + ).associateBy { it.id } + + type.dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humansById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "NULL-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration where only one type is queried snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration where only one type is queried snapshot.kt new file mode 100644 index 000000000..1467dac64 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration where only one type is queried snapshot.kt @@ -0,0 +1,209 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration where only one type is queried`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration where only one type is queried snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "batch_hydration__data__dataId": "DOG-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "batch_hydration__data__dataId": "FISH-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "batch_hydration__data__dataId": "DOG-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "batch_hydration__data__dataId": "FISH-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0"]) { + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "batch_hydration__data__id": "HUMAN-0" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["DOG-0", "FISH-0", "DOG-1", "FISH-1"]) { + | ... on Dog { + | batch_hydration__data__id: id + | } + | ... on Fish { + | __typename + | fins + | id + | batch_hydration__data__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "batch_hydration__data__id": "DOG-0" + | }, + | { + | "__typename": "Fish", + | "id": "FISH-0", + | "fins": 4, + | "batch_hydration__data__id": "FISH-0" + | }, + | { + | "batch_hydration__data__id": "DOG-1" + | }, + | { + | "__typename": "Fish", + | "id": "FISH-1", + | "fins": 8, + | "batch_hydration__data__id": "FISH-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "data": {} + * }, + * { + * "data": { + * "__typename": "Fish", + * "id": "FISH-0", + * "fins": 4 + * } + * }, + * { + * "data": {} + * }, + * { + * "data": { + * "__typename": "Fish", + * "id": "FISH-1", + * "fins": 8 + * } + * }, + * { + * "data": {} + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "data": {} + | }, + | { + | "data": { + | "__typename": "Fish", + | "id": "FISH-0", + | "fins": 4 + | } + | }, + | { + | "data": {} + | }, + | { + | "data": { + | "__typename": "Fish", + | "id": "FISH-1", + | "fins": 8 + | } + | }, + | { + | "data": {} + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration where only one type is queried.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration where only one type is queried.kt new file mode 100644 index 000000000..584e5ccc7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration where only one type is queried.kt @@ -0,0 +1,185 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration where only one type is queried` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + data { + ... on Fish { + __typename + id + fins + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Fish { + id: ID + fins: Int + } + type Dog { + id: ID + breed: String + } + union Pet = Fish | Dog + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Fish { + id: ID + fins: Int + } + type Dog { + id: ID + breed: String + } + union Pet = Fish | Dog + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Dog(id = "DOG-0"), + Pets_Fish(id = "FISH-0", fins = 4), + Pets_Dog(id = "DOG-1"), + Pets_Fish(id = "FISH-1", fins = 8), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humanById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: LivingThing + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "id" + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "id" + ) + } + union LivingThing = Human | Fish | Dog + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "DOG-0"), + Foo_Foo(dataId = "FISH-0"), + Foo_Foo(dataId = "DOG-1"), + Foo_Foo(dataId = "FISH-1"), + Foo_Foo(dataId = "HUMAN-0"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Dog( + override val id: String? = null, + val breed: String? = null, + ) : Pets_Pet + + private data class Pets_Fish( + override val id: String? = null, + val fins: Int? = null, + ) : Pets_Pet + + private sealed interface Pets_Pet { + val id: String? + } + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with conditions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with conditions snapshot.kt new file mode 100644 index 000000000..d7e2ce299 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with conditions snapshot.kt @@ -0,0 +1,241 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration with conditions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration with conditions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita", + | "batch_hydration__data__id": "PET-0" + | }, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with conditions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with conditions.kt new file mode 100644 index 000000000..dd27c93c3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with conditions.kt @@ -0,0 +1,173 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration with conditions` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Pet(breed = "Akita", id = "PET-0"), + Pets_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humanById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + when: { + result: { + sourceField: "dataId" + predicate: { matches: "PET.*" } + } + } + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + when: { + result: { + sourceField: "dataId" + predicate: { matches: "HUMAN.*" } + } + } + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with interfaces snapshot.kt new file mode 100644 index 000000000..69054be8a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with interfaces snapshot.kt @@ -0,0 +1,276 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration with interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration with interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "DOG-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "FISH-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "DOG-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "FISH-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-4", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["DOG-0", "FISH-0", "DOG-1", "FISH-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | ... on Dog { + | breed + | } + | ... on Fish { + | fins + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Dog", + | "id": "DOG-0", + | "batch_hydration__data__id": "DOG-0", + | "breed": "Akita" + | }, + | { + | "__typename": "Fish", + | "id": "FISH-0", + | "batch_hydration__data__id": "FISH-0", + | "fins": 4 + | }, + | { + | "__typename": "Dog", + | "id": "DOG-1", + | "batch_hydration__data__id": "DOG-1", + | "breed": "Labrador" + | }, + | { + | "__typename": "Fish", + | "id": "FISH-1", + | "batch_hydration__data__id": "FISH-1", + | "fins": 8 + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Dog", + * "id": "DOG-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Fish", + * "id": "FISH-0", + * "fins": 4 + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Dog", + * "id": "DOG-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Fish", + * "id": "FISH-1", + * "fins": 8 + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-4", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Dog", + | "id": "DOG-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Fish", + | "id": "FISH-0", + | "fins": 4 + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Dog", + | "id": "DOG-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Fish", + | "id": "FISH-1", + | "fins": 8 + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-4", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with interfaces.kt new file mode 100644 index 000000000..3aa2dbec0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with interfaces.kt @@ -0,0 +1,200 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration with interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Dog { + __typename + id + breed + } + ... on Fish { + __typename + id + fins + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Fish implements Pet { + id: ID + fins: Int + } + type Dog implements Pet { + id: ID + breed: String + } + interface Pet { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Fish implements Pet { + id: ID + fins: Int + } + type Dog implements Pet { + id: ID + breed: String + } + interface Pet { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Dog(id = "DOG-0", breed = "Akita"), + Pets_Fish(id = "FISH-0", fins = 4), + Pets_Dog(id = "DOG-1", breed = "Labrador"), + Pets_Fish(id = "FISH-1", fins = 8), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humanById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + ).associateBy { it.id } + + type + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: LivingThing + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "id" + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "id" + ) + } + union LivingThing = Human | Fish | Dog + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "DOG-0", id = "FOO-0"), + Foo_Foo(dataId = "FISH-0", id = "FOO-1"), + Foo_Foo(dataId = "DOG-1", id = "FOO-2"), + Foo_Foo(dataId = "FISH-1", id = "FOO-3"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-4"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Dog( + override val id: String? = null, + val breed: String? = null, + ) : Pets_Pet + + private data class Pets_Fish( + override val id: String? = null, + val fins: Int? = null, + ) : Pets_Pet + + private interface Pets_Pet { + val id: String? + } + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with lots of renames snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with lots of renames snapshot.kt new file mode 100644 index 000000000..db054128c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with lots of renames snapshot.kt @@ -0,0 +1,250 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration with lots of renames`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration with lots of renames snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "bar", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | __typename__rename__id: __typename + | batch_hydration__data__hiddenId: hiddenId + | rename__id__identifier: identifier + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "rename__id__identifier": "PERSON-0", + | "__typename__rename__id": "Human", + | "name": "Fanny Longbottom", + | "batch_hydration__data__hiddenId": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "rename__id__identifier": "PERSON-1", + | "__typename__rename__id": "Human", + | "name": "John Doe", + | "batch_hydration__data__hiddenId": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "bar", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | __typename__rename__id: __typename + | __typename__rename__breed: __typename + | batch_hydration__data__hiddenId: hiddenId + | rename__id__identifier: identifier + | rename__breed__kind: kind + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "rename__id__identifier": "ANIMAL-0", + | "__typename__rename__id": "Pet", + | "rename__breed__kind": "Akita", + | "__typename__rename__breed": "Pet", + | "batch_hydration__data__hiddenId": "PET-0" + | }, + | { + | "__typename": "Pet", + | "rename__id__identifier": "ANIMAL-1", + | "__typename__rename__id": "Pet", + | "rename__breed__kind": "Labrador", + | "__typename__rename__breed": "Pet", + | "batch_hydration__data__hiddenId": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Animal", + * "id": "ANIMAL-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Person", + * "name": "Fanny Longbottom", + * "id": "PERSON-0" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Animal", + * "id": "ANIMAL-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Person", + * "name": "John Doe", + * "id": "PERSON-1" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Animal", + | "id": "ANIMAL-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Person", + | "name": "Fanny Longbottom", + | "id": "PERSON-0" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Animal", + | "id": "ANIMAL-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Person", + | "name": "John Doe", + | "id": "PERSON-1" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with lots of renames.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with lots of renames.kt new file mode 100644 index 000000000..6da4bb365 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with lots of renames.kt @@ -0,0 +1,161 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration with lots of renames` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Animal { + __typename + id + breed + } + ... on Person { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "bar", + overallSchema = """ + type Query { + animalById(ids: [ID]): [Animal] @renamed(from: "petById") + petById(ids: [ID]): [Animal] + personById(ids: [ID]): [Person] @renamed(from: "humanById") + humanById(ids: [ID]): [Person] + } + type Animal @renamed(from: "Pet") { + id: ID @renamed(from: "identifier") + breed: String @renamed(from: "kind") + } + type Person @renamed(from: "Human") { + id: ID @renamed(from: "identifier") + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + petById(ids: [ID]): [Pet] + } + type Human { + hiddenId: ID + identifier: ID + name: String + } + type Pet { + hiddenId: ID + identifier: ID + kind: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Bar_Pet(hiddenId = "PET-0", identifier = "ANIMAL-0", kind = "Akita"), + Bar_Pet(hiddenId = "PET-1", identifier = "ANIMAL-1", kind = "Labrador"), + ).associateBy { it.hiddenId } + + val humanById = listOf( + Bar_Human( + hiddenId = "HUMAN-0", + identifier = "PERSON-0", + name = "Fanny Longbottom", + ), + Bar_Human( + hiddenId = "HUMAN-1", + identifier = "PERSON-1", + name = "John Doe", + ), + ).associateBy { it.hiddenId } + + type + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "bar" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "hiddenId" + ) + @hydrated( + service: "bar" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "hiddenId" + ) + } + union Data = Animal | Person + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + ), +) { + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) + + private data class Bar_Human( + val hiddenId: String? = null, + val identifier: String? = null, + val name: String? = null, + ) + + private data class Bar_Pet( + val hiddenId: String? = null, + val identifier: String? = null, + val kind: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with rename snapshot.kt new file mode 100644 index 000000000..60b26dde6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with rename snapshot.kt @@ -0,0 +1,244 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration with rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration with rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Person", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Person", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | __typename__rename__breed: __typename + | id + | batch_hydration__data__id: id + | rename__breed__kind: kind + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "rename__breed__kind": "Akita", + | "__typename__rename__breed": "Pet", + | "batch_hydration__data__id": "PET-0" + | }, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "rename__breed__kind": "Labrador", + | "__typename__rename__breed": "Pet", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with rename.kt new file mode 100644 index 000000000..64972f562 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with rename.kt @@ -0,0 +1,160 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration with rename` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String @renamed(from: "kind") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + kind: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Pet(id = "PET-0", kind = "Akita"), + Pets_Pet(id = "PET-1", kind = "Labrador"), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human @renamed(from: "Person") { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Person] + } + type Person { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humansById = listOf( + People_Person(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Person(id = "HUMAN-1", name = "John Doe") + ).associateBy { it.id } + + type.dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humansById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val kind: String? = null, + ) + + private data class People_Person( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with unions snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with unions snapshot.kt new file mode 100644 index 000000000..cf7fd4d4c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with unions snapshot.kt @@ -0,0 +1,278 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydration with unions`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydration with unions snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "DOG-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "FISH-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "DOG-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "FISH-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-4", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["DOG-0", "FISH-0", "DOG-1", "FISH-1"]) { + | __typename + | ... on Dog { + | breed + | id + | batch_hydration__data__id: id + | } + | ... on Fish { + | fins + | id + | batch_hydration__data__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Dog", + | "id": "DOG-0", + | "breed": "Akita", + | "batch_hydration__data__id": "DOG-0" + | }, + | { + | "__typename": "Fish", + | "id": "FISH-0", + | "fins": 4, + | "batch_hydration__data__id": "FISH-0" + | }, + | { + | "__typename": "Dog", + | "id": "DOG-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "DOG-1" + | }, + | { + | "__typename": "Fish", + | "id": "FISH-1", + | "fins": 8, + | "batch_hydration__data__id": "FISH-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Dog", + * "id": "DOG-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Fish", + * "id": "FISH-0", + * "fins": 4 + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Dog", + * "id": "DOG-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Fish", + * "id": "FISH-1", + * "fins": 8 + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-4", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Dog", + | "id": "DOG-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Fish", + | "id": "FISH-0", + | "fins": 4 + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Dog", + | "id": "DOG-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Fish", + | "id": "FISH-1", + | "fins": 8 + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-4", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with unions.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with unions.kt new file mode 100644 index 000000000..a48e9618b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration with unions.kt @@ -0,0 +1,197 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration with unions` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Dog { + __typename + id + breed + } + ... on Fish { + __typename + id + fins + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Fish { + id: ID + fins: Int + } + type Dog { + id: ID + breed: String + } + union Pet = Fish | Dog + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Fish { + id: ID + fins: Int + } + type Dog { + id: ID + breed: String + } + union Pet = Fish | Dog + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Dog(id = "DOG-0", breed = "Akita"), + Pets_Fish(id = "FISH-0", fins = 4), + Pets_Dog(id = "DOG-1", breed = "Labrador"), + Pets_Fish(id = "FISH-1", fins = 8), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humanById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: LivingThing + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "id" + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + identifiedBy: "id" + ) + } + union LivingThing = Human | Fish | Dog + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "DOG-0", id = "FOO-0"), + Foo_Foo(dataId = "FISH-0", id = "FOO-1"), + Foo_Foo(dataId = "DOG-1", id = "FOO-2"), + Foo_Foo(dataId = "FISH-1", id = "FOO-3"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-4"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Dog( + override val id: String? = null, + val breed: String? = null, + ) : Pets_Pet + + private data class Pets_Fish( + override val id: String? = null, + val fins: Int? = null, + ) : Pets_Pet + + private sealed interface Pets_Pet { + val id: String? + } + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration.kt new file mode 100644 index 000000000..45f706c11 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydration.kt @@ -0,0 +1,160 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Pet(breed = "Akita", id = "PET-0"), + Pets_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + type.dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humanById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe"), + ).associateBy { it.id } + + type + .dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humanById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydrations are executed in parallel snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydrations are executed in parallel snapshot.kt new file mode 100644 index 000000000..34b719a0f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydrations are executed in parallel snapshot.kt @@ -0,0 +1,241 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`batch polymorphic hydrations are executed in parallel`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `batch polymorphic hydrations are executed in parallel snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__batch_hydration__data: __typename + | batch_hydration__data__dataId: dataId + | batch_hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "batch_hydration__data__dataId": "PET-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "batch_hydration__data__dataId": "HUMAN-0", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "batch_hydration__data__dataId": "PET-1", + | "__typename__batch_hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "batch_hydration__data__dataId": "HUMAN-1", + | "__typename__batch_hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(ids: ["HUMAN-0", "HUMAN-1"]) { + | __typename + | id + | batch_hydration__data__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": [ + | { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom", + | "batch_hydration__data__id": "HUMAN-0" + | }, + | { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe", + | "batch_hydration__data__id": "HUMAN-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(ids: ["PET-0", "PET-1"]) { + | __typename + | breed + | id + | batch_hydration__data__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": [ + | { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita", + | "batch_hydration__data__id": "PET-0" + | }, + | { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador", + | "batch_hydration__data__id": "PET-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-2", + * "data": { + * "__typename": "Pet", + * "id": "PET-1", + * "breed": "Labrador" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-3", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-1", + * "name": "John Doe" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-2", + | "data": { + | "__typename": "Pet", + | "id": "PET-1", + | "breed": "Labrador" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-3", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-1", + | "name": "John Doe" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydrations are executed in parallel.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydrations are executed in parallel.kt new file mode 100644 index 000000000..6ff6d48c7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/batch polymorphic hydrations are executed in parallel.kt @@ -0,0 +1,160 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `batch polymorphic hydrations are executed in parallel` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(ids: [ID]): [Pet] + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Pet(breed = "Akita", id = "PET-0"), + Pets_Pet(breed = "Labrador", id = "PET-1"), + ).associateBy { it.id } + + type + .dataFetcher("petById") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(ids: [ID]): [Human] + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val humansById = listOf( + People_Human(id = "HUMAN-0", name = "Fanny Longbottom"), + People_Human(id = "HUMAN-1", name = "John Doe") + ).associateBy { it.id } + + type.dataFetcher("humanById") { env -> + env.getArgument>("ids")?.map(humansById::get) + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "ids" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo(dataId = "HUMAN-0", id = "FOO-1"), + Foo_Foo(dataId = "PET-1", id = "FOO-2"), + Foo_Foo(dataId = "HUMAN-1", id = "FOO-3"), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/polymorphic hydration instructions use different inputs snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/polymorphic hydration instructions use different inputs snapshot.kt new file mode 100644 index 000000000..e5a81c77b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/polymorphic hydration instructions use different inputs snapshot.kt @@ -0,0 +1,186 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`polymorphic hydration instructions use different inputs`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `polymorphic hydration instructions use different inputs snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Dogs", + query = """ + | { + | dogsByIds(ids: ["good-boye-1"]) { + | __typename + | batch_hydration__animal__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "dogsByIds": [ + | { + | "__typename": "Dog", + | "name": "Abe", + | "batch_hydration__animal__id": "good-boye-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Pets", + query = """ + | { + | petsByIds(ids: ["good-boye-1", "tall-boye-9"]) { + | __typename__batch_hydration__animal: __typename + | batch_hydration__animal__animalId: animalId + | batch_hydration__animal__animalId: animalId + | batch_hydration__animal__giraffeInput: giraffeInput { + | nickname + | } + | batch_hydration__animal__giraffeInput: giraffeInput { + | birthday + | } + | batch_hydration__animal__giraffeInput: giraffeInput { + | height + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petsByIds": [ + | { + | "batch_hydration__animal__animalId": "good-boye-1", + | "batch_hydration__animal__giraffeInput": null, + | "__typename__batch_hydration__animal": "Pet" + | }, + | { + | "batch_hydration__animal__animalId": "tall-boye-9", + | "batch_hydration__animal__giraffeInput": { + | "nickname": "Tall Boye", + | "birthday": 1001203200, + | "height": 570 + | }, + | "__typename__batch_hydration__animal": "Pet" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Zoo", + query = """ + | { + | giraffes(filters: [{birthday : 1001203200, height : 570, nickname : "Tall Boye"}]) { + | __typename + | birthday + | batch_hydration__animal__birthday: birthday + | height + | batch_hydration__animal__height: height + | name + | batch_hydration__animal__nickname: nickname + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "giraffes": [ + | { + | "__typename": "Giraffe", + | "name": "Rukiya", + | "birthday": 1001203200, + | "height": 570, + | "batch_hydration__animal__nickname": "Tall Boye", + | "batch_hydration__animal__birthday": 1001203200, + | "batch_hydration__animal__height": 570 + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "petsByIds": [ + * { + * "animal": { + * "__typename": "Dog", + * "name": "Abe" + * } + * }, + * { + * "animal": { + * "__typename": "Giraffe", + * "name": "Rukiya", + * "birthday": 1001203200, + * "height": 570 + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "petsByIds": [ + | { + | "animal": { + | "__typename": "Dog", + | "name": "Abe" + | } + | }, + | { + | "animal": { + | "__typename": "Giraffe", + | "name": "Rukiya", + | "birthday": 1001203200, + | "height": 570 + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/polymorphic hydration instructions use different inputs.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/polymorphic hydration instructions use different inputs.kt new file mode 100644 index 000000000..2db81f571 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/polymorphic hydration instructions use different inputs.kt @@ -0,0 +1,266 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `polymorphic hydration instructions use different inputs` : NadelLegacyIntegrationTest( + query = """ + query { + petsByIds(ids: ["good-boye-1", "tall-boye-9"]) { + animal { + __typename + ... on Dog { + name + } + ... on Cat { + name + } + ... on Giraffe { + name + birthday + height + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Pets", + overallSchema = """ + type Query { + petsByIds(ids: [ID!]!): [Pet] + } + union Animal = Dog | Cat | Giraffe + type Pet { + animal: Animal + @hydrated( + service: "Dogs" + field: "dogsByIds" + arguments: [{ name: "ids", value: "${'$'}source.animalId"}] + identifiedBy: "id" + batchSize: 90 + ) + @hydrated( + service: "Cats" + field: "cats.catsByIds" + arguments: [{ name: "ids", value: "${'$'}source.animalId"}] + identifiedBy: "id" + batchSize: 90 + ) + @hydrated( + service: "Zoo" + field: "giraffes" + arguments: [{ name: "filters", value: "${'$'}source.giraffeInput"}] + inputIdentifiedBy: [ + {sourceId: "giraffeInput.nickname", resultId: "nickname"} + {sourceId: "giraffeInput.birthday", resultId: "birthday"} + {sourceId: "giraffeInput.height", resultId: "height"} + ] + batchSize: 90 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petsByIds(ids: [ID!]!): [Pet] + } + type Pet { + animalId: ID! + giraffeInput: PetGiraffeInput + } + type PetGiraffeInput { + nickname: String! + birthday: Int! + height: Int! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val petById = listOf( + Pets_Pet( + animalId = "good-boye-1", + giraffeInput = null + ), + Pets_Pet( + animalId = "tall-boye-9", + giraffeInput = Pets_PetGiraffeInput( + nickname = "Tall Boye", + birthday = 1_001_203_200, + height = 570, + ), + ), + ).associateBy { it.animalId } + + type + .dataFetcher("petsByIds") { env -> + env.getArgument>("ids")?.map(petById::get) + } + } + }, + ), + Service( + name = "Dogs", + overallSchema = """ + type Query { + dogsByIds(ids: [ID!]!): [Dog] + } + type Dog { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + dogsByIds(ids: [ID!]!): [Dog] + } + type Dog { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val dogsById = listOf( + Dogs_Dog(id = "good-boye-1", name = "Abe"), + ).associateBy { it.id } + + type.dataFetcher("dogsByIds") { env -> + env.getArgument>("ids")?.map(dogsById::get) + } + } + }, + ), + Service( + name = "Cats", + overallSchema = """ + type Query { + cats: CatQuery + } + type CatQuery { + catsByIds(ids: [ID!]!): [Cat] + } + type Cat { + id: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + cats: CatQuery + } + type CatQuery { + catsByIds(ids: [ID!]!): [Cat] + } + type Cat { + id: ID! + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Zoo", + overallSchema = """ + type Query { + giraffes(filters: [GiraffeFilter]): [Giraffe] + } + input GiraffeFilter { + nickname: String! + birthday: Int! + height: Int! + } + type Giraffe { + id: ID! + name: String + nickname: String + birthday: Int + height: Int + } + """.trimIndent(), + underlyingSchema = """ + type Query { + giraffes(filters: [GiraffeFilter]): [Giraffe] + } + input GiraffeFilter { + nickname: String! + birthday: Int! + height: Int! + } + type Giraffe { + id: ID! + name: String + nickname: String + birthday: Int + height: Int + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("giraffes") { env -> + if (env.getArgument("filters") == + listOf( + mapOf( + "nickname" to "Tall Boye", + "birthday" to 1_001_203_200, + "height" to 570, + ), + ) + ) { + listOf( + Zoo_Giraffe( + birthday = 1_001_203_200, + height = 570, + name = "Rukiya", + nickname = "Tall Boye", + ), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val animalId: String? = null, + val giraffeInput: Pets_PetGiraffeInput? = null, + ) + + private data class Pets_PetGiraffeInput( + val nickname: String? = null, + val birthday: Int? = null, + val height: Int? = null, + ) + + private data class Dogs_Dog( + val id: String? = null, + val name: String? = null, + ) + + private data class Cats_Cat( + val id: String? = null, + val name: String? = null, + ) + + private data class Cats_CatQuery( + val catsByIds: List? = null, + ) + + private data class Zoo_Giraffe( + val id: String? = null, + val name: String? = null, + val nickname: String? = null, + val birthday: Int? = null, + val height: Int? = null, + ) + + private data class Zoo_GiraffeFilter( + val nickname: String? = null, + val birthday: Int? = null, + val height: Int? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration snapshot.kt new file mode 100644 index 000000000..49a7b7453 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration snapshot.kt @@ -0,0 +1,181 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`solitary polymorphic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `solitary polymorphic hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__hydration__data: __typename + | hydration__data__dataId: dataId + | hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "hydration__data__dataId": "PET-0", + | "__typename__hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "hydration__data__dataId": "HUMAN-0", + | "__typename__hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(id: "HUMAN-0") { + | __typename + | __typename__type_filter__id: __typename + | __typename__type_filter__breed: __typename + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": { + | "__typename": "Human", + | "__typename__type_filter__id": "Human", + | "id": "HUMAN-0", + | "__typename__type_filter__breed": "Human", + | "name": "Fanny Longbottom" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "pets", + query = """ + | { + | petById(id: "PET-0") { + | __typename + | __typename__type_filter__id: __typename + | __typename__type_filter__name: __typename + | breed + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "petById": { + | "__typename": "Pet", + | "id": "PET-0", + | "__typename__type_filter__id": "Pet", + | "breed": "Akita", + | "__typename__type_filter__name": "Pet" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": { + * "__typename": "Pet", + * "id": "PET-0", + * "breed": "Akita" + * } + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": { + | "__typename": "Pet", + | "id": "PET-0", + | "breed": "Akita" + | } + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration when hook returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration when hook returns null snapshot.kt new file mode 100644 index 000000000..9ac65c9ff --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration when hook returns null snapshot.kt @@ -0,0 +1,143 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`solitary polymorphic hydration when hook returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `solitary polymorphic hydration when hook returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo { + | __typename + | __typename__hydration__data: __typename + | hydration__data__dataId: dataId + | hydration__data__dataId: dataId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "hydration__data__dataId": "NULL-0", + | "__typename__hydration__data": "Foo" + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "hydration__data__dataId": "HUMAN-0", + | "__typename__hydration__data": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "people", + query = """ + | { + | humanById(id: "HUMAN-0") { + | __typename + | __typename__type_filter__id: __typename + | __typename__type_filter__breed: __typename + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "humanById": { + | "__typename": "Human", + | "__typename__type_filter__id": "Human", + | "id": "HUMAN-0", + | "__typename__type_filter__breed": "Human", + | "name": "Fanny Longbottom" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "__typename": "Foo", + * "id": "FOO-0", + * "data": null + * }, + * { + * "__typename": "Foo", + * "id": "FOO-1", + * "data": { + * "__typename": "Human", + * "id": "HUMAN-0", + * "name": "Fanny Longbottom" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "__typename": "Foo", + | "id": "FOO-0", + | "data": null + | }, + | { + | "__typename": "Foo", + | "id": "FOO-1", + | "data": { + | "__typename": "Human", + | "id": "HUMAN-0", + | "name": "Fanny Longbottom" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration when hook returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration when hook returns null.kt new file mode 100644 index 000000000..20c200c16 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration when hook returns null.kt @@ -0,0 +1,149 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `solitary polymorphic hydration when hook returns null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(id: ID): Pet + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(id: ID): Pet + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(id: ID): Human + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(id: ID): Human + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("humanById") { env -> + if (env.getArgument("id") == "HUMAN-0") { + People_Human(id = "HUMAN-0", name = "Fanny Longbottom") + } else { + null + } + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "id" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "id" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "NULL-0", id = "FOO-0"), + Foo_Foo( + dataId = "HUMAN-0", + id = "FOO-1", + ), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration.kt new file mode 100644 index 000000000..5d6888663 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/polymorphic hydrations/solitary polymorphic hydration.kt @@ -0,0 +1,158 @@ +package graphql.nadel.tests.legacy.`new hydration`.`polymorphic hydrations` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `solitary polymorphic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + id + data { + ... on Pet { + __typename + id + breed + } + ... on Human { + __typename + id + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "pets", + overallSchema = """ + type Query { + petById(id: ID): Pet + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + petById(id: ID): Pet + } + type Pet { + id: ID + breed: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("petById") { env -> + if (env.getArgument("id") == "PET-0") { + Pets_Pet(breed = "Akita", id = "PET-0") + } else { + null + } + } + } + }, + ), + Service( + name = "people", + overallSchema = """ + type Query { + humanById(id: ID): Human + } + type Human { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + humanById(id: ID): Human + } + type Human { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("humanById") { env -> + if (env.getArgument("id") == "HUMAN-0") { + People_Human(id = "HUMAN-0", name = "Fanny Longbottom") + } else { + null + } + } + } + }, + ), + Service( + name = "foo", + overallSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + data: Data + @hydrated( + service: "pets" + field: "petById" + arguments: [ + {name: "id" value: "${'$'}source.dataId"} + ] + ) + @hydrated( + service: "people" + field: "humanById" + arguments: [ + {name: "id" value: "${'$'}source.dataId"} + ] + ) + } + union Data = Pet | Human + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: [Foo] + } + type Foo { + id: ID + dataId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + listOf( + Foo_Foo(dataId = "PET-0", id = "FOO-0"), + Foo_Foo( + dataId = "HUMAN-0", + id = "FOO-1", + ), + ) + } + } + }, + ), + ), +) { + private data class Pets_Pet( + val id: String? = null, + val breed: String? = null, + ) + + private data class People_Human( + val id: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val id: String? = null, + val dataId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydrated interfaces work as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydrated interfaces work as expected snapshot.kt new file mode 100644 index 000000000..e03ce510f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydrated interfaces work as expected snapshot.kt @@ -0,0 +1,184 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with hydrated interfaces work as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with hydrated interfaces work as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "OwnerService", + query = """ + | query petQ { + | ownerById(id: "cruella") { + | name + | ... on CaringOwner { + | givesPats + | } + | ... on CruelOwner { + | givesSmacks + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "ownerById": { + | "name": "Cruella De Vil", + | "givesSmacks": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "OwnerService", + query = """ + | query petQ { + | ownerById(id: "dearly") { + | name + | ... on CaringOwner { + | givesPats + | } + | ... on CruelOwner { + | givesSmacks + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "ownerById": { + | "name": "Mr Dearly", + | "givesPats": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | __typename__hydration__owners: __typename + | name + | ... on Cat { + | hydration__owners__ownerIds: ownerIds + | } + | ... on Dog { + | hydration__owners__ownerIds: ownerIds + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "__typename__hydration__owners": "Dog", + | "hydration__owners__ownerIds": [ + | "dearly" + | ] + | }, + | { + | "name": "Whiskers", + | "__typename__hydration__owners": "Cat", + | "hydration__owners__ownerIds": [ + | "cruella" + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "owners": [ + * { + * "name": "Mr Dearly", + * "givesPats": true + * } + * ] + * }, + * { + * "name": "Whiskers", + * "owners": [ + * { + * "name": "Cruella De Vil", + * "givesSmacks": true + * } + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "owners": [ + | { + | "name": "Mr Dearly", + | "givesPats": true + | } + | ] + | }, + | { + | "name": "Whiskers", + | "owners": [ + | { + | "name": "Cruella De Vil", + | "givesSmacks": true + | } + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydrated interfaces work as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydrated interfaces work as expected.kt new file mode 100644 index 000000000..26ebae433 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydrated interfaces work as expected.kt @@ -0,0 +1,282 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with hydrated interfaces work as expected` : NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + owners { + name + ... on CaringOwner { + givesPats + } + ... on CruelOwner { + givesSmacks + } + } + } + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + owners: [Owner] + @hydrated( + service: "OwnerService" + field: "ownerById" + arguments: [{name: "id" value: "${'$'}source.ownerIds"}] + ) + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + owners: [Owner] + @hydrated( + service: "OwnerService" + field: "ownerById" + arguments: [{name: "id" value: "${'$'}source.ownerIds"}] + ) + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + owners: [Owner] + @hydrated( + service: "OwnerService" + field: "ownerById" + arguments: [{name: "id" value: "${'$'}source.ownerIds"}] + ) + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", ownerIds = listOf("dearly")), + PetService_Cat( + name = "Whiskers", + ownerIds = listOf("cruella"), + ), + ) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + ownerById(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + ownerById(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("ownerById") { env -> + if (env.getArgument("id") == "dearly") { + OwnerService_CaringOwner(name = "Mr Dearly", givesPats = true) + } else if (env.getArgument("id") == "cruella") { + OwnerService_CruelOwner(name = "Cruella De Vil", givesSmacks = true) + } else { + null + } + } + } + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydration that fail with errors are reflected in the result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydration that fail with errors are reflected in the result snapshot.kt new file mode 100644 index 000000000..a6da2a759 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydration that fail with errors are reflected in the result snapshot.kt @@ -0,0 +1,124 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with hydration that fail with errors are reflected in the result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with hydration that fail with errors are reflected in the result snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barById(id: "barId123") { + | __typename__hydration__nestedBar: __typename + | name + | hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error during hydration", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "barById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId123", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error during hydration", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error during hydration", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydration that fail with errors are reflected in the result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydration that fail with errors are reflected in the result.kt new file mode 100644 index 000000000..429e53986 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with hydration that fail with errors are reflected in the result.kt @@ -0,0 +1,121 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with hydration that fail with errors are reflected in the result` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + nestedBar { + name + nestedBar { + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bar: Bar + barById(id: ID): Bar + } + type Bar { + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.nestedBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + nestedBarId: ID + } + type Query { + bar: Bar + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId123") { + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error during hydration", + ), + ), + ), + ).build() + } else { + null + } + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + bar: Bar + @hydrated( + service: "Bar" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + name: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Foo_Foo(barId = "barId123") + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val id: String? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with synthetic hydration that fail with errors are reflected in the result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with synthetic hydration that fail with errors are reflected in the result snapshot.kt new file mode 100644 index 000000000..882586541 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with synthetic hydration that fail with errors are reflected in the result snapshot.kt @@ -0,0 +1,129 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with synthetic hydration that fail with errors are reflected in the result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with synthetic hydration that fail with errors are reflected in the result snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barQuery { + | barById(id: "barId123") { + | __typename__hydration__nestedBar: __typename + | name + | hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Error during hydration", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "barQuery": { + | "barById": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId123", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Error during hydration", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Error during hydration", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with synthetic hydration that fail with errors are reflected in the result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with synthetic hydration that fail with errors are reflected in the result.kt new file mode 100644 index 000000000..ee62f6bb5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with synthetic hydration that fail with errors are reflected in the result.kt @@ -0,0 +1,138 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with synthetic hydration that fail with errors are reflected in the result` : + NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + nestedBar { + name + nestedBar { + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + barQuery: BarQuery + } + type BarQuery { + bar: Bar + barById(id: ID): Bar + } + type Bar { + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barQuery.barById" + arguments: [{name: "id" value: "${'$'}source.nestedBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + nestedBarId: ID + } + type BarQuery { + bar: Bar + barById(id: ID): Bar + } + type Query { + barQuery: BarQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barQuery") { + Unit + } + } + wiring.type("BarQuery") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId123") { + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Error during hydration", + ), + ), + ), + ).build() + } else { + null + } + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String + bar: Bar + @hydrated( + service: "Bar" + field: "barQuery.barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + name: String + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Foo_Foo(barId = "barId123") + } + } + }, + ), + ), + ) { + private data class Bar_Bar( + val id: String? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Bar_BarQuery( + val bar: Bar_Bar? = null, + val barById: Bar_Bar? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data and lots of renames snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data and lots of renames snapshot.kt new file mode 100644 index 000000000..aa6266c06 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data and lots of renames snapshot.kt @@ -0,0 +1,271 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with three nested hydrations and simple data and lots of renames`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with three nested hydrations and simple data and lots of renames snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["bar1"]) { + | __typename__rename__barName: __typename + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__bar__barId: barId + | rename__barName__name: name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "rename__barName__name": "Bar 1", + | "__typename__rename__barName": "Bar", + | "batch_hydration__nestedBar__nestedBarId": "nestedBar1", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["nestedBar1"]) { + | __typename__rename__barName: __typename + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__nestedBar__barId: barId + | rename__barName__name: name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "rename__barName__name": "NestedBarName1", + | "__typename__rename__barName": "Bar", + | "batch_hydration__nestedBar__nestedBarId": "nestedBarId456", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__nestedBar__barId": "nestedBar1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["nestedBarId456"]) { + | __typename__rename__barName: __typename + | __typename__rename__barDetails: __typename + | batch_hydration__nestedBar__barId: barId + | rename__barDetails__details: details { + | __typename__rename__barAge: __typename + | __typename__rename__barContact: __typename + | rename__barAge__age: age + | rename__barContact__contact: contact { + | __typename__rename__barEmail: __typename + | __typename__rename__barPhone: __typename + | rename__barEmail__email: email + | rename__barPhone__phone: phone + | } + | } + | rename__barName__name: name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "rename__barName__name": "NestedBarName2", + | "__typename__rename__barName": "Bar", + | "rename__barDetails__details": { + | "rename__barAge__age": 1, + | "__typename__rename__barAge": "Details", + | "rename__barContact__contact": { + | "rename__barEmail__email": "test", + | "__typename__rename__barEmail": "ContactDetails", + | "rename__barPhone__phone": 1, + | "__typename__rename__barPhone": "ContactDetails" + | }, + | "__typename__rename__barContact": "Details" + | }, + | "__typename__rename__barDetails": "Bar", + | "batch_hydration__nestedBar__barId": "nestedBarId456" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | rename__fooz__foos: foos { + | __typename__rename__fooDetails: __typename + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | rename__fooDetails__details: details { + | __typename__rename__fooName: __typename + | __typename__rename__fooAge: __typename + | __typename__rename__fooContact: __typename + | rename__fooAge__age: age + | rename__fooContact__contact: contact { + | __typename__rename__fooEmail: __typename + | __typename__rename__fooPhone: __typename + | rename__fooEmail__email: email + | rename__fooPhone__phone: phone + | } + | rename__fooName__name: name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__fooz__foos": [ + | { + | "rename__fooDetails__details": { + | "rename__fooName__name": "smith", + | "__typename__rename__fooName": "Details", + | "rename__fooAge__age": 1, + | "__typename__rename__fooAge": "Details", + | "rename__fooContact__contact": { + | "rename__fooEmail__email": "test", + | "__typename__rename__fooEmail": "ContactDetails", + | "rename__fooPhone__phone": 1, + | "__typename__rename__fooPhone": "ContactDetails" + | }, + | "__typename__rename__fooContact": "Details" + | }, + | "__typename__rename__fooDetails": "Foo", + | "batch_hydration__bar__barId": "bar1", + | "__typename__batch_hydration__bar": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "fooz": [ + * { + * "fooDetails": { + * "fooName": "smith", + * "fooAge": 1, + * "fooContact": { + * "fooEmail": "test", + * "fooPhone": 1 + * } + * }, + * "bar": { + * "barName": "Bar 1", + * "nestedBar": { + * "barName": "NestedBarName1", + * "nestedBar": { + * "barName": "NestedBarName2", + * "barDetails": { + * "barAge": 1, + * "barContact": { + * "barEmail": "test", + * "barPhone": 1 + * } + * } + * } + * } + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "fooz": [ + | { + | "fooDetails": { + | "fooName": "smith", + | "fooAge": 1, + | "fooContact": { + | "fooEmail": "test", + | "fooPhone": 1 + | } + | }, + | "bar": { + | "barName": "Bar 1", + | "nestedBar": { + | "barName": "NestedBarName1", + | "nestedBar": { + | "barName": "NestedBarName2", + | "barDetails": { + | "barAge": 1, + | "barContact": { + | "barEmail": "test", + | "barPhone": 1 + | } + | } + | } + | } + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data and lots of renames.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data and lots of renames.kt new file mode 100644 index 000000000..9e991889f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data and lots of renames.kt @@ -0,0 +1,214 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with three nested hydrations and simple data and lots of renames` : NadelLegacyIntegrationTest( + query = """ + query { + fooz { + fooDetails { + fooName + fooAge + fooContact { + fooEmail + fooPhone + } + } + bar { + barName + nestedBar { + barName + nestedBar { + barName + barDetails { + barAge + barContact { + barEmail + barPhone + } + } + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + ibar: Bar @renamed(from: "bar") + barsById(id: [ID]): [Bar] + } + type Bar { + barId: ID + barName: String @renamed(from: "name") + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.nestedBarId"}] + identifiedBy: "barId" + ) + barDetails: BarDetails @renamed(from: "details") + } + type BarDetails @renamed(from: "Details") { + barAge: Int @renamed(from: "age") + barContact: BarContactDetails @renamed(from: "contact") + } + type BarContactDetails @renamed(from: "ContactDetails") { + barEmail: String @renamed(from: "email") + barPhone: Int @renamed(from: "phone") + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + barId: ID + details: Details + name: String + nestedBarId: ID + } + type ContactDetails { + email: String + phone: Int + } + type Details { + age: Int + contact: ContactDetails + } + type Query { + bar: Bar + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Bar_Bar( + barId = "bar1", + name = "Bar 1", + nestedBarId = "nestedBar1" + ), + Bar_Bar( + barId = "nestedBar1", + name = "NestedBarName1", + nestedBarId = "nestedBarId456", + ), + Bar_Bar( + barId = "nestedBarId456", + details = Bar_Details( + age = 1, + contact = Bar_ContactDetails( + email = "test", + phone = 1, + ), + ), + name = "NestedBarName2", + ), + ).associateBy { it.barId } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.map(barsById::get) + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + fooz: [Fooz] @renamed(from: "foos") + } + type Fooz @renamed(from: "Foo") { + fooDetails: FooDetails @renamed(from: "details") + bar: Bar + @hydrated( + service: "Bar" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "barId" + batchSize: 2 + ) + } + type FooDetails @renamed(from: "Details") { + fooName: String @renamed(from: "name") + fooAge: Int @renamed(from: "age") + fooContact: FooContactDetails @renamed(from: "contact") + } + type FooContactDetails @renamed(from: "ContactDetails") { + fooEmail: String @renamed(from: "email") + fooPhone: Int @renamed(from: "phone") + } + """.trimIndent(), + underlyingSchema = """ + type ContactDetails { + email: String + phone: Int + } + type Details { + age: Int + contact: ContactDetails + name: String + } + type Foo { + barId: ID + details: Details + } + type Query { + foos: [Foo] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foos") { env -> + listOf( + Foo_Foo( + barId = "bar1", + details = Foo_Details( + age = 1, + contact = Foo_ContactDetails(email = "test", phone = 1), + name = "smith", + ), + ), + ) + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val barId: String? = null, + val details: Bar_Details? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Bar_ContactDetails( + val email: String? = null, + val phone: Int? = null, + ) + + private data class Bar_Details( + val age: Int? = null, + val contact: Bar_ContactDetails? = null, + ) + + private data class Foo_ContactDetails( + val email: String? = null, + val phone: Int? = null, + ) + + private data class Foo_Details( + val age: Int? = null, + val contact: Foo_ContactDetails? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val details: Foo_Details? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data snapshot.kt new file mode 100644 index 000000000..2d523f8a2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data snapshot.kt @@ -0,0 +1,182 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with three nested hydrations and simple data`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with three nested hydrations and simple data snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["bar1"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__bar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar 1", + | "batch_hydration__nestedBar__nestedBarId": "nestedBar1", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["nestedBar1"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__nestedBar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "NestedBarName1", + | "batch_hydration__nestedBar__nestedBarId": "nestedBarId456", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__nestedBar__barId": "nestedBar1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["nestedBarId456"]) { + | batch_hydration__nestedBar__barId: barId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "NestedBarName2", + | "batch_hydration__nestedBar__barId": "nestedBarId456" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foos { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "batch_hydration__bar__barId": "bar1", + | "__typename__batch_hydration__bar": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "bar": { + * "name": "Bar 1", + * "nestedBar": { + * "name": "NestedBarName1", + * "nestedBar": { + * "name": "NestedBarName2" + * } + * } + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "bar": { + | "name": "Bar 1", + | "nestedBar": { + | "name": "NestedBarName1", + | "nestedBar": { + | "name": "NestedBarName2" + | } + | } + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data.kt new file mode 100644 index 000000000..e98556f09 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and simple data.kt @@ -0,0 +1,125 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with three nested hydrations and simple data` : NadelLegacyIntegrationTest( + query = """ + query { + foos { + bar { + name + nestedBar { + name + nestedBar { + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bar: Bar + barsById(id: [ID]): [Bar] + } + type Bar { + barId: ID + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.nestedBarId"}] + identifiedBy: "barId" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + barId: ID + name: String + nestedBarId: ID + } + type Query { + bar: Bar + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Bar_Bar( + barId = "bar1", + name = "Bar 1", + nestedBarId = "nestedBar1", + ), + Bar_Bar( + barId = "nestedBar1", + name = "NestedBarName1", + nestedBarId = "nestedBarId456", + ), + Bar_Bar( + barId = "nestedBarId456", + name = "NestedBarName2", + ) + ).associateBy { it.barId } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.map(barsById::get) + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foos: [Foo] + } + type Foo { + name: String + bar: Bar + @hydrated( + service: "Bar" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "barId" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + name: String + } + type Query { + foos: [Foo] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foos") { env -> + listOf(Foo_Foo(barId = "bar1")) + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val barId: String? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and synthetic fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and synthetic fields snapshot.kt new file mode 100644 index 000000000..b455d719a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and synthetic fields snapshot.kt @@ -0,0 +1,266 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with three nested hydrations and synthetic fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with three nested hydrations and synthetic fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsQuery { + | barsById(id: ["bar1", "bar2"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__bar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsQuery": { + | "barsById": [ + | { + | "name": "Bar 1", + | "batch_hydration__nestedBar__nestedBarId": "nestedBar1", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar1" + | }, + | { + | "name": "Bar 2", + | "batch_hydration__nestedBar__nestedBarId": "nestedBar2", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar2" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsQuery { + | barsById(id: ["bar3"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__bar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsQuery": { + | "barsById": [ + | { + | "name": "Bar 3", + | "batch_hydration__nestedBar__nestedBarId": null, + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsQuery { + | barsById(id: ["nestedBar1", "nestedBar2"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__nestedBar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsQuery": { + | "barsById": [ + | { + | "name": "NestedBarName1", + | "batch_hydration__nestedBar__nestedBarId": "nestedBarId456", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__nestedBar__barId": "nestedBar1" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsQuery { + | barsById(id: ["nestedBarId456"]) { + | batch_hydration__nestedBar__barId: barId + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsQuery": { + | "barsById": [ + | { + | "name": "NestedBarName2", + | "batch_hydration__nestedBar__barId": "nestedBarId456" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foos { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "batch_hydration__bar__barId": "bar1", + | "__typename__batch_hydration__bar": "Foo" + | }, + | { + | "batch_hydration__bar__barId": "bar2", + | "__typename__batch_hydration__bar": "Foo" + | }, + | { + | "batch_hydration__bar__barId": "bar3", + | "__typename__batch_hydration__bar": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "bar": { + * "name": "Bar 1", + * "nestedBar": { + * "name": "NestedBarName1", + * "nestedBar": { + * "name": "NestedBarName2" + * } + * } + * } + * }, + * { + * "bar": { + * "name": "Bar 2", + * "nestedBar": null + * } + * }, + * { + * "bar": { + * "name": "Bar 3", + * "nestedBar": null + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "bar": { + | "name": "Bar 1", + | "nestedBar": { + | "name": "NestedBarName1", + | "nestedBar": { + | "name": "NestedBarName2" + | } + | } + | } + | }, + | { + | "bar": { + | "name": "Bar 2", + | "nestedBar": null + | } + | }, + | { + | "bar": { + | "name": "Bar 3", + | "nestedBar": null + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and synthetic fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and synthetic fields.kt new file mode 100644 index 000000000..65c0e5f3c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations and synthetic fields.kt @@ -0,0 +1,151 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with three nested hydrations and synthetic fields` : NadelLegacyIntegrationTest( + query = """ + query { + foos { + bar { + name + nestedBar { + name + nestedBar { + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + barsQuery: BarQuery + } + type BarQuery { + bar: Bar + barsById(id: [ID]): [Bar] + } + type Bar { + barId: ID + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barsQuery.barsById" + arguments: [{ name: "id" value: "${'$'}source.nestedBarId"}] + identifiedBy: "barId" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + barId: ID + name: String + nestedBarId: ID + } + type BarQuery { + bar: Bar + barsById(id: [ID]): [Bar] + } + type Query { + barsQuery: BarQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsQuery") { + Unit + } + } + wiring.type("BarQuery") { type -> + val barsById = listOf( + Bar_Bar( + barId = "bar3", + name = "Bar 3", + nestedBarId = null, + ), + Bar_Bar( + barId = "bar1", + name = "Bar 1", + nestedBarId = "nestedBar1", + ), + Bar_Bar( + barId = "bar2", + name = "Bar 2", + nestedBarId = "nestedBar2", + ), + Bar_Bar( + barId = "nestedBar1", + name = "NestedBarName1", + nestedBarId = "nestedBarId456", + ), + Bar_Bar( + barId = "nestedBarId456", + name = "NestedBarName2", + ), + ).associateBy { it.barId } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.mapNotNull(barsById::get) + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foos: [Foo] + } + type Foo { + name: String + bar: Bar + @hydrated( + service: "Bar" + field: "barsQuery.barsById" + arguments: [{ name: "id" value: "${'$'}source.barId"}] + identifiedBy: "barId" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + name: String + } + type Query { + foos: [Foo] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foos") { env -> + listOf(Foo_Foo(barId = "bar1"), Foo_Foo(barId = "bar2"), Foo_Foo(barId = "bar3")) + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val barId: String? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Bar_BarQuery( + val bar: Bar_Bar? = null, + val barsById: List? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations snapshot.kt new file mode 100644 index 000000000..12b9ff9c0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations snapshot.kt @@ -0,0 +1,250 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with three nested hydrations`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query with three nested hydrations snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["bar1", "bar2"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__bar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar 1", + | "batch_hydration__nestedBar__nestedBarId": "nestedBar1", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar1" + | }, + | { + | "name": "Bar 2", + | "batch_hydration__nestedBar__nestedBarId": "nestedBar2", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["bar3"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__bar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "Bar 3", + | "batch_hydration__nestedBar__nestedBarId": null, + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__bar__barId": "bar3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["nestedBar1", "nestedBar2"]) { + | __typename__batch_hydration__nestedBar: __typename + | batch_hydration__nestedBar__barId: barId + | name + | batch_hydration__nestedBar__nestedBarId: nestedBarId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "NestedBarName1", + | "batch_hydration__nestedBar__nestedBarId": "nestedBarId456", + | "__typename__batch_hydration__nestedBar": "Bar", + | "batch_hydration__nestedBar__barId": "nestedBar1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | barsById(id: ["nestedBarId456"]) { + | batch_hydration__nestedBar__barId: barId + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsById": [ + | { + | "name": "NestedBarName2", + | "batch_hydration__nestedBar__barId": "nestedBarId456" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foos { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "batch_hydration__bar__barId": "bar1", + | "__typename__batch_hydration__bar": "Foo" + | }, + | { + | "batch_hydration__bar__barId": "bar2", + | "__typename__batch_hydration__bar": "Foo" + | }, + | { + | "batch_hydration__bar__barId": "bar3", + | "__typename__batch_hydration__bar": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "bar": { + * "name": "Bar 1", + * "nestedBar": { + * "name": "NestedBarName1", + * "nestedBar": { + * "name": "NestedBarName2" + * } + * } + * } + * }, + * { + * "bar": { + * "name": "Bar 2", + * "nestedBar": null + * } + * }, + * { + * "bar": { + * "name": "Bar 3", + * "nestedBar": null + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "bar": { + | "name": "Bar 1", + | "nestedBar": { + | "name": "NestedBarName1", + | "nestedBar": { + | "name": "NestedBarName2" + | } + | } + | } + | }, + | { + | "bar": { + | "name": "Bar 2", + | "nestedBar": null + | } + | }, + | { + | "bar": { + | "name": "Bar 3", + | "nestedBar": null + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations.kt new file mode 100644 index 000000000..54c089ebf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/query with three nested hydrations.kt @@ -0,0 +1,135 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with three nested hydrations` : NadelLegacyIntegrationTest( + query = """ + query { + foos { + bar { + name + nestedBar { + name + nestedBar { + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bar: Bar + barsById(id: [ID]): [Bar] + } + type Bar { + barId: ID + name: String + nestedBar: Bar + @hydrated( + service: "Bar" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.nestedBarId"}] + identifiedBy: "barId" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + barId: ID + name: String + nestedBarId: ID + } + type Query { + bar: Bar + barsById(id: [ID]): [Bar] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val barsById = listOf( + Bar_Bar( + barId = "bar3", + name = "Bar 3", + nestedBarId = null, + ), + Bar_Bar( + barId = "bar1", + name = "Bar 1", + nestedBarId = "nestedBar1", + ), + Bar_Bar( + barId = "bar2", + name = "Bar 2", + nestedBarId = "nestedBar2", + ), + Bar_Bar( + barId = "nestedBar1", + name = "NestedBarName1", + nestedBarId = "nestedBarId456", + ), + Bar_Bar( + barId = "nestedBarId456", + name = "NestedBarName2", + ), + ).associateBy { it.barId } + + type.dataFetcher("barsById") { env -> + env.getArgument>("id")?.mapNotNull(barsById::get) + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foos: [Foo] + } + type Foo { + name: String + bar: Bar + @hydrated( + service: "Bar" + field: "barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + identifiedBy: "barId" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + name: String + } + type Query { + foos: [Foo] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foos") { env -> + listOf(Foo_Foo(barId = "bar1"), Foo_Foo(barId = "bar2"), Foo_Foo(barId = "bar3")) + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val barId: String? = null, + val name: String? = null, + val nestedBarId: String? = null, + ) + + private data class Foo_Foo( + val barId: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/renamed and hydrated query using same underlying source snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/renamed and hydrated query using same underlying source snapshot.kt new file mode 100644 index 000000000..bda57c246 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/renamed and hydrated query using same underlying source snapshot.kt @@ -0,0 +1,114 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed and hydrated query using same underlying source`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed and hydrated query using same underlying source snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | detail(detailId: "ID") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "detail": { + | "name": "apple" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__deep_rename__renamedField: __typename + | __typename__hydration__details: __typename + | deep_rename__renamedField__issue: issue { + | field + | } + | hydration__details__issue: issue { + | fooId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "deep_rename__renamedField__issue": { + | "field": "field" + | }, + | "__typename__deep_rename__renamedField": "Foo", + | "hydration__details__issue": { + | "fooId": "ID" + | }, + | "__typename__hydration__details": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "renamedField": "field", + * "details": { + * "name": "apple" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "renamedField": "field", + | "details": { + | "name": "apple" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/renamed and hydrated query using same underlying source.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/renamed and hydrated query using same underlying source.kt new file mode 100644 index 000000000..b40694a4e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/renamed and hydrated query using same underlying source.kt @@ -0,0 +1,91 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed and hydrated query using same underlying source` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + renamedField + details { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + detail(detailId: ID): Detail + foo: Foo + } + type Foo { + renamedField: String @renamed(from: "issue.field") + details: [Detail] + @hydrated( + service: "Foo" + field: "detail" + arguments: [{name: "detailId" value: "${'$'}source.issue.fooId"}] + ) + } + type Detail { + detailId: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Detail { + detailId: ID! + name: String + } + type Foo { + field: String + fooId: ID + issue: Issue + } + type Issue { + field: String + fooId: ID + } + type Query { + detail(detailId: ID): Detail + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Foo_Foo(issue = Foo_Issue(`field` = "field", fooId = "ID")) + } + .dataFetcher("detail") { env -> + if (env.getArgument("detailId") == "ID") { + Foo_Detail(name = "apple") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Detail( + val detailId: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val `field`: String? = null, + val fooId: String? = null, + val issue: Foo_Issue? = null, + ) + + private data class Foo_Issue( + val `field`: String? = null, + val fooId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level overlapping fields in the query snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level overlapping fields in the query snapshot.kt new file mode 100644 index 000000000..7d5289e1e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level overlapping fields in the query snapshot.kt @@ -0,0 +1,109 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`repeated hydrated fields on the same level overlapping fields in the query`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `repeated hydrated fields on the same level overlapping fields in the query snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__issue__issueId": "ISSUE-1", + | "__typename__hydration__issue": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issue(issueId: "ISSUE-1") { + | desc + | name + | summary + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "name": "I AM A NAME", + | "summary": "I AM A SUMMARY", + | "desc": "I AM A DESC" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "issue": { + * "name": "I AM A NAME", + * "summary": "I AM A SUMMARY", + * "desc": "I AM A DESC" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "name": "I AM A NAME", + | "summary": "I AM A SUMMARY", + | "desc": "I AM A DESC" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level overlapping fields in the query.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level overlapping fields in the query.kt new file mode 100644 index 000000000..f21a730ea --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level overlapping fields in the query.kt @@ -0,0 +1,87 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `repeated hydrated fields on the same level overlapping fields in the query` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + issue { + name + summary + } + issue { + desc + summary + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + issue(issueId: ID): Issue + } + type Foo { + issue: Issue + @hydrated( + service: "Foo" + field: "issue" + arguments: [{name: "issueId" value: "${'$'}source.issueId"}] + ) + } + type Issue { + id: ID + name: String + desc: String + summary: String + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + issueId: ID + } + type Issue { + desc: String + id: ID + name: String + summary: String + } + type Query { + foo: Foo + issue(issueId: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Foo_Foo(issueId = "ISSUE-1") + } + .dataFetcher("issue") { env -> + if (env.getArgument("issueId") == "ISSUE-1") { + Foo_Issue(desc = "I AM A DESC", name = "I AM A NAME", summary = "I AM A SUMMARY") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Foo( + val issueId: String? = null, + ) + + private data class Foo_Issue( + val desc: String? = null, + val id: String? = null, + val name: String? = null, + val summary: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level snapshot.kt new file mode 100644 index 000000000..e736aa637 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`repeated hydrated fields on the same level`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `repeated hydrated fields on the same level snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__issue__issueId": "ISSUE-1", + | "__typename__hydration__issue": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issue(issueId: "ISSUE-1") { + | desc + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "name": "I AM A NAME", + | "desc": "I AM A DESC" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "issue": { + * "name": "I AM A NAME", + * "desc": "I AM A DESC" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "name": "I AM A NAME", + | "desc": "I AM A DESC" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level when using batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level when using batch hydration snapshot.kt new file mode 100644 index 000000000..c8ada4780 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level when using batch hydration snapshot.kt @@ -0,0 +1,109 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`repeated hydrated fields on the same level when using batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `repeated hydrated fields on the same level when using batch hydration snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__issue__issueId": "ISSUE-1", + | "__typename__batch_hydration__issue": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issues(issueIds: ["ISSUE-1"]) { + | desc + | batch_hydration__issue__id: id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "name": "I AM A NAME", + | "desc": "I AM A DESC", + | "batch_hydration__issue__id": "ISSUE-1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "issue": { + * "name": "I AM A NAME", + * "desc": "I AM A DESC" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "name": "I AM A NAME", + | "desc": "I AM A DESC" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level when using batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level when using batch hydration.kt new file mode 100644 index 000000000..8a5e0720f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level when using batch hydration.kt @@ -0,0 +1,82 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `repeated hydrated fields on the same level when using batch hydration` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + issue { + name + } + issue { + desc + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + issues(issueIds: [ID!]): [Issue!] + } + type Foo { + issue: Issue + @hydrated( + service: "Foo" + field: "issues" + arguments: [{name: "issueIds" value: "${'$'}source.issueId"}] + ) + } + type Issue { + id: ID + name: String + desc: String + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + issueId: ID + } + type Issue { + desc: String + id: ID + name: String + } + type Query { + foo: Foo + issues(issueIds: [ID!]): [Issue!] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesById = listOf( + Foo_Issue(desc = "I AM A DESC", id = "ISSUE-1", name = "I AM A NAME"), + ).associateBy { it.id } + + type + .dataFetcher("foo") { env -> + Foo_Foo(issueId = "ISSUE-1") + } + type.dataFetcher("issues") { env -> + env.getArgument>("issueIds")?.map(issuesById::get) + } + } + }, + ), + ), +) { + private data class Foo_Foo( + val issueId: String? = null, + ) + + private data class Foo_Issue( + val desc: String? = null, + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level.kt new file mode 100644 index 000000000..78894919e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/repeated hydrated fields on the same level.kt @@ -0,0 +1,82 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `repeated hydrated fields on the same level` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + issue { + name + } + issue { + desc + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + issue(issueId: ID): Issue + } + type Foo { + issue: Issue + @hydrated( + service: "Foo" + field: "issue" + arguments: [{name: "issueId" value: "${'$'}source.issueId"}] + ) + } + type Issue { + id: ID + name: String + desc: String + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + issueId: ID + } + type Issue { + desc: String + id: ID + name: String + } + type Query { + foo: Foo + issue(issueId: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Foo_Foo(issueId = "ISSUE-1") + } + .dataFetcher("issue") { env -> + if (env.getArgument("issueId") == "ISSUE-1") { + Foo_Issue(desc = "I AM A DESC", name = "I AM A NAME") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Foo( + val issueId: String? = null, + ) + + private data class Foo_Issue( + val desc: String? = null, + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for hydrations snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for hydrations snapshot.kt new file mode 100644 index 000000000..5c74fced2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for hydrations snapshot.kt @@ -0,0 +1,132 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`same source for hydrations`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `same source for hydrations snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | detail(detailId: "ID") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "detail": { + | "name": "apple" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__issue: __typename + | __typename__hydration__detail: __typename + | hydration__issue__fooId: fooId + | hydration__detail__fooId: fooId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__issue__fooId": "ID", + | "__typename__hydration__issue": "Foo", + | "hydration__detail__fooId": "ID", + | "__typename__hydration__detail": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issue(issueId: "ID") { + | field + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "field": "field_name" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "issue": { + * "field": "field_name" + * }, + * "detail": { + * "name": "apple" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "field": "field_name" + | }, + | "detail": { + | "name": "apple" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for hydrations.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for hydrations.kt new file mode 100644 index 000000000..a68873bd1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for hydrations.kt @@ -0,0 +1,111 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `same source for hydrations` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + issue { + field + } + detail { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + detail(detailId: ID): Detail + issue(issueId: ID): Issue + } + type Foo { + issue: Issue + @hydrated( + service: "Foo" + field: "issue" + arguments: [{name: "issueId" value: "${'$'}source.fooId"}] + ) + detail: Detail + @hydrated( + service: "Foo" + field: "detail" + arguments: [{name: "detailId" value: "${'$'}source.fooId"}] + ) + } + type Detail { + detailId: ID! + name: String + } + type Issue { + fooId: ID + field: String + } + """.trimIndent(), + underlyingSchema = """ + type Detail { + detailId: ID! + name: String + } + type Foo { + field: String + fooId: ID + issue: Issue + } + type Issue { + field: String + fooId: ID + } + type Query { + detail(detailId: ID): Detail + foo: Foo + issue(issueId: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Foo_Foo(fooId = "ID") + } + .dataFetcher("issue") { env -> + if (env.getArgument("issueId") == "ID") { + Foo_Issue(`field` = "field_name") + } else { + null + } + } + .dataFetcher("detail") { env -> + if (env.getArgument("detailId") == "ID") { + Foo_Detail(name = "apple") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Detail( + val detailId: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val `field`: String? = null, + val fooId: String? = null, + val issue: Foo_Issue? = null, + ) + + private data class Foo_Issue( + val `field`: String? = null, + val fooId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for nested hydrations and a rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for nested hydrations and a rename snapshot.kt new file mode 100644 index 000000000..53cb557ca --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for nested hydrations and a rename snapshot.kt @@ -0,0 +1,150 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`same source for nested hydrations and a rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `same source for nested hydrations and a rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | detail(detailId: "ID") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "detail": { + | "name": "apple" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__hydration__issue: __typename + | __typename__hydration__detail: __typename + | __typename__deep_rename__renamedField: __typename + | hydration__issue__issue: issue { + | fooId + | } + | hydration__detail__issue: issue { + | fooId + | } + | deep_rename__renamedField__issue: issue { + | field + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__issue__issue": { + | "fooId": "ID" + | }, + | "__typename__hydration__issue": "Foo", + | "hydration__detail__issue": { + | "fooId": "ID" + | }, + | "__typename__hydration__detail": "Foo", + | "deep_rename__renamedField__issue": { + | "field": "field1" + | }, + | "__typename__deep_rename__renamedField": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | issue(issueId: "ID") { + | field + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "field": "field_name" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "issue": { + * "field": "field_name" + * }, + * "detail": { + * "name": "apple" + * }, + * "renamedField": "field1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "field": "field_name" + | }, + | "detail": { + | "name": "apple" + | }, + | "renamedField": "field1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for nested hydrations and a rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for nested hydrations and a rename.kt new file mode 100644 index 000000000..63ce8e90b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/same source for nested hydrations and a rename.kt @@ -0,0 +1,113 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `same source for nested hydrations and a rename` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + issue { + field + } + detail { + name + } + renamedField + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + detail(detailId: ID): Detail + issue(issueId: ID): Issue + } + type Foo { + renamedField: String @renamed(from: "issue.field") + issue: Issue + @hydrated( + service: "Foo" + field: "issue" + arguments: [{name: "issueId" value: "${'$'}source.issue.fooId"}] + ) + detail: Detail + @hydrated( + service: "Foo" + field: "detail" + arguments: [{name: "detailId" value: "${'$'}source.issue.fooId"}] + ) + } + type Detail { + detailId: ID! + name: String + } + type Issue { + fooId: ID + field: String + } + """.trimIndent(), + underlyingSchema = """ + type Detail { + detailId: ID! + name: String + } + type Foo { + field: String + fooId: ID + issue: Issue + } + type Issue { + field: String + fooId: ID + } + type Query { + detail(detailId: ID): Detail + foo: Foo + issue(issueId: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Foo_Foo(issue = Foo_Issue(fooId = "ID", `field` = "field1")) + } + .dataFetcher("issue") { env -> + if (env.getArgument("issueId") == "ID") { + Foo_Issue(`field` = "field_name") + } else { + null + } + } + .dataFetcher("detail") { env -> + if (env.getArgument("detailId") == "ID") { + Foo_Detail(name = "apple") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Detail( + val detailId: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val `field`: String? = null, + val fooId: String? = null, + val issue: Foo_Issue? = null, + ) + + private data class Foo_Issue( + val `field`: String? = null, + val fooId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple hydration query with a synthetic field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple hydration query with a synthetic field snapshot.kt new file mode 100644 index 000000000..78f26d865 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple hydration query with a synthetic field snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`simple hydration query with a synthetic field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `simple hydration query with a synthetic field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | issue { + | __typename__hydration__project: __typename + | hydration__project__projectId: projectId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__project__projectId": "project1", + | "__typename__hydration__project": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | projects { + | project(id: "project1") { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "projects": { + | "project": { + | "name": "Project 1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "project": { + * "name": "Project 1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "project": { + | "name": "Project 1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple hydration query with a synthetic field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple hydration query with a synthetic field.kt new file mode 100644 index 000000000..44574e411 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple hydration query with a synthetic field.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `simple hydration query with a synthetic field` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + project { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + projects: ProjectsQuery + } + type ProjectsQuery { + project(id: ID): Project + } + type Project { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Project { + id: ID + name: String + } + type ProjectsQuery { + project(id: ID): Project + } + type Query { + projects: ProjectsQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("projects") { + Unit + } + } + wiring.type("ProjectsQuery") { type -> + type.dataFetcher("project") { env -> + if (env.getArgument("id") == "project1") { + Service2_Project(name = "Project 1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID + project: Project + @hydrated( + service: "service2" + field: "projects.project" + arguments: [{name: "id" value: "${'$'}source.projectId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + projectId: ID + } + type Query { + issue(id: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Service1_Issue(projectId = "project1") + } + } + }, + ), + ), +) { + private data class Service2_Project( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_ProjectsQuery( + val project: Service2_Project? = null, + ) + + private data class Service1_Issue( + val id: String? = null, + val projectId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple synthetic hydration with one service and type renaming snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple synthetic hydration with one service and type renaming snapshot.kt new file mode 100644 index 000000000..7b08adba9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple synthetic hydration with one service and type renaming snapshot.kt @@ -0,0 +1,133 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`simple synthetic hydration with one service and type renaming`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `simple synthetic hydration with one service and type renaming snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "testing", + query = """ + | { + | tests { + | character(id: "C1") { + | id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "tests": { + | "character": { + | "id": "C1", + | "name": "Luke" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "testing", + query = """ + | { + | tests { + | testing { + | movie { + | __typename__hydration__character: __typename + | hydration__character__characterId: characterId + | id + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "tests": { + | "testing": { + | "movie": { + | "id": "M1", + | "name": "Movie 1", + | "hydration__character__characterId": "C1", + | "__typename__hydration__character": "Movie" + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "tests": { + * "testing": { + * "movie": { + * "id": "M1", + * "name": "Movie 1", + * "character": { + * "id": "C1", + * "name": "Luke" + * } + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "tests": { + | "testing": { + | "movie": { + | "id": "M1", + | "name": "Movie 1", + | "character": { + | "id": "C1", + | "name": "Luke" + | } + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple synthetic hydration with one service and type renaming.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple synthetic hydration with one service and type renaming.kt new file mode 100644 index 000000000..7b8efc383 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/simple synthetic hydration with one service and type renaming.kt @@ -0,0 +1,127 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `simple synthetic hydration with one service and type renaming` : NadelLegacyIntegrationTest( + query = """ + query { + tests { + testing { + movie { + id + name + character { + id + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "testing", + overallSchema = """ + type Query { + tests: TestQuery + } + type TestQuery { + testing: Testing + character(id: ID): TestingCharacter + } + type Testing { + movie: Movie + } + type TestingCharacter @renamed(from: "Character") { + id: ID! + name: String + } + type Movie { + id: ID! + name: String + character: TestingCharacter + @hydrated( + service: "testing" + field: "tests.character" + arguments: [{name: "id" value: "${'$'}source.characterId"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Character { + id: ID! + name: String + } + type Movie { + characterId: ID + id: ID! + name: String + } + type Query { + tests: TestQuery + } + type TestQuery { + character(id: ID): Character + testing: Testing + } + type Testing { + movie: Movie + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("tests") { + Unit + } + } + wiring.type("Query") { type -> + type.dataFetcher("tests") { env -> + Testing_TestQuery( + testing = Testing_Testing( + movie = Testing_Movie( + characterId = "C1", + id = "M1", + name = "Movie 1", + ), + ), + ) + } + } + + wiring.type("TestQuery") { type -> + type.dataFetcher("character") { env -> + if (env.getArgument("id") == "C1") { + Testing_Character(id = "C1", name = "Luke") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Testing_Character( + val id: String? = null, + val name: String? = null, + ) + + private data class Testing_Movie( + val characterId: String? = null, + val id: String? = null, + val name: String? = null, + ) + + private data class Testing_TestQuery( + val character: Testing_Character? = null, + val testing: Testing_Testing? = null, + ) + + private data class Testing_Testing( + val movie: Testing_Movie? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration batching returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration batching returns null snapshot.kt new file mode 100644 index 000000000..27dd2e3bd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration batching returns null snapshot.kt @@ -0,0 +1,111 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration batching returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration batching returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsQuery { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barsQuery": { + | "barsById": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": [ + * null, + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": [ + | null, + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration batching returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration batching returns null.kt new file mode 100644 index 000000000..14f8d113d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration batching returns null.kt @@ -0,0 +1,104 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration batching returns null` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsQuery: BarsQuery + } + type BarsQuery { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type BarsQuery { + barsById(id: [ID]): [Bar] + } + type Query { + barsQuery: BarsQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsQuery") { + Unit + } + } + wiring.type("BarsQuery") { type -> + type.dataFetcher("barsById") { env -> + null + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsQuery.barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_BarsQuery( + val barsById: List? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call over itself within renamed types snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call over itself within renamed types snapshot.kt new file mode 100644 index 000000000..4b0d18176 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call over itself within renamed types snapshot.kt @@ -0,0 +1,213 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration call over itself within renamed types`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration call over itself within renamed types snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "testing", + query = """ + | { + | tests { + | characters(ids: ["C1", "C2", "C3"]) { + | id + | batch_hydration__characters__id: id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "tests": { + | "characters": [ + | { + | "id": "C1", + | "name": "Luke", + | "batch_hydration__characters__id": "C1" + | }, + | { + | "id": "C2", + | "name": "Leia", + | "batch_hydration__characters__id": "C2" + | }, + | { + | "id": "C3", + | "name": "Anakin", + | "batch_hydration__characters__id": "C3" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "testing", + query = """ + | { + | tests { + | testing { + | movies { + | __typename__batch_hydration__characters: __typename + | batch_hydration__characters__characterIds: characterIds + | id + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "tests": { + | "testing": { + | "movies": [ + | { + | "id": "M1", + | "name": "Movie 1", + | "batch_hydration__characters__characterIds": [ + | "C1", + | "C2" + | ], + | "__typename__batch_hydration__characters": "Movie" + | }, + | { + | "id": "M2", + | "name": "Movie 2", + | "batch_hydration__characters__characterIds": [ + | "C1", + | "C2", + | "C3" + | ], + | "__typename__batch_hydration__characters": "Movie" + | } + | ] + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "tests": { + * "testing": { + * "movies": [ + * { + * "id": "M1", + * "name": "Movie 1", + * "characters": [ + * { + * "id": "C1", + * "name": "Luke" + * }, + * { + * "id": "C2", + * "name": "Leia" + * } + * ] + * }, + * { + * "id": "M2", + * "name": "Movie 2", + * "characters": [ + * { + * "id": "C1", + * "name": "Luke" + * }, + * { + * "id": "C2", + * "name": "Leia" + * }, + * { + * "id": "C3", + * "name": "Anakin" + * } + * ] + * } + * ] + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "tests": { + | "testing": { + | "movies": [ + | { + | "id": "M1", + | "name": "Movie 1", + | "characters": [ + | { + | "id": "C1", + | "name": "Luke" + | }, + | { + | "id": "C2", + | "name": "Leia" + | } + | ] + | }, + | { + | "id": "M2", + | "name": "Movie 2", + | "characters": [ + | { + | "id": "C1", + | "name": "Luke" + | }, + | { + | "id": "C2", + | "name": "Leia" + | }, + | { + | "id": "C3", + | "name": "Anakin" + | } + | ] + | } + | ] + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call over itself within renamed types.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call over itself within renamed types.kt new file mode 100644 index 000000000..a0ec34d35 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call over itself within renamed types.kt @@ -0,0 +1,137 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration call over itself within renamed types` : NadelLegacyIntegrationTest( + query = """ + query { + tests { + testing { + movies { + id + name + characters { + id + name + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "testing", + overallSchema = """ + type Query { + tests: TestQuery + } + type TestQuery { + testing: Testing + characters(ids: [ID!]!): [TestingCharacter] + } + type Testing { + movies: [TestingMovie] + } + type TestingCharacter @renamed(from: "Character") { + id: ID! + name: String + } + type TestingMovie @renamed(from: "Movie") { + id: ID! + name: String + characters: [TestingCharacter] + @hydrated( + service: "testing" + field: "tests.characters" + arguments: [{name: "ids" value: "${'$'}source.characterIds"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Character { + id: ID! + name: String + } + type Movie { + characterIds: [ID] + id: ID! + name: String + } + type Query { + tests: TestQuery + } + type TestQuery { + characters(ids: [ID!]!): [Character] + testing: Testing + } + type Testing { + movies: [Movie] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("tests") { + Unit + } + } + wiring.type("Query") { type -> + type.dataFetcher("tests") { env -> + Testing_TestQuery( + testing = Testing_Testing( + movies = listOf( + Testing_Movie( + characterIds = listOf("C1", "C2"), + id = "M1", + name = "Movie 1", + ), + Testing_Movie( + characterIds = listOf("C1", "C2", "C3"), + id = "M2", + name = "Movie 2", + ), + ), + ), + ) + } + } + + wiring.type("TestQuery") { type -> + val charactersById = listOf( + Testing_Character(id = "C1", name = "Luke"), + Testing_Character(id = "C2", name = "Leia"), + Testing_Character(id = "C3", name = "Anakin"), + ).associateBy { it.id } + + type + .dataFetcher("characters") { env -> + env.getArgument>("ids")?.map(charactersById::get) + } + } + }, + ), + ), +) { + private data class Testing_Character( + val id: String? = null, + val name: String? = null, + ) + + private data class Testing_Movie( + val characterIds: List? = null, + val id: String? = null, + val name: String? = null, + ) + + private data class Testing_TestQuery( + val characters: List? = null, + val testing: Testing_Testing? = null, + ) + + private data class Testing_Testing( + val movies: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call with two argument values from original field arguments snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call with two argument values from original field arguments snapshot.kt new file mode 100644 index 000000000..09558eaef --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call with two argument values from original field arguments snapshot.kt @@ -0,0 +1,120 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration call with two argument values from original field arguments`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `synthetic hydration call with two argument values from original field arguments snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__author: __typename + | batch_hydration__author__authorId: authorId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__author__authorId": "USER-1", + | "__typename__batch_hydration__author": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | usersQuery { + | usersByIds(extraArg1: "extraArg1", extraArg2: 10, id: ["USER-1"]) { + | batch_hydration__author__id: id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "usersQuery": { + | "usersByIds": [ + | { + | "name": "User 1", + | "batch_hydration__author__id": "USER-1" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "author": { + * "name": "User 1" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "author": { + | "name": "User 1" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call with two argument values from original field arguments.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call with two argument values from original field arguments.kt new file mode 100644 index 000000000..398ad8ec6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration call with two argument values from original field arguments.kt @@ -0,0 +1,122 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration call with two argument values from original field arguments` : + NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + author(extraArg1: "extraArg1", extraArg2: 10) { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersQuery: UsersQuery + } + type UsersQuery { + usersByIds(extraArg1: String, extraArg2: Int, id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersQuery: UsersQuery + } + type User { + id: ID + name: String + } + type UsersQuery { + usersByIds(extraArg1: String, extraArg2: Int, id: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("usersQuery") { + Unit + } + } + wiring.type("UsersQuery") { type -> + val usersByIds = listOf( + UserService_User( + id = "USER-1", + name = "User 1" + ), + ).associateBy { it.id } + + type.dataFetcher("usersByIds") { env -> + if (env.getArgument("extraArg1") == "extraArg1" && env.getArgument("extraArg2") == 10) { + env.getArgument>("id")?.map(usersByIds::get) + } else { + null + } + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + author(extraArg1: String, extraArg2: Int): User @hydrated( + service: "UserService" + field: "usersQuery.usersByIds" + arguments: [ + {name: "extraArg1" value: "${'$'}argument.extraArg1"} + {name: "extraArg2" value: "${'$'}argument.extraArg2"} + {name: "id" value: "${'$'}source.authorId"} + ] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorId: ID + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorId = "USER-1", id = "ISSUE-1")) + } + } + }, + ), + ), + ) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class UserService_UsersQuery( + val usersByIds: List? = null, + ) + + private data class Issues_Issue( + val authorId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration forwards error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration forwards error snapshot.kt new file mode 100644 index 000000000..abb3e6a93 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration forwards error snapshot.kt @@ -0,0 +1,125 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration forwards error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration forwards error snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId1", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsQuery { + | barById(id: "barId1") { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "barsQuery": { + | "barById": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Some error occurred", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration forwards error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration forwards error.kt new file mode 100644 index 000000000..a63647991 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration forwards error.kt @@ -0,0 +1,121 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration forwards error` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsQuery: BarsQuery + } + type BarsQuery { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type BarsQuery { + barById(id: ID): Bar + } + type Query { + barsQuery: BarsQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsQuery") { + Unit + } + } + wiring.type("BarsQuery") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId1") { + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Some error occurred", + ), + ), + ), + ).build() + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barsQuery.barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId1") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_BarsQuery( + val barById: Service2_Bar? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is empty list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is empty list snapshot.kt new file mode 100644 index 000000000..239f94ec1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is empty list snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration input is empty list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration input is empty list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is empty list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is empty list.kt new file mode 100644 index 000000000..0fb26e975 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is empty list.kt @@ -0,0 +1,97 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration input is empty list` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersQuery: UserQuery + } + type UserQuery { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersQuery: UserQuery + } + type User { + id: ID + name: String + } + type UserQuery { + usersByIds(ids: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersQuery.usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorIds = emptyList(), id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class UserService_UserQuery( + val usersByIds: List? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is null snapshot.kt new file mode 100644 index 000000000..9f43f781d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is null snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration input is null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration input is null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": null, + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": null + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": null + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is null.kt new file mode 100644 index 000000000..6cd1b5473 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration input is null.kt @@ -0,0 +1,97 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration input is null` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + usersQuery: UserQuery + } + type UserQuery { + usersByIds(ids: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + usersQuery: UserQuery + } + type User { + id: ID + name: String + } + type UserQuery { + usersByIds(ids: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "UserService" + field: "usersQuery.usersByIds" + arguments: [{name: "ids" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(authorIds = null, id = "ISSUE-1")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class UserService_UserQuery( + val usersByIds: List? = null, + ) + + private data class Issues_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration list with batching forwards error snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration list with batching forwards error snapshot.kt new file mode 100644 index 000000000..23d7119b0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration list with batching forwards error snapshot.kt @@ -0,0 +1,138 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration list with batching forwards error`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration list with batching forwards error snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__batch_hydration__bar: __typename + | batch_hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "batch_hydration__bar__barId": [ + | "barId1", + | "barId2", + | "barId3" + | ], + | "__typename__batch_hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barsQuery { + | barsById(id: ["barId1", "barId2", "barId3"]) { + | batch_hydration__bar__id: id + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "barsQuery": { + | "barsById": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Some error occurred", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": { + * "bar": [ + * null, + * null, + * null + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Some error occurred", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": { + | "bar": [ + | null, + | null, + | null + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration list with batching forwards error.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration list with batching forwards error.kt new file mode 100644 index 000000000..5e82f0708 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration list with batching forwards error.kt @@ -0,0 +1,117 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.execution.DataFetcherResult +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration list with batching forwards error` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barsQuery: BarsQuery + } + type BarsQuery { + barsById(id: [ID]): [Bar] + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type BarsQuery { + barsById(id: [ID]): [Bar] + } + type Query { + barsQuery: BarsQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barsQuery") { + Unit + } + } + wiring.type("BarsQuery") { type -> + type.dataFetcher("barsById") { env -> + DataFetcherResult + .newResult() + .data(null) + .errors( + listOf( + toGraphQLError( + mapOf( + "message" to "Some error occurred", + ), + ), + ), + ).build() + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: [Bar] + @hydrated( + service: "service2" + field: "barsQuery.barsById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: [ID] + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = listOf("barId1", "barId2", "barId3")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_BarsQuery( + val barsById: List? = null, + ) + + private data class Service1_Foo( + val barId: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration with renamed type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration with renamed type snapshot.kt new file mode 100644 index 000000000..740ceef00 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration with renamed type snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration with renamed type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration with renamed type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | bars { + | barById(id: "hydrated-bar") { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bars": { + | "barById": { + | "id": "hydrated-bar" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | rename__foo__fooOriginal: fooOriginal { + | __typename__hydration__fooBar: __typename + | hydration__fooBar__fooBarId: fooBarId + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__foo__fooOriginal": { + | "id": "Foo", + | "hydration__fooBar__fooBarId": "hydrated-bar", + | "__typename__hydration__fooBar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "id": "Foo", + * "fooBar": { + * "id": "hydrated-bar" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "id": "Foo", + | "fooBar": { + | "id": "hydrated-bar" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration with renamed type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration with renamed type.kt new file mode 100644 index 000000000..5c252c897 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration with renamed type.kt @@ -0,0 +1,106 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration with renamed type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + id + fooBar { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bars: BarQuery + } + type BarQuery { + barById(id: ID!): Bar + } + type Bar { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID! + } + type BarQuery { + barById(id: ID!): Bar + } + type Query { + bars: BarQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bars") { + Unit + } + } + wiring.type("BarQuery") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "hydrated-bar") { + Bar_Bar(id = "hydrated-bar") + } else { + null + } + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo @renamed(from: "fooOriginal") + } + type Foo { + id: ID! + fooBar: Bar + @hydrated( + service: "Bar" + field: "bars.barById" + arguments: [{name: "id" value: "${'$'}source.fooBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + fooBarId: ID + id: ID! + } + type Query { + fooOriginal: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("fooOriginal") { env -> + Foo_Foo(fooBarId = "hydrated-bar", id = "Foo") + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val id: String? = null, + ) + + private data class Bar_BarQuery( + val barById: Bar_Bar? = null, + ) + + private data class Foo_Foo( + val fooBarId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration works when an ancestor field has been renamed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration works when an ancestor field has been renamed snapshot.kt new file mode 100644 index 000000000..d81ba6a07 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration works when an ancestor field has been renamed snapshot.kt @@ -0,0 +1,121 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`synthetic hydration works when an ancestor field has been renamed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `synthetic hydration works when an ancestor field has been renamed snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | rename__devOpsRelationships__relationships: relationships { + | __typename__rename__devOpsNodes: __typename + | rename__devOpsNodes__nodes: nodes { + | __typename__hydration__devOpsIssue: __typename + | hydration__devOpsIssue__issueId: issueId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__devOpsRelationships__relationships": { + | "rename__devOpsNodes__nodes": [ + | { + | "hydration__devOpsIssue__issueId": "1", + | "__typename__hydration__devOpsIssue": "Relationship" + | } + | ], + | "__typename__rename__devOpsNodes": "RelationshipConnection" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | syntheticIssue { + | issue(id: "1") { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "syntheticIssue": { + | "issue": { + | "id": "1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "devOpsRelationships": { + * "devOpsNodes": [ + * { + * "devOpsIssue": { + * "id": "1" + * } + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "devOpsRelationships": { + | "devOpsNodes": [ + | { + | "devOpsIssue": { + | "id": "1" + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration works when an ancestor field has been renamed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration works when an ancestor field has been renamed.kt new file mode 100644 index 000000000..3e74fc881 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/synthetic hydration works when an ancestor field has been renamed.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `synthetic hydration works when an ancestor field has been renamed` : NadelLegacyIntegrationTest( + query = """ + query { + devOpsRelationships { + devOpsNodes { + devOpsIssue { + id + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type DevOpsIssue @renamed(from: "Issue") { + id: ID + } + type DevOpsRelationship @renamed(from: "Relationship") { + devOpsIssue: DevOpsIssue + @hydrated( + service: "IssueService" + field: "syntheticIssue.issue" + arguments: [{name: "id" value: "${'$'}source.issueId"}] + ) + } + type DevOpsRelationshipConnection @renamed(from: "RelationshipConnection") { + devOpsNodes: [DevOpsRelationship] @renamed(from: "nodes") + } + type SyntheticIssue { + devOpsIssue(id: ID): DevOpsIssue @renamed(from: "issue") + issue(id: ID): DevOpsIssue + } + type Query { + devOpsRelationships: DevOpsRelationshipConnection @renamed(from: "relationships") + syntheticIssue: SyntheticIssue + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + } + type Query { + relationships: RelationshipConnection + syntheticIssue: SyntheticIssue + } + type Relationship { + issueId: ID + } + type RelationshipConnection { + nodes: [Relationship] + } + type SyntheticIssue { + issue(id: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("syntheticIssue") { + Unit + } + } + wiring.type("Query") { type -> + type.dataFetcher("relationships") { env -> + IssueService_RelationshipConnection( + nodes = listOf( + IssueService_Relationship( + issueId = "1", + ), + ), + ) + } + } + + wiring.type("SyntheticIssue") { type -> + type.dataFetcher("issue") { env -> + if (env.getArgument("id") == "1") { + IssueService_Issue(id = "1") + } else { + null + } + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + ) + + private data class IssueService_Relationship( + val issueId: String? = null, + ) + + private data class IssueService_RelationshipConnection( + val nodes: List? = null, + ) + + private data class IssueService_SyntheticIssue( + val issue: IssueService_Issue? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in batched synthetic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in batched synthetic hydration snapshot.kt new file mode 100644 index 000000000..628ab19c4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in batched synthetic hydration snapshot.kt @@ -0,0 +1,188 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field data returns null in batched synthetic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field data returns null in batched synthetic hydration snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | users { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"]) { + | id + | batch_hydration__authors__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": { + | "usersByIds": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | users { + | usersByIds(id: ["USER-4", "USER-5"]) { + | id + | batch_hydration__authors__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": { + | "usersByIds": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * null, + * null + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * null + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * null, + * null, + * null + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | null, + | null + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | null + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | null, + | null, + | null + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in batched synthetic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in batched synthetic hydration.kt new file mode 100644 index 000000000..81b458941 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in batched synthetic hydration.kt @@ -0,0 +1,114 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field data returns null in batched synthetic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + users: UsersQuery + } + type UsersQuery { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: UsersQuery + } + type User { + id: ID + name: String + } + type UsersQuery { + usersByIds(id: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { + Unit + } + } + wiring.type("UsersQuery") { type -> + type.dataFetcher("usersByIds") { env -> + null + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "service2" + field: "users.usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Service1_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Service1_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Service1_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class Service2_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_UsersQuery( + val usersByIds: List? = null, + ) + + private data class Service1_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in synthetic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in synthetic hydration snapshot.kt new file mode 100644 index 000000000..d9d5dd732 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in synthetic hydration snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field data returns null in synthetic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field data returns null in synthetic hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | issue { + | __typename__hydration__project: __typename + | hydration__project__projectId: projectId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__project__projectId": "project1", + | "__typename__hydration__project": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | projects { + | project(id: "project1") { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "projects": { + | "project": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "project": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "project": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in synthetic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in synthetic hydration.kt new file mode 100644 index 000000000..a041ab574 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field data returns null in synthetic hydration.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field data returns null in synthetic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + project { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + projects: ProjectsQuery + } + type ProjectsQuery { + project(id: ID): Project + } + type Project { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Project { + id: ID + name: String + } + type ProjectsQuery { + project(id: ID): Project + } + type Query { + projects: ProjectsQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("projects") { + Unit + } + } + wiring.type("ProjectsQuery") { type -> + type.dataFetcher("project") { env -> + if (env.getArgument("id") == "project1") { + null + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID + project: Project + @hydrated( + service: "service2" + field: "projects.project" + arguments: [{name: "id" value: "${'$'}source.projectId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + projectId: ID + } + type Query { + issue(id: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Service1_Issue(projectId = "project1") + } + } + }, + ), + ), +) { + private data class Service2_Project( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_ProjectsQuery( + val project: Service2_Project? = null, + ) + + private data class Service1_Issue( + val id: String? = null, + val projectId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in batched synthetic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in batched synthetic hydration snapshot.kt new file mode 100644 index 000000000..7bed5bc6d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in batched synthetic hydration snapshot.kt @@ -0,0 +1,183 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field is null in batched synthetic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field is null in batched synthetic hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | issues { + | __typename__batch_hydration__authors: __typename + | batch_hydration__authors__authorIds: authorIds + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "batch_hydration__authors__authorIds": [ + | "USER-1", + | "USER-2" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-2", + | "batch_hydration__authors__authorIds": [ + | "USER-3" + | ], + | "__typename__batch_hydration__authors": "Issue" + | }, + | { + | "id": "ISSUE-3", + | "batch_hydration__authors__authorIds": [ + | "USER-2", + | "USER-4", + | "USER-5" + | ], + | "__typename__batch_hydration__authors": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | users { + | usersByIds(id: ["USER-1", "USER-2", "USER-3"]) { + | id + | batch_hydration__authors__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | users { + | usersByIds(id: ["USER-4", "USER-5"]) { + | id + | batch_hydration__authors__id: id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1", + * "authors": [ + * null, + * null + * ] + * }, + * { + * "id": "ISSUE-2", + * "authors": [ + * null + * ] + * }, + * { + * "id": "ISSUE-3", + * "authors": [ + * null, + * null, + * null + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1", + | "authors": [ + | null, + | null + | ] + | }, + | { + | "id": "ISSUE-2", + | "authors": [ + | null + | ] + | }, + | { + | "id": "ISSUE-3", + | "authors": [ + | null, + | null, + | null + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in batched synthetic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in batched synthetic hydration.kt new file mode 100644 index 000000000..574eea856 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in batched synthetic hydration.kt @@ -0,0 +1,113 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field is null in batched synthetic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + id + authors { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + users: UsersQuery + } + type UsersQuery { + usersByIds(id: [ID]): [User] + } + type User { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: UsersQuery + } + type User { + id: ID + name: String + } + type UsersQuery { + usersByIds(id: [ID]): [User] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { + null + } + } + wiring.type("UsersQuery") { type -> + type.dataFetcher("usersByIds") { env -> + null + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + authors: [User] + @hydrated( + service: "service2" + field: "users.usersByIds" + arguments: [{name: "id" value: "${'$'}source.authorIds"}] + identifiedBy: "id" + batchSize: 3 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorIds: [ID] + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Service1_Issue(authorIds = listOf("USER-1", "USER-2"), id = "ISSUE-1"), + Service1_Issue(authorIds = listOf("USER-3"), id = "ISSUE-2"), + Service1_Issue( + authorIds = listOf("USER-2", "USER-4", "USER-5"), + id = "ISSUE-3", + ), + ) + } + } + }, + ), + ), +) { + private data class Service2_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_UsersQuery( + val usersByIds: List? = null, + ) + + private data class Service1_Issue( + val authorIds: List? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in synthetic hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in synthetic hydration snapshot.kt new file mode 100644 index 000000000..19cd4e7b1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in synthetic hydration snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`top level field is null in synthetic hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `top level field is null in synthetic hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | issue { + | __typename__hydration__project: __typename + | hydration__project__projectId: projectId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "hydration__project__projectId": "project1", + | "__typename__hydration__project": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | projects { + | project(id: "project1") { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "projects": { + | "project": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "project": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "project": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in synthetic hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in synthetic hydration.kt new file mode 100644 index 000000000..086d34121 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/top level field is null in synthetic hydration.kt @@ -0,0 +1,108 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `top level field is null in synthetic hydration` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + project { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + projects: ProjectsQuery + } + type ProjectsQuery { + project(id: ID): Project + } + type Project { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Project { + id: ID + name: String + } + type ProjectsQuery { + project(id: ID): Project + } + type Query { + projects: ProjectsQuery + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("projects") { + Unit + } + } + wiring.type("ProjectsQuery") { type -> + type.dataFetcher("project") { env -> + if (env.getArgument("id") == "project1") { + null + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + issue(id: ID): Issue + } + type Issue { + id: ID + project: Project + @hydrated( + service: "service2" + field: "projects.project" + arguments: [{name: "id" value: "${'$'}source.projectId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + projectId: ID + } + type Query { + issue(id: ID): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Service1_Issue(projectId = "project1") + } + } + }, + ), + ), +) { + private data class Service2_Project( + val id: String? = null, + val name: String? = null, + ) + + private data class Service2_ProjectsQuery( + val project: Service2_Project? = null, + ) + + private data class Service1_Issue( + val id: String? = null, + val projectId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/transformer on hydration fields snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/transformer on hydration fields snapshot.kt new file mode 100644 index 000000000..e5184b970 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/transformer on hydration fields snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`transformer on hydration fields`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `transformer on hydration fields snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "transformed-id") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "name": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "name": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "name": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/transformer on hydration fields.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/transformer on hydration fields.kt new file mode 100644 index 000000000..520721943 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/new hydration/transformer on hydration fields.kt @@ -0,0 +1,93 @@ +package graphql.nadel.tests.legacy.`new hydration` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `transformer on hydration fields` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "transformed-id") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) + + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when invalid variables are passed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when invalid variables are passed snapshot.kt new file mode 100644 index 000000000..40d56b414 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when invalid variables are passed snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`oneOf fails when invalid variables are passed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `oneOf fails when invalid variables are passed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Validation error (WrongType@[search]) : Exactly one key must be specified + * for OneOf type 'SearchInput'.", + * "locations": [ + * { + * "line": 2, + * "column": 10 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ] + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Validation error (WrongType@[search]) : Exactly one key must be specified for OneOf type 'SearchInput'.", + | "locations": [ + | { + | "line": 2, + | "column": 10 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ] + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when invalid variables are passed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when invalid variables are passed.kt new file mode 100644 index 000000000..78d70ed30 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when invalid variables are passed.kt @@ -0,0 +1,42 @@ +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `oneOf fails when invalid variables are passed` : NadelLegacyIntegrationTest( + query = """ + query myQuery(${'$'}name: String, ${'$'}id: ID) { + search(by: {name: ${'$'}name, id: ${'$'}id}) + } + """.trimIndent(), + variables = mapOf("name" to "Figaro"), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + search(by: SearchInput!): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + search(by: SearchInput!): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_SearchInput( + val name: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when nested input snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when nested input snapshot.kt new file mode 100644 index 000000000..68e0d7481 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when nested input snapshot.kt @@ -0,0 +1,58 @@ +// @formatter:off +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`oneOf fails when nested input`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `oneOf fails when nested input snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "OneOf type field 'IdInput.email' must be non-null.", + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "OneOf type field 'IdInput.email' must be non-null.", + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when nested input.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when nested input.kt new file mode 100644 index 000000000..0fb473a79 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when nested input.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `oneOf fails when nested input` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + search(by: {id: {email: null}}) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput { + name: String + id: IdInput + } + input IdInput @oneOf { + email: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput { + name: String + id: IdInput + } + input IdInput @oneOf { + email: String + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_IdInput( + val email: String? = null, + val id: String? = null, + ) + + private data class MyService_SearchInput( + val name: String? = null, + val id: MyService_IdInput? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when no values are passed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when no values are passed snapshot.kt new file mode 100644 index 000000000..d14cbbf38 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when no values are passed snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`oneOf fails when no values are passed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `oneOf fails when no values are passed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Validation error (WrongType@[search]) : Exactly one key must be specified + * for OneOf type 'SearchInput'.", + * "locations": [ + * { + * "line": 2, + * "column": 10 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ] + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Validation error (WrongType@[search]) : Exactly one key must be specified for OneOf type 'SearchInput'.", + | "locations": [ + | { + | "line": 2, + | "column": 10 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ] + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when no values are passed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when no values are passed.kt new file mode 100644 index 000000000..e32ada747 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when no values are passed.kt @@ -0,0 +1,42 @@ +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `oneOf fails when no values are passed` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + search(by: {}) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_SearchInput( + val name: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when null value is passed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when null value is passed snapshot.kt new file mode 100644 index 000000000..db0e6086f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when null value is passed snapshot.kt @@ -0,0 +1,58 @@ +// @formatter:off +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`oneOf fails when null value is passed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `oneOf fails when null value is passed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "OneOf type field 'SearchInput.name' must be non-null.", + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "OneOf type field 'SearchInput.name' must be non-null.", + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when null value is passed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when null value is passed.kt new file mode 100644 index 000000000..ddf923f21 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when null value is passed.kt @@ -0,0 +1,42 @@ +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `oneOf fails when null value is passed` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + search(by: {name: null}) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_SearchInput( + val name: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when values are passed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when values are passed snapshot.kt new file mode 100644 index 000000000..95b71367c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when values are passed snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`oneOf fails when values are passed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `oneOf fails when values are passed snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Validation error (WrongType@[search]) : Exactly one key must be specified + * for OneOf type 'SearchInput'.", + * "locations": [ + * { + * "line": 2, + * "column": 10 + * } + * ], + * "extensions": { + * "classification": "ValidationError" + * } + * } + * ] + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Validation error (WrongType@[search]) : Exactly one key must be specified for OneOf type 'SearchInput'.", + | "locations": [ + | { + | "line": 2, + | "column": 10 + | } + | ], + | "extensions": { + | "classification": "ValidationError" + | } + | } + | ] + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when values are passed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when values are passed.kt new file mode 100644 index 000000000..d40e5c6df --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf fails when values are passed.kt @@ -0,0 +1,42 @@ +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `oneOf fails when values are passed` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + search(by: {name: "Figaro", id: "1001"}) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + search(by: SearchInput!): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + search(by: SearchInput!): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class MyService_SearchInput( + val name: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf successful snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf successful snapshot.kt new file mode 100644 index 000000000..97c1d3d17 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf successful snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`oneOf successful`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `oneOf successful snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query myQuery { + | search(by: {name : "Figaro"}) + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "search": "Figaro" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "search": "Figaro" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "search": "Figaro" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf successful.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf successful.kt new file mode 100644 index 000000000..395dcc1a9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/oneOf/oneOf successful.kt @@ -0,0 +1,51 @@ +package graphql.nadel.tests.legacy.oneOf + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `oneOf successful` : NadelLegacyIntegrationTest( + query = """ + query myQuery { + search(by: {name: "Figaro"}) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + search(by: SearchInput): String + } + input SearchInput @oneOf { + name: String + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("search") { env -> + if (env.getArgument("by") == mapOf("name" to "Figaro")) { + "Figaro" + } else { + null + } + } + } + }, + ), + ), +) { + private data class MyService_SearchInput( + val name: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/fragment referenced twice from inside query and inside another fragment snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/fragment referenced twice from inside query and inside another fragment snapshot.kt new file mode 100644 index 000000000..5e8ac9909 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/fragment referenced twice from inside query and inside another fragment snapshot.kt @@ -0,0 +1,73 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`fragment referenced twice from inside query and inside another fragment`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `fragment referenced twice from inside query and inside another fragment snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "id": "ID" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "id": "ID" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "id": "ID" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/fragment referenced twice from inside query and inside another fragment.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/fragment referenced twice from inside query and inside another fragment.kt new file mode 100644 index 000000000..162030532 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/fragment referenced twice from inside query and inside another fragment.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `fragment referenced twice from inside query and inside another fragment` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + id + ...F2 + ...F1 + } + } + fragment F2 on Bar { + id + } + fragment F1 on Bar { + id + ...F2 + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Bar + } + type Bar { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: String + } + type Query { + foo: Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Foo_Bar(id = "ID") + } + } + }, + ), + ), +) { + private data class Foo_Bar( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields get typename added snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields get typename added snapshot.kt new file mode 100644 index 000000000..22b49346b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields get typename added snapshot.kt @@ -0,0 +1,108 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`lower level interface fields get typename added`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `lower level interface fields get typename added snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | collar { + | color + | } + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "collar": { + | "color": "blue" + | } + | }, + | { + | "name": "Whiskers", + | "collar": { + | "color": "red" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "collar": { + * "color": "blue" + * } + * }, + * { + * "name": "Whiskers", + * "collar": { + * "color": "red" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "collar": { + | "color": "blue" + | } + | }, + | { + | "name": "Whiskers", + | "collar": { + | "color": "red" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields get typename added.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields get typename added.kt new file mode 100644 index 000000000..e69b69b86 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields get typename added.kt @@ -0,0 +1,244 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `lower level interface fields get typename added` : NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + collar { + color + } + } + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(collar = PetService_DogCollar(color = "blue"), name = "Sparky"), + PetService_Cat(collar = PetService_CatCollar(color = "red"), name = "Whiskers"), + ) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields which are renamed get typename added snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields which are renamed get typename added snapshot.kt new file mode 100644 index 000000000..a111e4fb2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields which are renamed get typename added snapshot.kt @@ -0,0 +1,119 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`lower level interface fields which are renamed get typename added`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `lower level interface fields which are renamed get typename added snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | __typename__rename__collarToRenamed: __typename + | name + | ... on Cat { + | rename__collarToRenamed__collar: collar { + | color + | } + | } + | ... on Dog { + | rename__collarToRenamed__collar: collar { + | color + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "__typename__rename__collarToRenamed": "Dog", + | "rename__collarToRenamed__collar": { + | "color": "blue" + | } + | }, + | { + | "name": "Whiskers", + | "__typename__rename__collarToRenamed": "Cat", + | "rename__collarToRenamed__collar": { + | "color": "red" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "collarToRenamed": { + * "color": "blue" + * } + * }, + * { + * "name": "Whiskers", + * "collarToRenamed": { + * "color": "red" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "collarToRenamed": { + | "color": "blue" + | } + | }, + | { + | "name": "Whiskers", + | "collarToRenamed": { + | "color": "red" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields which are renamed get typename added.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields which are renamed get typename added.kt new file mode 100644 index 000000000..f3e575c37 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/lower level interface fields which are renamed get typename added.kt @@ -0,0 +1,244 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `lower level interface fields which are renamed get typename added` : NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + collarToRenamed { + color + } + } + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", collar = PetService_DogCollar(color = "blue")), + PetService_Cat(name = "Whiskers", collar = PetService_CatCollar(color = "red")), + ) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that DONT have typename in them work as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that DONT have typename in them work as expected snapshot.kt new file mode 100644 index 000000000..f9d9af702 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that DONT have typename in them work as expected snapshot.kt @@ -0,0 +1,134 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with pass through interfaces and unions that DONT have typename in them work as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with pass through interfaces and unions that DONT have typename in them work as expected snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | name + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "wearsCollar": true + | }, + | { + | "name": "Whiskers", + | "wearsBell": false + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | raining(isLoyal: true) { + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "raining": { + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "wearsCollar": true + * }, + * { + * "name": "Whiskers", + * "wearsBell": false + * } + * ], + * "raining": { + * "wearsCollar": true + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "wearsCollar": true + | }, + | { + | "name": "Whiskers", + | "wearsBell": false + | } + | ], + | "raining": { + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that DONT have typename in them work as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that DONT have typename in them work as expected.kt new file mode 100644 index 000000000..876ba9c12 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that DONT have typename in them work as expected.kt @@ -0,0 +1,267 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with pass through interfaces and unions that DONT have typename in them work as expected` : + NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + ... on Dog { + wearsCollar + } + ... on Cat { + wearsBell + } + } + raining(isLoyal: ${'$'}isLoyal) { + ... on Dog { + wearsCollar + } + ... on Cat { + wearsBell + } + } + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("raining") { env -> + if (env.getArgument("isLoyal") == true) { + PetService_Dog(wearsCollar = true) + } else { + null + } + } + .dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", wearsCollar = true), + PetService_Cat( + name = "Whiskers", + wearsBell = false, + ), + ) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), + ) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have MIXED typename in them work as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have MIXED typename in them work as expected snapshot.kt new file mode 100644 index 000000000..164d6607d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have MIXED typename in them work as expected snapshot.kt @@ -0,0 +1,142 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with pass through interfaces and unions that have MIXED typename in them work as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with pass through interfaces and unions that have MIXED typename in them work as expected snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | name + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | __typename + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "wearsCollar": true, + | "__typename": "Dog" + | }, + | { + | "name": "Whiskers", + | "wearsBell": false + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | raining(isLoyal: true) { + | __typename + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "raining": { + | "__typename": "Dog", + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "wearsCollar": true, + * "__typename": "Dog" + * }, + * { + * "name": "Whiskers", + * "wearsBell": false + * } + * ], + * "raining": { + * "__typename": "Dog", + * "wearsCollar": true + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "wearsCollar": true, + | "__typename": "Dog" + | }, + | { + | "name": "Whiskers", + | "wearsBell": false + | } + | ], + | "raining": { + | "__typename": "Dog", + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have MIXED typename in them work as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have MIXED typename in them work as expected.kt new file mode 100644 index 000000000..c6aee043a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have MIXED typename in them work as expected.kt @@ -0,0 +1,269 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with pass through interfaces and unions that have MIXED typename in them work as expected` : + NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + ... on Dog { + wearsCollar + __typename + } + ... on Cat { + wearsBell + } + } + raining(isLoyal: ${'$'}isLoyal) { + __typename + ... on Dog { + wearsCollar + } + ... on Cat { + wearsBell + } + } + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", wearsCollar = true), + PetService_Cat( + name = "Whiskers", + wearsBell = false, + ), + ) + } else { + null + } + } + .dataFetcher("raining") { env -> + if (env.getArgument("isLoyal") == true) { + PetService_Dog(wearsCollar = true) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), + ) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have aliased typename in fragments work as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have aliased typename in fragments work as expected snapshot.kt new file mode 100644 index 000000000..e2626b1ea --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have aliased typename in fragments work as expected snapshot.kt @@ -0,0 +1,109 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with pass through interfaces and unions that have aliased typename in fragments work as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with pass through interfaces and unions that have aliased typename in fragments work as expected snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | name + | ... on Cat { + | aliasedCatTypeName: __typename + | wearsBell + | } + | ... on Dog { + | aliasedDogTypeName: __typename + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "wearsCollar": true, + | "aliasedDogTypeName": "Dog" + | }, + | { + | "name": "Whiskers", + | "wearsBell": false, + | "aliasedCatTypeName": "Cat" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "wearsCollar": true, + * "aliasedDogTypeName": "Dog" + * }, + * { + * "name": "Whiskers", + * "wearsBell": false, + * "aliasedCatTypeName": "Cat" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "wearsCollar": true, + | "aliasedDogTypeName": "Dog" + | }, + | { + | "name": "Whiskers", + | "wearsBell": false, + | "aliasedCatTypeName": "Cat" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have aliased typename in fragments work as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have aliased typename in fragments work as expected.kt new file mode 100644 index 000000000..952e45201 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have aliased typename in fragments work as expected.kt @@ -0,0 +1,254 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with pass through interfaces and unions that have aliased typename in fragments work as expected` : + NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + ...DogFrag + ... on Cat { + wearsBell + aliasedCatTypeName: __typename + } + } + } + fragment DogFrag on Dog { + wearsCollar + aliasedDogTypeName: __typename + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", wearsCollar = true), + PetService_Cat( + name = "Whiskers", + wearsBell = false, + ), + ) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), + ) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in fragments work as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in fragments work as expected snapshot.kt new file mode 100644 index 000000000..089718e70 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in fragments work as expected snapshot.kt @@ -0,0 +1,145 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with pass through interfaces and unions that have typename in fragments work as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with pass through interfaces and unions that have typename in fragments work as expected snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | __typename + | name + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "__typename": "Dog", + | "wearsCollar": true + | }, + | { + | "name": "Whiskers", + | "__typename": "Cat", + | "wearsBell": false + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | raining(isLoyal: true) { + | __typename + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "raining": { + | "__typename": "Dog", + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "__typename": "Dog", + * "wearsCollar": true + * }, + * { + * "name": "Whiskers", + * "__typename": "Cat", + * "wearsBell": false + * } + * ], + * "raining": { + * "__typename": "Dog", + * "wearsCollar": true + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "__typename": "Dog", + | "wearsCollar": true + | }, + | { + | "name": "Whiskers", + | "__typename": "Cat", + | "wearsBell": false + | } + | ], + | "raining": { + | "__typename": "Dog", + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in fragments work as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in fragments work as expected.kt new file mode 100644 index 000000000..9ea2e39bc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in fragments work as expected.kt @@ -0,0 +1,276 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with pass through interfaces and unions that have typename in fragments work as expected` : + NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + ...DogFrag + ... on Dog { + wearsCollar + __typename + } + ... on Cat { + wearsBell + __typename + } + } + raining(isLoyal: ${'$'}isLoyal) { + ... on Dog { + wearsCollar + __typename + } + ... on Cat { + wearsBell + __typename + } + } + } + fragment DogFrag on Dog { + wearsCollar + __typename + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", wearsCollar = true), + PetService_Cat( + name = "Whiskers", + wearsBell = false, + ), + ) + } else { + null + } + } + .dataFetcher("raining") { env -> + if (env.getArgument("isLoyal") == true) { + PetService_Dog(wearsCollar = true) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), + ) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in them work as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in them work as expected snapshot.kt new file mode 100644 index 000000000..3d2b51d9d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in them work as expected snapshot.kt @@ -0,0 +1,145 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query with pass through interfaces and unions that have typename in them work as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class + `query with pass through interfaces and unions that have typename in them work as expected snapshot` + : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | pets(isLoyal: true) { + | __typename + | name + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "__typename": "Dog", + | "wearsCollar": true + | }, + | { + | "name": "Whiskers", + | "__typename": "Cat", + | "wearsBell": false + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "PetService", + query = """ + | query petQ { + | raining(isLoyal: true) { + | __typename + | ... on Cat { + | wearsBell + | } + | ... on Dog { + | wearsCollar + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "raining": { + | "__typename": "Dog", + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "pets": [ + * { + * "name": "Sparky", + * "__typename": "Dog", + * "wearsCollar": true + * }, + * { + * "name": "Whiskers", + * "__typename": "Cat", + * "wearsBell": false + * } + * ], + * "raining": { + * "__typename": "Dog", + * "wearsCollar": true + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "pets": [ + | { + | "name": "Sparky", + | "__typename": "Dog", + | "wearsCollar": true + | }, + | { + | "name": "Whiskers", + | "__typename": "Cat", + | "wearsBell": false + | } + | ], + | "raining": { + | "__typename": "Dog", + | "wearsCollar": true + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in them work as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in them work as expected.kt new file mode 100644 index 000000000..5f8cc036f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/query with pass through interfaces and unions that have typename in them work as expected.kt @@ -0,0 +1,270 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query with pass through interfaces and unions that have typename in them work as expected` : + NadelLegacyIntegrationTest( + query = """ + query petQ(${'$'}isLoyal: Boolean) { + pets(isLoyal: ${'$'}isLoyal) { + name + __typename + ... on Dog { + wearsCollar + __typename + } + ... on Cat { + wearsBell + } + } + raining(isLoyal: ${'$'}isLoyal) { + __typename + ... on Dog { + wearsCollar + } + ... on Cat { + wearsBell + } + } + } + """.trimIndent(), + variables = mapOf("isLoyal" to true), + services = listOf( + Service( + name = "PetService", + overallSchema = """ + type Query { + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + interface Pet { + name: String + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Cat implements Pet { + name: String + wearsBell: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + type Dog implements Pet { + name: String + wearsCollar: Boolean + collar: Collar + collarToRenamed: Collar @renamed(from: "collar") + } + union CatsAndDogs = Cat | Dog + interface Collar { + color: String + size: String + } + type DogCollar implements Collar { + color: String + size: String + } + type CatCollar implements Collar { + color: String + size: String + } + """.trimIndent(), + underlyingSchema = """ + interface Collar { + color: String + size: String + } + interface Pet { + collar: Collar + name: String + ownerIds: [String] + } + union CatsAndDogs = Cat | Dog + type Cat implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsBell: Boolean + } + type CatCollar implements Collar { + color: String + size: String + } + type Dog implements Pet { + collar: Collar + name: String + ownerIds: [String] + wearsCollar: Boolean + } + type DogCollar implements Collar { + color: String + size: String + } + type Mutation { + hello: String + } + type Query { + hello: World + pets(isLoyal: Boolean): [Pet] + raining(isLoyal: Boolean): CatsAndDogs + } + type World { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("raining") { env -> + if (env.getArgument("isLoyal") == true) { + PetService_Dog(wearsCollar = true) + } else { + null + } + } + .dataFetcher("pets") { env -> + if (env.getArgument("isLoyal") == true) { + listOf( + PetService_Dog(name = "Sparky", wearsCollar = true), + PetService_Cat( + name = "Whiskers", + wearsBell = false, + ), + ) + } else { + null + } + } + } + wiring.type("CatsAndDogs") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Collar") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("Pet") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "OwnerService", + overallSchema = """ + type Query { + owner(id: String): Owner + } + interface Owner { + name: String + } + type CaringOwner implements Owner { + name: String + givesPats: Boolean + } + type CruelOwner implements Owner { + name: String + givesSmacks: Boolean + } + """.trimIndent(), + underlyingSchema = """ + interface Owner { + name: String + } + type CaringOwner implements Owner { + givesPats: Boolean + name: String + } + type CruelOwner implements Owner { + givesSmacks: Boolean + name: String + } + type Query { + owner(id: String): Owner + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Owner") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), + ) { + private data class PetService_Cat( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsBell: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_CatCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private sealed interface PetService_CatsAndDogs + + private interface PetService_Collar { + val color: String? + + val size: String? + } + + private data class PetService_Dog( + override val collar: PetService_Collar? = null, + override val name: String? = null, + override val ownerIds: List? = null, + val wearsCollar: Boolean? = null, + ) : PetService_Pet, + PetService_CatsAndDogs + + private data class PetService_DogCollar( + override val color: String? = null, + override val size: String? = null, + ) : PetService_Collar + + private interface PetService_Pet { + val collar: PetService_Collar? + + val name: String? + + val ownerIds: List? + } + + private data class PetService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class OwnerService_CaringOwner( + val givesPats: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private data class OwnerService_CruelOwner( + val givesSmacks: Boolean? = null, + override val name: String? = null, + ) : OwnerService_Owner + + private interface OwnerService_Owner { + val name: String? + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/two top level fields with a fragment snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/two top level fields with a fragment snapshot.kt new file mode 100644 index 000000000..2e268b4ce --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/two top level fields with a fragment snapshot.kt @@ -0,0 +1,119 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`two top level fields with a fragment`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `two top level fields with a fragment snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1" + | }, + | { + | "id": "ISSUE-2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | user { + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "user": { + | "id": "USER-1", + | "name": "User 1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "id": "ISSUE-1" + * }, + * { + * "id": "ISSUE-2" + * } + * ], + * "user": { + * "id": "USER-1", + * "name": "User 1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "id": "ISSUE-1" + | }, + | { + | "id": "ISSUE-2" + | } + | ], + | "user": { + | "id": "USER-1", + | "name": "User 1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/two top level fields with a fragment.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/two top level fields with a fragment.kt new file mode 100644 index 000000000..d71da9e48 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/two top level fields with a fragment.kt @@ -0,0 +1,91 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `two top level fields with a fragment` : NadelLegacyIntegrationTest( + query = """ + fragment I on Issue { + id + } + fragment U on User { + id + name + } + query { + issues { + ...I + } + user { + ...U + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "UserService", + overallSchema = """ + type Query { + user: User + } + type User { + id: ID + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + user: User + } + type User { + id: ID + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("user") { env -> + UserService_User(id = "USER-1", name = "User 1") + } + } + }, + ), + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + authorId: ID + id: ID + } + type Query { + issues: [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(Issues_Issue(id = "ISSUE-1"), Issues_Issue(id = "ISSUE-2")) + } + } + }, + ), + ), +) { + private data class UserService_User( + val id: String? = null, + val name: String? = null, + ) + + private data class Issues_Issue( + val authorId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/typename is correctly passed on and artificial typename is removed snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/typename is correctly passed on and artificial typename is removed snapshot.kt new file mode 100644 index 000000000..bbbcc08e3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/typename is correctly passed on and artificial typename is removed snapshot.kt @@ -0,0 +1,119 @@ +// @formatter:off +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`typename is correctly passed on and artificial typename is removed`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `typename is correctly passed on and artificial typename is removed snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issues { + | __typename + | id + | ... on Issue { + | authorIds + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "__typename": "Issue", + | "id": "ISSUE-1", + | "authorIds": [ + | "USER-1", + | "USER-2" + | ] + | }, + | { + | "__typename": "Issue", + | "id": "ISSUE-2", + | "authorIds": [ + | "USER-3" + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "__typename": "Issue", + * "id": "ISSUE-1", + * "authorIds": [ + * "USER-1", + * "USER-2" + * ] + * }, + * { + * "__typename": "Issue", + * "id": "ISSUE-2", + * "authorIds": [ + * "USER-3" + * ] + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "__typename": "Issue", + | "id": "ISSUE-1", + | "authorIds": [ + | "USER-1", + | "USER-2" + | ] + | }, + | { + | "__typename": "Issue", + | "id": "ISSUE-2", + | "authorIds": [ + | "USER-3" + | ] + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/typename is correctly passed on and artificial typename is removed.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/typename is correctly passed on and artificial typename is removed.kt new file mode 100644 index 000000000..5f4de3ca6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/polymorphism/typename is correctly passed on and artificial typename is removed.kt @@ -0,0 +1,73 @@ +package graphql.nadel.tests.legacy.polymorphism + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `typename is correctly passed on and artificial typename is removed` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + __typename + id + ... on Issue { + authorIds + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issues: [AbstractIssue] + } + interface AbstractIssue { + id: ID + } + type Issue implements AbstractIssue { + id: ID + authorIds: [ID] + } + """.trimIndent(), + underlyingSchema = """ + interface AbstractIssue { + id: ID + } + type Issue implements AbstractIssue { + authorIds: [ID] + id: ID + } + type Query { + issues: [AbstractIssue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf( + Issues_Issue(id = "ISSUE-1", authorIds = listOf("USER-1", "USER-2")), + Issues_Issue(id = "ISSUE-2", authorIds = listOf("USER-3")), + ) + } + } + wiring.type("AbstractIssue") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface Issues_AbstractIssue { + val id: String? + } + + private data class Issues_Issue( + val authorIds: List? = null, + override val id: String? = null, + ) : Issues_AbstractIssue +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/a lot of renames snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/a lot of renames snapshot.kt new file mode 100644 index 000000000..40183cba7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/a lot of renames snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`a lot of renames`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `a lot of renames snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Boards", + query = """ + | { + | boardScope { + | __typename__rename__cardParents: __typename + | rename__cardParents__issueParents: issueParents { + | __typename__rename__cardType: __typename + | rename__cardType__issueType: issueType { + | __typename__rename__inlineCardCreate: __typename + | id + | rename__inlineCardCreate__inlineIssueCreate: inlineIssueCreate { + | enabled + | } + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "boardScope": { + | "rename__cardParents__issueParents": [ + | { + | "rename__cardType__issueType": { + | "id": "ID-1", + | "rename__inlineCardCreate__inlineIssueCreate": { + | "enabled": true + | }, + | "__typename__rename__inlineCardCreate": "IssueType" + | }, + | "__typename__rename__cardType": "IssueParent" + | } + | ], + | "__typename__rename__cardParents": "BoardScope" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "boardScope": { + * "cardParents": [ + * { + * "cardType": { + * "id": "ID-1", + * "inlineCardCreate": { + * "enabled": true + * } + * } + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "boardScope": { + | "cardParents": [ + | { + | "cardType": { + | "id": "ID-1", + | "inlineCardCreate": { + | "enabled": true + | } + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/a lot of renames.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/a lot of renames.kt new file mode 100644 index 000000000..e4894b2d6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/a lot of renames.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `a lot of renames` : NadelLegacyIntegrationTest( + query = """ + query { + boardScope { + cardParents { + cardType { + id + inlineCardCreate { + enabled + } + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Boards", + overallSchema = """ + type Query { + boardScope: BoardScope + } + type BoardScope { + cardParents: [CardParent]! @renamed(from: "issueParents") + } + type CardParent @renamed(from: "IssueParent") { + cardType: CardType! @renamed(from: "issueType") + } + type CardType @renamed(from: "IssueType") { + id: ID + inlineCardCreate: InlineCardCreateConfig @renamed(from: "inlineIssueCreate") + } + type InlineCardCreateConfig @renamed(from: "InlineIssueCreateConfig") { + enabled: Boolean! + } + """.trimIndent(), + underlyingSchema = """ + type BoardScope { + issueParents: [IssueParent]! + } + type InlineIssueCreateConfig { + enabled: Boolean! + } + type IssueParent { + issueType: IssueType! + } + type IssueType { + id: ID + inlineIssueCreate: InlineIssueCreateConfig + } + type Query { + boardScope: BoardScope + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("boardScope") { env -> + Boards_BoardScope( + issueParents = listOf( + Boards_IssueParent( + issueType = Boards_IssueType( + id = "ID-1", + inlineIssueCreate = Boards_InlineIssueCreateConfig(enabled = true), + ), + ), + ), + ) + } + } + }, + ), + ), +) { + private data class Boards_BoardScope( + val issueParents: List? = null, + ) + + private data class Boards_InlineIssueCreateConfig( + val enabled: Boolean? = null, + ) + + private data class Boards_IssueParent( + val issueType: Boards_IssueType? = null, + ) + + private data class Boards_IssueType( + val id: String? = null, + val inlineIssueCreate: Boards_InlineIssueCreateConfig? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform snapshot.kt new file mode 100644 index 000000000..7156c63b5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`chain rename transform`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `chain rename transform snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__test__world: world(arg: "aaarrg") { + | __typename + | __typename__rename__cities: __typename + | id + | rename__cities__places: places(continent: Asia) + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__test__world": { + | "__typename": "World", + | "id": "Earth", + | "rename__cities__places": [ + | "Uhh yea I know cities" + | ], + | "__typename__rename__cities": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": { + * "__typename": "World", + * "id": "Earth", + * "cities": [ + * "Uhh yea I know cities" + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": { + | "__typename": "World", + | "id": "Earth", + | "cities": [ + | "Uhh yea I know cities" + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform with type rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform with type rename snapshot.kt new file mode 100644 index 000000000..a35c682bc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform with type rename snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`chain rename transform with type rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `chain rename transform with type rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__test__world: world(arg: "aaarrg") { + | __typename + | __typename__rename__cities: __typename + | id + | rename__cities__places: places(continent: Asia) + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__test__world": { + | "__typename": "World", + | "id": "Earth", + | "rename__cities__places": [ + | "Uhh yea I know cities" + | ], + | "__typename__rename__cities": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "test": { + * "__typename": "Test", + * "id": "Earth", + * "cities": [ + * "Uhh yea I know cities" + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "test": { + | "__typename": "Test", + | "id": "Earth", + | "cities": [ + | "Uhh yea I know cities" + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform with type rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform with type rename.kt new file mode 100644 index 000000000..204d196af --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform with type rename.kt @@ -0,0 +1,83 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `chain rename transform with type rename` : NadelLegacyIntegrationTest( + query = """ + query { + test(arg: "Hello World") { + __typename + id + cities(continent: Oceania) + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + test(arg: String): Test @renamed(from: "world") + } + type Test @renamed(from: "World") { + id: ID + cities(continent: Continent): [String] @renamed(from: "places") + } + enum Continent { + Africa + Antarctica + Asia + Oceania + Europe + NorthAmerica + SouthAmerica + } + """.trimIndent(), + underlyingSchema = """ + type Query { + world(arg: String): World + } + type World { + id: ID + places(continent: Continent): [String] + } + enum Continent { + Africa + Antarctica + Asia + Oceania + Europe + NorthAmerica + SouthAmerica + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("world") { env -> + if (env.getArgument("arg") == "aaarrg") { + MyService_World(id = "Earth", places = listOf("Uhh yea I know cities")) + } else { + null + } + } + } + }, + ), + ), +) { + private enum class MyService_Continent { + Africa, + Antarctica, + Asia, + Oceania, + Europe, + NorthAmerica, + SouthAmerica, + } + + private data class MyService_World( + val id: String? = null, + val places: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform.kt new file mode 100644 index 000000000..caa77315d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/chain rename transform.kt @@ -0,0 +1,83 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `chain rename transform` : NadelLegacyIntegrationTest( + query = """ + query { + test(arg: "Hello World") { + __typename + id + cities(continent: Oceania) + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + test(arg: String): World @renamed(from: "world") + } + type World { + id: ID + cities(continent: Continent): [String] @renamed(from: "places") + } + enum Continent { + Africa + Antarctica + Asia + Oceania + Europe + NorthAmerica + SouthAmerica + } + """.trimIndent(), + underlyingSchema = """ + type Query { + world(arg: String): World + } + type World { + id: ID + places(continent: Continent): [String] + } + enum Continent { + Africa + Antarctica + Asia + Oceania + Europe + NorthAmerica + SouthAmerica + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("world") { env -> + if (env.getArgument("arg") == "aaarrg") { + MyService_World(id = "Earth", places = listOf("Uhh yea I know cities")) + } else { + null + } + } + } + }, + ), + ), +) { + private enum class MyService_Continent { + Africa, + Antarctica, + Asia, + Oceania, + Europe, + NorthAmerica, + SouthAmerica, + } + + private data class MyService_World( + val id: String? = null, + val places: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/correct typename is returned snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/correct typename is returned snapshot.kt new file mode 100644 index 000000000..966f89ed2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/correct typename is returned snapshot.kt @@ -0,0 +1,111 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`correct typename is returned`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `correct typename is returned snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | typenameTest { + | __typename + | object { + | __typename + | } + | objects { + | __typename + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "typenameTest": { + | "__typename": "TypenameTest", + | "object": { + | "__typename": "ObjectUnderlying" + | }, + | "objects": [ + | { + | "__typename": "ObjectUnderlying" + | }, + | { + | "__typename": "ObjectUnderlying" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "typenameTest": { + * "__typename": "TypenameTest", + * "object": { + * "__typename": "ObjectOverall" + * }, + * "objects": [ + * { + * "__typename": "ObjectOverall" + * }, + * { + * "__typename": "ObjectOverall" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "typenameTest": { + | "__typename": "TypenameTest", + | "object": { + | "__typename": "ObjectOverall" + | }, + | "objects": [ + | { + | "__typename": "ObjectOverall" + | }, + | { + | "__typename": "ObjectOverall" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/correct typename is returned.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/correct typename is returned.kt new file mode 100644 index 000000000..a8eb2cb10 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/correct typename is returned.kt @@ -0,0 +1,165 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `correct typename is returned` : NadelLegacyIntegrationTest( + query = """ + query { + typenameTest { + __typename + object { + __typename + } + objects { + __typename + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("typenameTest") { env -> + MyService_TypenameTest( + `object` = MyService_ObjectUnderlying(), + objects = listOf(MyService_ObjectUnderlying(), MyService_ObjectUnderlying()), + ) + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/fragment type rename and field rename works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/fragment type rename and field rename works as expected snapshot.kt new file mode 100644 index 000000000..21a01c5df --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/fragment type rename and field rename works as expected snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`fragment type rename and field rename works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `fragment type rename and field rename works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameObject__renameObjectUnderlying: renameObjectUnderlying { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameObject__renameObjectUnderlying": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameObject": { + * "name": "val" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameObject": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/fragment type rename and field rename works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/fragment type rename and field rename works as expected.kt new file mode 100644 index 000000000..5c5848495 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/fragment type rename and field rename works as expected.kt @@ -0,0 +1,159 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `fragment type rename and field rename works as expected` : NadelLegacyIntegrationTest( + query = """ + query { + renameObject { + ...FragDef + } + } + fragment FragDef on ObjectOverall { + name + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameObjectUnderlying") { env -> + MyService_ObjectUnderlying(name = "val") + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/inline fragment type rename and field rename works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/inline fragment type rename and field rename works as expected snapshot.kt new file mode 100644 index 000000000..ece9b2128 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/inline fragment type rename and field rename works as expected snapshot.kt @@ -0,0 +1,73 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`inline fragment type rename and field rename works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `inline fragment type rename and field rename works as expected snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameObject__renameObjectUnderlying: renameObjectUnderlying { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameObject__renameObjectUnderlying": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameObject": { + * "name": "val" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameObject": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/inline fragment type rename and field rename works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/inline fragment type rename and field rename works as expected.kt new file mode 100644 index 000000000..c4901b9ac --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/inline fragment type rename and field rename works as expected.kt @@ -0,0 +1,158 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `inline fragment type rename and field rename works as expected` : NadelLegacyIntegrationTest( + query = """ + query { + renameObject { + ... on ObjectOverall { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameObjectUnderlying") { env -> + MyService_ObjectUnderlying(name = "val") + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename direct works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename direct works as expected snapshot.kt new file mode 100644 index 000000000..1e8f82980 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename direct works as expected snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`interface rename direct works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `interface rename direct works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameInterface__renameInterfaceUnderlying: renameInterfaceUnderlying { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameInterface__renameInterfaceUnderlying": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameInterface": { + * "name": "val" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameInterface": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename direct works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename direct works as expected.kt new file mode 100644 index 000000000..9691f7c82 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename direct works as expected.kt @@ -0,0 +1,156 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `interface rename direct works as expected` : NadelLegacyIntegrationTest( + query = """ + query { + renameInterface { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameInterfaceUnderlying") { env -> + MyService_ObjectUnderlying(name = "val") + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename with fragments works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename with fragments works as expected snapshot.kt new file mode 100644 index 000000000..5fe839ae8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename with fragments works as expected snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`interface rename with fragments works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `interface rename with fragments works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameObject__renameObjectUnderlying: renameObjectUnderlying { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameObject__renameObjectUnderlying": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameObject": { + * "name": "val" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameObject": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename with fragments works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename with fragments works as expected.kt new file mode 100644 index 000000000..9847fce23 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/interface rename with fragments works as expected.kt @@ -0,0 +1,158 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `interface rename with fragments works as expected` : NadelLegacyIntegrationTest( + query = """ + query { + renameObject { + ... on InterfaceOverall { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameObjectUnderlying") { env -> + MyService_ObjectUnderlying(name = "val") + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things snapshot.kt new file mode 100644 index 000000000..4d6f7301d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`let jsw do jsw things`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `let jsw do jsw things snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": "Custom Scalar" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": "Custom Scalar" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": "Custom Scalar" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things.kt new file mode 100644 index 000000000..e63e3cb13 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `let jsw do jsw things` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: A + } + scalar A @renamed(from: "X") + scalar B @renamed(from: "X") + scalar C @renamed(from: "Y") + scalar D @renamed(from: "Y") + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: X + } + scalar X + enum Y { + P + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + "Custom Scalar" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("X") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) { + private enum class Service_Y { + P, + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/nested renamed types snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/nested renamed types snapshot.kt new file mode 100644 index 000000000..26fcc21d1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/nested renamed types snapshot.kt @@ -0,0 +1,104 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`nested renamed types`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `nested renamed types snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename + | parent { + | __typename + | building { + | __typename + | id + | } + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename": "Foo", + | "parent": { + | "id": "ParentFoo1", + | "__typename": "Foo", + | "building": { + | "__typename": "Building", + | "id": "Bar-1" + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "__typename": "FooX", + * "parent": { + * "id": "ParentFoo1", + * "__typename": "FooX", + * "building": { + * "__typename": "Bar", + * "id": "Bar-1" + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "__typename": "FooX", + | "parent": { + | "id": "ParentFoo1", + | "__typename": "FooX", + | "building": { + | "__typename": "Bar", + | "id": "Bar-1" + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/nested renamed types.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/nested renamed types.kt new file mode 100644 index 000000000..f789aa0cc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/nested renamed types.kt @@ -0,0 +1,75 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `nested renamed types` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + parent { + id + __typename + building { + __typename + id + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service1", + overallSchema = """ + type Query { + foo: FooX + } + type FooX @renamed(from: "Foo") { + id: ID + parent: FooX + building: Bar + } + type Bar @renamed(from: "Building") { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + id: ID! + parent: Foo + building: Building + } + type Building { + id: ID! + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo( + parent = Service1_Foo( + building = Service1_Building(id = "Bar-1"), + id = "ParentFoo1", + ), + ) + } + } + }, + ), + ), +) { + private data class Service1_Building( + val id: String? = null, + ) + + private data class Service1_Foo( + val id: String? = null, + val parent: Service1_Foo? = null, + val building: Service1_Building? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/query to two services with field rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/query to two services with field rename snapshot.kt new file mode 100644 index 000000000..aa94d7e4b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/query to two services with field rename snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`query to two services with field rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `query to two services with field rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Bar", + query = """ + | { + | bar { + | __typename__rename__name: __typename + | rename__name__title: title + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bar": { + | "rename__name__title": "Bar", + | "__typename__rename__name": "Bar" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | rename__otherFoo__fooOriginal: fooOriginal { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__otherFoo__fooOriginal": { + | "name": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "otherFoo": { + * "name": "Foo" + * }, + * "bar": { + * "name": "Bar" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "otherFoo": { + | "name": "Foo" + | }, + | "bar": { + | "name": "Bar" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/query to two services with field rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/query to two services with field rename.kt new file mode 100644 index 000000000..202e3f580 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/query to two services with field rename.kt @@ -0,0 +1,79 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `query to two services with field rename` : NadelLegacyIntegrationTest( + query = """ + query { + otherFoo: foo { + name + } + bar { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Bar", + overallSchema = """ + type Query { + bar: Bar + } + type Bar { + name: String @renamed(from: "title") + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + title: String + } + type Query { + bar: Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bar") { env -> + Bar_Bar(title = "Bar") + } + } + }, + ), + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo @renamed(from: "fooOriginal") + } + type Foo { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + name: String + } + type Query { + fooOriginal: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("fooOriginal") { env -> + Foo_Foo(name = "Foo") + } + } + }, + ), + ), +) { + private data class Bar_Bar( + val title: String? = null, + ) + + private data class Foo_Foo( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside hydration snapshot.kt new file mode 100644 index 000000000..03c6e4507 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside hydration snapshot.kt @@ -0,0 +1,102 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename inside hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename inside hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | __typename__rename__title: __typename + | rename__title__name: name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "rename__title__name": "Bar1", + | "__typename__rename__title": "Bar" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "title": "Bar1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "title": "Bar1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside hydration.kt new file mode 100644 index 000000000..51e660b4b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside hydration.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename inside hydration` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + bar { + title + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + title: String @renamed(from: "name") + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: ID + bar: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.barId"} + ] + ) + barLongerInput: Bar @hydrated( + service: "service2" + field: "barById" + arguments: [ + {name: "id" value: "${'$'}source.fooDetails.externalBarId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "barId") + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside multiple hydrations snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside multiple hydrations snapshot.kt new file mode 100644 index 000000000..7b9e445c5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside multiple hydrations snapshot.kt @@ -0,0 +1,146 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename inside multiple hydrations`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename inside multiple hydrations snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foos { + | __typename__hydration__bar: __typename + | hydration__bar__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "hydration__bar__barId": "barId", + | "__typename__hydration__bar": "Foo" + | }, + | { + | "hydration__bar__barId": "barId2", + | "__typename__hydration__bar": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId") { + | __typename__rename__title: __typename + | rename__title__name: name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "rename__title__name": "Bar1", + | "__typename__rename__title": "Bar" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service2", + query = """ + | { + | barById(id: "barId2") { + | __typename__rename__title: __typename + | rename__title__name: name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "barById": { + | "rename__title__name": "Bar2", + | "__typename__rename__title": "Bar" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "bar": { + * "title": "Bar1" + * } + * }, + * { + * "bar": { + * "title": "Bar2" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "bar": { + | "title": "Bar1" + | } + | }, + | { + | "bar": { + | "title": "Bar2" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside multiple hydrations.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside multiple hydrations.kt new file mode 100644 index 000000000..609f1c4a0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside multiple hydrations.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename inside multiple hydrations` : NadelLegacyIntegrationTest( + query = """ + query { + foos { + bar { + title + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service2", + overallSchema = """ + type Query { + barById(id: ID): Bar + } + type Bar { + id: ID + title: String @renamed(from: "name") + } + """.trimIndent(), + underlyingSchema = """ + type Bar { + id: ID + name: String + } + type Query { + barById(id: ID): Bar + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("barById") { env -> + if (env.getArgument("id") == "barId") { + Service2_Bar(name = "Bar1") + } else if (env.getArgument("id") == "barId2") { + Service2_Bar(name = "Bar2") + } else { + null + } + } + } + }, + ), + Service( + name = "service1", + overallSchema = """ + type Query { + foos: [Foo] + } + type Foo { + id: ID + bar: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.barId"}] + ) + barLongerInput: Bar + @hydrated( + service: "service2" + field: "barById" + arguments: [{name: "id" value: "${'$'}source.fooDetails.externalBarId"}] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + fooDetails: FooDetails + id: ID + } + type FooDetails { + externalBarId: ID + } + type Query { + foos: [Foo] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foos") { env -> + listOf(Service1_Foo(barId = "barId"), Service1_Foo(barId = "barId2")) + } + } + }, + ), + ), +) { + private data class Service2_Bar( + val id: String? = null, + val name: String? = null, + ) + + private data class Service1_Foo( + val barId: String? = null, + val fooDetails: Service1_FooDetails? = null, + val id: String? = null, + ) + + private data class Service1_FooDetails( + val externalBarId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside renamed type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside renamed type snapshot.kt new file mode 100644 index 000000000..05a876764 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside renamed type snapshot.kt @@ -0,0 +1,78 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename inside renamed type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename inside renamed type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename + | __typename__rename__title: __typename + | rename__title__barId: barId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename": "Foo", + | "rename__title__barId": "Bar1", + | "__typename__rename__title": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "__typename": "FooX", + * "title": "Bar1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "__typename": "FooX", + | "title": "Bar1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside renamed type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside renamed type.kt new file mode 100644 index 000000000..f4f45448a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename inside renamed type.kt @@ -0,0 +1,50 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename inside renamed type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + title + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service1", + overallSchema = """ + type Query { + foo: FooX + } + type FooX @renamed(from: "Foo") { + id: ID + title: ID @renamed(from: "barId") + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(barId = "Bar1") + } + } + }, + ), + ), +) { + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename nested inside renamed type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename nested inside renamed type snapshot.kt new file mode 100644 index 000000000..9f8b6c39e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename nested inside renamed type snapshot.kt @@ -0,0 +1,86 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename nested inside renamed type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename nested inside renamed type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service1", + query = """ + | { + | foo { + | __typename + | parent { + | __typename__rename__title: __typename + | rename__title__barId: barId + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename": "Foo", + | "parent": { + | "rename__title__barId": "Foo1-2", + | "__typename__rename__title": "Foo" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "__typename": "FooX", + * "parent": { + * "title": "Foo1-2" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "__typename": "FooX", + | "parent": { + | "title": "Foo1-2" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename nested inside renamed type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename nested inside renamed type.kt new file mode 100644 index 000000000..d6b52d4c3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename nested inside renamed type.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename nested inside renamed type` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + __typename + parent { + title + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service1", + overallSchema = """ + type Query { + foo: FooX + } + type FooX @renamed(from: "Foo") { + id: ID + title: ID @renamed(from: "barId") + parent: FooX + } + """.trimIndent(), + underlyingSchema = """ + type Foo { + barId: ID + id: ID + parent: Foo + } + type Query { + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service1_Foo(parent = Service1_Foo(barId = "Foo1-2")) + } + } + }, + ), + ), +) { + private data class Service1_Foo( + val barId: String? = null, + val id: String? = null, + val parent: Service1_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename on shared abstract type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename on shared abstract type snapshot.kt new file mode 100644 index 000000000..7aef99bc8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename on shared abstract type snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename on shared abstract type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename on shared abstract type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "worlds", + query = """ + | { + | node(id: "world-1") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "node": { + | "id": "Test" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "node": { + * "id": "Test" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "node": { + | "id": "Test" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename on shared abstract type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename on shared abstract type.kt new file mode 100644 index 000000000..bbb27f686 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename on shared abstract type.kt @@ -0,0 +1,118 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename on shared abstract type` : NadelLegacyIntegrationTest( + query = """ + query { + node(id: "world-1") { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "shared", + overallSchema = """ + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "worlds", + overallSchema = """ + type Query { + node(id: ID): Node + } + type World implements Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + worlds: [World] + } + type World implements Node { + id: ID! + } + interface Node { + id: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("node") { env -> + if (env.getArgument("id") == "world-1") { + Worlds_World(id = "Test") + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "planets", + overallSchema = """ + type Planet implements Node { + id: ID! @renamed(from: "identifier") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + type Planet implements Node { + identifier: ID! + id: ID! + } + interface Node { + id: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface Planets_Node { + val id: String? + } + + private data class Planets_Planet( + val identifier: String? = null, + override val id: String? = null, + ) : Planets_Node + + private interface Worlds_Node { + val id: String? + } + + private data class Worlds_World( + override val id: String? = null, + ) : Worlds_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first last path element returning null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first last path element returning null snapshot.kt new file mode 100644 index 000000000..020b0a221 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first last path element returning null snapshot.kt @@ -0,0 +1,78 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename with first last path element returning null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename with first last path element returning null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "deep_rename__name__details": { + | "name": null + | }, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "name": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "name": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first last path element returning null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first last path element returning null.kt new file mode 100644 index 000000000..72284fa6b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first last path element returning null.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename with first last path element returning null` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + name: String @renamed(from: "details.name") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + details: IssueDetails + } + type IssueDetails { + name: String + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_Issue(details = Issues_IssueDetails(name = null)) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val details: Issues_IssueDetails? = null, + ) + + private data class Issues_IssueDetails( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first path element returning null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first path element returning null snapshot.kt new file mode 100644 index 000000000..2a7d77599 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first path element returning null snapshot.kt @@ -0,0 +1,76 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename with first path element returning null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename with first path element returning null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | issue { + | __typename__deep_rename__name: __typename + | deep_rename__name__details: details { + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issue": { + | "deep_rename__name__details": null, + | "__typename__deep_rename__name": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issue": { + * "name": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issue": { + | "name": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first path element returning null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first path element returning null.kt new file mode 100644 index 000000000..782d2f5ca --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with first path element returning null.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename with first path element returning null` : NadelLegacyIntegrationTest( + query = """ + query { + issue { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + issue: Issue + } + type Issue { + name: String @renamed(from: "details.name") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + details: IssueDetails + } + type IssueDetails { + name: String + } + type Query { + issue: Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + Issues_Issue(details = null) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + val details: Issues_IssueDetails? = null, + ) + + private data class Issues_IssueDetails( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces asking typename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces asking typename snapshot.kt new file mode 100644 index 000000000..af47997c0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces asking typename snapshot.kt @@ -0,0 +1,113 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename with interfaces asking typename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename with interfaces asking typename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | __typename + | ... on Issue { + | id + | } + | ... on User { + | __typename__rename__id: __typename + | rename__id__ari: ari + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "Issue", + | "id": "GQLGW-001" + | }, + | { + | "__typename": "Issue", + | "id": "GQLGW-1102" + | }, + | { + | "__typename": "User", + | "rename__id__ari": "ari:i-always-forget-the-format/1", + | "__typename__rename__id": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "__typename": "JiraIssue", + * "id": "GQLGW-001" + * }, + * { + * "__typename": "JiraIssue", + * "id": "GQLGW-1102" + * }, + * { + * "__typename": "User", + * "id": "ari:i-always-forget-the-format/1" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "JiraIssue", + | "id": "GQLGW-001" + | }, + | { + | "__typename": "JiraIssue", + | "id": "GQLGW-1102" + | }, + | { + | "__typename": "User", + | "id": "ari:i-always-forget-the-format/1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces asking typename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces asking typename.kt new file mode 100644 index 000000000..64c49e5b0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces asking typename.kt @@ -0,0 +1,84 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename with interfaces asking typename` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + __typename + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID! + } + interface Node { + id: ID! + } + type User implements Node { + id: ID! @renamed(from: "ari") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + } + type User implements Node { + id: ID! + ari: ID! + name: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("nodes") { env -> + listOf( + Issues_Issue(id = "GQLGW-001"), + Issues_Issue(id = "GQLGW-1102"), + Issues_User( + ari = "ari:i-always-forget-the-format/1", + ), + ) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_User( + override val id: String? = null, + val ari: String? = null, + val name: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces snapshot.kt new file mode 100644 index 000000000..d1ec922f9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces snapshot.kt @@ -0,0 +1,103 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename with interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename with interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | ... on Issue { + | id + | } + | ... on User { + | __typename__rename__id: __typename + | rename__id__ari: ari + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "rename__id__ari": "ari:i-always-forget-the-format/1", + | "__typename__rename__id": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "id": "GQLGW-001" + * }, + * { + * "id": "GQLGW-1102" + * }, + * { + * "id": "ari:i-always-forget-the-format/1" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "id": "ari:i-always-forget-the-format/1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces.kt new file mode 100644 index 000000000..f45912fbd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with interfaces.kt @@ -0,0 +1,83 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename with interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID! + } + interface Node { + id: ID! + } + type User implements Node { + id: ID! @renamed(from: "ari") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + } + interface Node { + id: ID! + } + type Issue implements Node { + id: ID! + } + type User implements Node { + id: ID! + ari: ID! + name: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("nodes") { env -> + listOf( + Issues_Issue(id = "GQLGW-001"), + Issues_Issue(id = "GQLGW-1102"), + Issues_User( + ari = "ari:i-always-forget-the-format/1", + ), + ) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_User( + override val id: String? = null, + val ari: String? = null, + val name: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with more interfaces snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with more interfaces snapshot.kt new file mode 100644 index 000000000..d16e71854 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with more interfaces snapshot.kt @@ -0,0 +1,126 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`rename with more interfaces`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `rename with more interfaces snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Issues", + query = """ + | { + | nodes { + | ... on Issue { + | id + | } + | ... on Troll { + | __typename__rename__id: __typename + | rename__id__nameOfFirstThingEaten: nameOfFirstThingEaten + | } + | ... on User { + | __typename__rename__id: __typename + | rename__id__ari: ari + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "rename__id__nameOfFirstThingEaten": "My Arm", + | "__typename__rename__id": "Troll" + | }, + | { + | "rename__id__ari": "Franklin", + | "__typename__rename__id": "User" + | }, + | { + | "id": "GQLGW-11" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "id": "GQLGW-001" + * }, + * { + * "id": "GQLGW-1102" + * }, + * { + * "id": "My Arm" + * }, + * { + * "id": "Franklin" + * }, + * { + * "id": "GQLGW-11" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "id": "GQLGW-001" + | }, + | { + | "id": "GQLGW-1102" + | }, + | { + | "id": "My Arm" + | }, + | { + | "id": "Franklin" + | }, + | { + | "id": "GQLGW-11" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with more interfaces.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with more interfaces.kt new file mode 100644 index 000000000..c4175dfaf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/rename with more interfaces.kt @@ -0,0 +1,93 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `rename with more interfaces` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Issues", + overallSchema = """ + type Query { + nodes: [Node] + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID! + } + type Troll implements Node { + id: ID! @renamed(from: "nameOfFirstThingEaten") + } + interface Node { + id: ID! + } + type User implements Node { + id: ID! @renamed(from: "ari") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + } + interface Node { + id: ID! + } + type Troll implements Node { + id: ID! + nameOfFirstThingEaten: ID! + } + type Issue implements Node { + id: ID! + } + type User implements Node { + id: ID! + ari: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("nodes") { env -> + listOf( + Issues_Issue(id = "GQLGW-001"), + Issues_Issue(id = "GQLGW-1102"), + Issues_Troll(nameOfFirstThingEaten = "My Arm"), + Issues_User(ari = "Franklin"), + Issues_Issue(id = "GQLGW-11"), + ) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Issues_Issue( + override val id: String? = null, + ) : Issues_Node + + private interface Issues_Node { + val id: String? + } + + private data class Issues_Troll( + override val id: String? = null, + val nameOfFirstThingEaten: String? = null, + ) : Issues_Node + + private data class Issues_User( + override val id: String? = null, + val ari: String? = null, + ) : Issues_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed field with normal field using same source snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed field with normal field using same source snapshot.kt new file mode 100644 index 000000000..6a6f92536 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed field with normal field using same source snapshot.kt @@ -0,0 +1,98 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed field with normal field using same source`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed field with normal field using same source snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Foo", + query = """ + | { + | foo { + | __typename__deep_rename__renamedField: __typename + | issue { + | fooDetail { + | name + | } + | } + | deep_rename__renamedField__issue: issue { + | field + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "fooDetail": { + | "name": "fooName" + | } + | }, + | "deep_rename__renamedField__issue": { + | "field": "field" + | }, + | "__typename__deep_rename__renamedField": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "issue": { + * "fooDetail": { + * "name": "fooName" + * } + * }, + * "renamedField": "field" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "issue": { + | "fooDetail": { + | "name": "fooName" + | } + | }, + | "renamedField": "field" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed field with normal field using same source.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed field with normal field using same source.kt new file mode 100644 index 000000000..400ea4dca --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed field with normal field using same source.kt @@ -0,0 +1,80 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed field with normal field using same source` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + issue { + fooDetail { + name + } + } + renamedField + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Foo", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + renamedField: String @renamed(from: "issue.field") + issue: Issue + } + type Issue { + fooDetail: Detail + } + type Detail { + detailId: ID! + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Detail { + detailId: ID! + name: String + } + type Foo { + field: String + issue: Issue + } + type Issue { + field: String + fooDetail: Detail + } + type Query { + detail(detailIds: [ID]): Detail + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Foo_Foo(issue = Foo_Issue(fooDetail = Foo_Detail(name = "fooName"), `field` = "field")) + } + } + }, + ), + ), +) { + private data class Foo_Detail( + val detailId: String? = null, + val name: String? = null, + ) + + private data class Foo_Foo( + val `field`: String? = null, + val issue: Foo_Issue? = null, + ) + + private data class Foo_Issue( + val `field`: String? = null, + val fooDetail: Foo_Detail? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed list inside renamed list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed list inside renamed list snapshot.kt new file mode 100644 index 000000000..c90d77048 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed list inside renamed list snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed list inside renamed list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed list inside renamed list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssuesService", + query = """ + | { + | rename__renamedIssue__issue: issue { + | __typename__rename__renamedTicket: __typename + | rename__renamedTicket__ticket: ticket { + | __typename__rename__renamedTicketTypes: __typename + | rename__renamedTicketTypes__ticketTypes: ticketTypes { + | __typename__rename__renamedId: __typename + | __typename__rename__renamedDate: __typename + | rename__renamedDate__date: date + | rename__renamedId__id: id + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renamedIssue__issue": [ + | { + | "rename__renamedTicket__ticket": { + | "rename__renamedTicketTypes__ticketTypes": [ + | { + | "rename__renamedId__id": "1", + | "__typename__rename__renamedId": "TicketType", + | "rename__renamedDate__date": "20/11/2020", + | "__typename__rename__renamedDate": "TicketType" + | } + | ], + | "__typename__rename__renamedTicketTypes": "Ticket" + | }, + | "__typename__rename__renamedTicket": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renamedIssue": [ + * { + * "renamedTicket": { + * "renamedTicketTypes": [ + * { + * "renamedId": "1", + * "renamedDate": "20/11/2020" + * } + * ] + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renamedIssue": [ + | { + | "renamedTicket": { + | "renamedTicketTypes": [ + | { + | "renamedId": "1", + | "renamedDate": "20/11/2020" + | } + | ] + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed list inside renamed list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed list inside renamed list.kt new file mode 100644 index 000000000..ef2776e61 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed list inside renamed list.kt @@ -0,0 +1,80 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed list inside renamed list` : NadelLegacyIntegrationTest( + query = """ + query { + renamedIssue { + renamedTicket { + renamedTicketTypes { + renamedId + renamedDate + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssuesService", + overallSchema = """ + type Query { + renamedIssue: [RenamedIssue] @renamed(from: "issue") + } + type RenamedIssue @renamed(from: "Issue") { + renamedTicket: RenamedTicket @renamed(from: "ticket") + } + type RenamedTicket @renamed(from: "Ticket") { + renamedTicketTypes: [RenamedTicketType] @renamed(from: "ticketTypes") + } + type RenamedTicketType @renamed(from: "TicketType") { + renamedId: String @renamed(from: "id") + renamedDate: String @renamed(from: "date") + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + ticket: Ticket + } + type Query { + issue: [Issue] + } + type Ticket { + ticketTypes: [TicketType] + } + type TicketType { + date: String + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issue") { env -> + listOf( + IssuesService_Issue( + ticket = IssuesService_Ticket( + ticketTypes = listOf(IssuesService_TicketType(date = "20/11/2020", id = "1")), + ), + ), + ) + } + } + }, + ), + ), +) { + private data class IssuesService_Issue( + val ticket: IssuesService_Ticket? = null, + ) + + private data class IssuesService_Ticket( + val ticketTypes: List? = null, + ) + + private data class IssuesService_TicketType( + val date: String? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed top level field with argument snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed top level field with argument snapshot.kt new file mode 100644 index 000000000..75ad0d607 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed top level field with argument snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed top level field with argument`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed top level field with argument snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameObject__renameObjectUnderlying: renameObjectUnderlying(id: "OBJECT-001") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameObject__renameObjectUnderlying": { + | "name": "Object 001" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameObject": { + * "name": "Object 001" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameObject": { + | "name": "Object 001" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed top level field with argument.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed top level field with argument.kt new file mode 100644 index 000000000..7d7ffcb0e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/renamed top level field with argument.kt @@ -0,0 +1,50 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed top level field with argument` : NadelLegacyIntegrationTest( + query = """ + query { + renameObject(id: "OBJECT-001") { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + renameObject(id: ID!): ObjectOverall @renamed(from: "renameObjectUnderlying") + } + type ObjectOverall @renamed(from: "ObjectUnderlying") { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type ObjectUnderlying { + name: String + } + type Query { + renameObjectUnderlying(id: ID!): ObjectUnderlying + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameObjectUnderlying") { env -> + if (env.getArgument("id") == "OBJECT-001") { + MyService_ObjectUnderlying(name = "Object 001") + } else { + null + } + } + } + }, + ), + ), +) { + private data class MyService_ObjectUnderlying( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/simple type rename and field rename works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/simple type rename and field rename works as expected snapshot.kt new file mode 100644 index 000000000..5444a1425 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/simple type rename and field rename works as expected snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`simple type rename and field rename works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `simple type rename and field rename works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameObject__renameObjectUnderlying: renameObjectUnderlying { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameObject__renameObjectUnderlying": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameObject": { + * "name": "val" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameObject": { + | "name": "val" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/simple type rename and field rename works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/simple type rename and field rename works as expected.kt new file mode 100644 index 000000000..b3bc0c5a1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/simple type rename and field rename works as expected.kt @@ -0,0 +1,156 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `simple type rename and field rename works as expected` : NadelLegacyIntegrationTest( + query = """ + query { + renameObject { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameObjectUnderlying") { env -> + MyService_ObjectUnderlying(name = "val") + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/string field rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/string field rename snapshot.kt new file mode 100644 index 000000000..9fc70deab --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/string field rename snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`string field rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `string field rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameString__renameStringUnderlying: renameStringUnderlying + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameString__renameStringUnderlying": "hello" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameString": "hello" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameString": "hello" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/string field rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/string field rename.kt new file mode 100644 index 000000000..86cae6249 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/string field rename.kt @@ -0,0 +1,154 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `string field rename` : NadelLegacyIntegrationTest( + query = """ + query { + renameString + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameStringUnderlying") { env -> + "hello" + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in interface snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in interface snapshot.kt new file mode 100644 index 000000000..b29cc079b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in interface snapshot.kt @@ -0,0 +1,177 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type in interface`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type in interface snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | rename__nodes__all: all { + | __typename + | id + | ... on Issue { + | links { + | __typename + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__nodes__all": [ + | { + | "__typename": "Issue", + | "id": "issue/1", + | "links": null + | }, + | null, + | { + | "__typename": "Issue", + | "id": "issue/2", + | "links": [] + | }, + | { + | "__typename": "Issue", + | "id": "issue/3", + | "links": [ + | { + | "__typename": "User" + | }, + | { + | "__typename": "Issue" + | }, + | { + | "__typename": "Monkey" + | } + | ] + | }, + | { + | "__typename": "Monkey", + | "id": "monkey/1" + | }, + | { + | "__typename": "User", + | "id": "user/1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "__typename": "JiraIssue", + * "id": "issue/1", + * "links": null + * }, + * null, + * { + * "__typename": "JiraIssue", + * "id": "issue/2", + * "links": [] + * }, + * { + * "__typename": "JiraIssue", + * "id": "issue/3", + * "links": [ + * { + * "__typename": "User" + * }, + * { + * "__typename": "JiraIssue" + * }, + * { + * "__typename": "Donkey" + * } + * ] + * }, + * { + * "__typename": "Donkey", + * "id": "monkey/1" + * }, + * { + * "__typename": "User", + * "id": "user/1" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "JiraIssue", + | "id": "issue/1", + | "links": null + | }, + | null, + | { + | "__typename": "JiraIssue", + | "id": "issue/2", + | "links": [] + | }, + | { + | "__typename": "JiraIssue", + | "id": "issue/3", + | "links": [ + | { + | "__typename": "User" + | }, + | { + | "__typename": "JiraIssue" + | }, + | { + | "__typename": "Donkey" + | } + | ] + | }, + | { + | "__typename": "Donkey", + | "id": "monkey/1" + | }, + | { + | "__typename": "User", + | "id": "user/1" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in interface.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in interface.kt new file mode 100644 index 000000000..8d22d86db --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in interface.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type in interface` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + __typename + id + ... on JiraIssue { + links { + __typename + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + nodes: [Node] @renamed(from: "all") + } + type JiraIssue implements Node @renamed(from: "Issue") { + id: ID + links: [Node] + } + interface Node { + id: ID + } + type User implements Node { + id: ID + } + type Donkey implements Node @renamed(from: "Monkey") { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + all: [Node] + } + type Issue implements Node { + id: ID + links: [Node] + } + interface Node { + id: ID + } + type User implements Node { + id: ID + } + type Monkey implements Node { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("all") { env -> + listOf( + IssueService_Issue(id = "issue/1", links = null), + null, + IssueService_Issue( + id = "issue/2", + links = listOf(), + ), + IssueService_Issue( + id = "issue/3", + links = listOf( + IssueService_User(id = "user/1"), + IssueService_Issue("issue/1"), + IssueService_Monkey("monkey/1"), + ), + ), + IssueService_Monkey(id = "monkey/1"), + IssueService_User(id = "user/1"), + ) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + override val id: String? = null, + val links: List? = null, + ) : IssueService_Node + + private data class IssueService_Monkey( + override val id: String? = null, + ) : IssueService_Node + + private interface IssueService_Node { + val id: String? + } + + private data class IssueService_User( + override val id: String? = null, + ) : IssueService_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in another service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in another service snapshot.kt new file mode 100644 index 000000000..c3db1c4bd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in another service snapshot.kt @@ -0,0 +1,99 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type in union declared in another service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type in union declared in another service snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | nodes { + | __typename + | ... on Comment { + | id + | } + | ... on Issue { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "Issue", + | "id": "1" + | }, + | { + | "__typename": "Comment", + | "id": "2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "__typename": "Issue", + * "id": "1" + * }, + * { + * "__typename": "JiraComment", + * "id": "2" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "Issue", + | "id": "1" + | }, + | { + | "__typename": "JiraComment", + | "id": "2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in another service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in another service.kt new file mode 100644 index 000000000..7038d104f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in another service.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type in union declared in another service` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + __typename + ... on Issue { + id + } + ... on JiraComment { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + nodes: [Node] + } + type Issue { + id: ID + } + union Node = Issue | JiraComment + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + } + type Issue { + id: ID + } + type Comment { + id: ID + } + union Node = Issue | Comment + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("nodes") { env -> + listOf(IssueService_Issue(id = "1"), IssueService_Comment(id = "2")) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "CommentService", + overallSchema = """ + type Query { + comment: JiraComment + } + type JiraComment @renamed(from: "Comment") { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + comment: Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class IssueService_Comment( + val id: String? = null, + ) : IssueService_Node + + private data class IssueService_Issue( + val id: String? = null, + ) : IssueService_Node + + private sealed interface IssueService_Node + + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in same service snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in same service snapshot.kt new file mode 100644 index 000000000..1fcb4f672 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in same service snapshot.kt @@ -0,0 +1,99 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type in union declared in same service`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type in union declared in same service snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | nodes { + | __typename + | ... on Comment { + | id + | } + | ... on Issue { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "Issue", + | "id": "1" + | }, + | { + | "__typename": "Comment", + | "id": "2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "__typename": "Issue", + * "id": "1" + * }, + * { + * "__typename": "JiraComment", + * "id": "2" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "Issue", + | "id": "1" + | }, + | { + | "__typename": "JiraComment", + | "id": "2" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in same service.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in same service.kt new file mode 100644 index 000000000..e25fe403d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union declared in same service.kt @@ -0,0 +1,95 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type in union declared in same service` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + __typename + ... on Issue { + id + } + ... on JiraComment { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + nodes: [Node] + } + type Issue { + id: ID + } + union Node = Issue | JiraComment + type JiraComment @renamed(from: "Comment") { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + nodes: [Node] + } + type Issue { + id: ID + } + type Comment { + id: ID + } + union Node = Issue | Comment + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("nodes") { env -> + listOf(IssueService_Issue(id = "1"), IssueService_Comment(id = "2")) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "CommentService", + overallSchema = """ + type Query { + comment: JiraComment + } + """.trimIndent(), + underlyingSchema = """ + type Query { + comment: Comment + } + type Comment { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class IssueService_Comment( + val id: String? = null, + ) : IssueService_Node + + private data class IssueService_Issue( + val id: String? = null, + ) : IssueService_Node + + private sealed interface IssueService_Node + + private data class CommentService_Comment( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union snapshot.kt new file mode 100644 index 000000000..c14256873 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union snapshot.kt @@ -0,0 +1,183 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type in union`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type in union snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | rename__nodes__all: all { + | __typename + | ... on Issue { + | id + | links { + | __typename + | } + | } + | ... on Monkey { + | id + | } + | ... on User { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__nodes__all": [ + | { + | "__typename": "Issue", + | "id": "1", + | "links": null + | }, + | null, + | { + | "__typename": "Issue", + | "id": "2", + | "links": [] + | }, + | { + | "__typename": "Issue", + | "id": "3", + | "links": [ + | { + | "__typename": "User" + | }, + | { + | "__typename": "Issue" + | }, + | { + | "__typename": "Monkey" + | } + | ] + | }, + | { + | "__typename": "Monkey", + | "id": "4" + | }, + | { + | "__typename": "User", + | "id": "8" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "nodes": [ + * { + * "__typename": "JiraIssue", + * "id": "1", + * "links": null + * }, + * null, + * { + * "__typename": "JiraIssue", + * "id": "2", + * "links": [] + * }, + * { + * "__typename": "JiraIssue", + * "id": "3", + * "links": [ + * { + * "__typename": "User" + * }, + * { + * "__typename": "JiraIssue" + * }, + * { + * "__typename": "Donkey" + * } + * ] + * }, + * { + * "__typename": "Donkey", + * "id": "4" + * }, + * { + * "__typename": "User", + * "id": "8" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "nodes": [ + | { + | "__typename": "JiraIssue", + | "id": "1", + | "links": null + | }, + | null, + | { + | "__typename": "JiraIssue", + | "id": "2", + | "links": [] + | }, + | { + | "__typename": "JiraIssue", + | "id": "3", + | "links": [ + | { + | "__typename": "User" + | }, + | { + | "__typename": "JiraIssue" + | }, + | { + | "__typename": "Donkey" + | } + | ] + | }, + | { + | "__typename": "Donkey", + | "id": "4" + | }, + | { + | "__typename": "User", + | "id": "8" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union.kt new file mode 100644 index 000000000..52c74906c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type in union.kt @@ -0,0 +1,109 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type in union` : NadelLegacyIntegrationTest( + query = """ + query { + nodes { + __typename + ... on JiraIssue { + id + links { + __typename + } + } + ... on User { + id + } + ... on Donkey { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + nodes: [Node] @renamed(from: "all") + } + union Node = JiraIssue | User | Donkey + type JiraIssue @renamed(from: "Issue") { + id: ID + links: [Node] + } + type User { + id: ID + } + type Donkey @renamed(from: "Monkey") { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + union Node = Issue | User | Monkey + type Query { + all: [Node] + } + type Issue { + id: ID + links: [Node] + } + type User { + id: ID + } + type Monkey { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("all") { env -> + listOf( + IssueService_Issue(id = "1", links = null), + null, + IssueService_Issue( + id = "2", + links = listOf(), + ), + IssueService_Issue( + id = "3", + links = listOf( + IssueService_User(), + IssueService_Issue(), + IssueService_Monkey(), + ), + ), + IssueService_Monkey(id = "4"), + IssueService_User(id = "8"), + ) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + val links: List? = null, + ) : IssueService_Node + + private data class IssueService_Monkey( + val id: String? = null, + ) : IssueService_Node + + private sealed interface IssueService_Node + + private data class IssueService_User( + val id: String? = null, + ) : IssueService_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside batch hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside batch hydration snapshot.kt new file mode 100644 index 000000000..b1602f7d9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside batch hydration snapshot.kt @@ -0,0 +1,176 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside batch hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside batch hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issuesByIds(id: ["issue-1", "issue-2", "issue-3"]) { + | details { + | __typename + | name + | } + | batch_hydration__issue__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issuesByIds": [ + | { + | "details": { + | "__typename": "Details", + | "name": "Details of issue one" + | }, + | "batch_hydration__issue__id": "issue-1" + | }, + | { + | "details": { + | "__typename": "Details", + | "name": "Issue two" + | }, + | "batch_hydration__issue__id": "issue-2" + | }, + | { + | "details": { + | "__typename": "Details", + | "name": "Issue four – no wait three" + | }, + | "batch_hydration__issue__id": "issue-3" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | users { + | __typename__batch_hydration__issue: __typename + | batch_hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "users": [ + | { + | "batch_hydration__issue__issueId": "issue-1", + | "__typename__batch_hydration__issue": "User" + | }, + | { + | "batch_hydration__issue__issueId": "issue-2", + | "__typename__batch_hydration__issue": "User" + | }, + | { + | "batch_hydration__issue__issueId": "issue-3", + | "__typename__batch_hydration__issue": "User" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "users": [ + * { + * "issue": { + * "details": { + * "__typename": "IssueDetails", + * "name": "Details of issue one" + * } + * } + * }, + * { + * "issue": { + * "details": { + * "__typename": "IssueDetails", + * "name": "Issue two" + * } + * } + * }, + * { + * "issue": { + * "details": { + * "__typename": "IssueDetails", + * "name": "Issue four – no wait three" + * } + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "users": [ + | { + | "issue": { + | "details": { + | "__typename": "IssueDetails", + | "name": "Details of issue one" + | } + | } + | }, + | { + | "issue": { + | "details": { + | "__typename": "IssueDetails", + | "name": "Issue two" + | } + | } + | }, + | { + | "issue": { + | "details": { + | "__typename": "IssueDetails", + | "name": "Issue four – no wait three" + | } + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside batch hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside batch hydration.kt new file mode 100644 index 000000000..cc722a377 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside batch hydration.kt @@ -0,0 +1,122 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside batch hydration` : NadelLegacyIntegrationTest( + query = """ + query { + users { + issue { + details { + __typename + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issuesByIds(id: [ID!]): [Issue] + } + type Issue { + details: IssueDetails + } + type IssueDetails @renamed(from: "Details") { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + details: Details + } + type Details { + name: String + } + type Query { + issuesByIds(id: [ID!]): [Issue] + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val issuesByIds = listOf( + IssueService_Issue( + details = IssueService_Details(name = "Details of issue one"), + id = "issue-1", + ), + IssueService_Issue( + details = IssueService_Details( + name = "Issue two", + ), + id = "issue-2", + ), + IssueService_Issue( + details = IssueService_Details(name = "Issue four – no wait three"), + id = "issue-3", + ), + ).associateBy { it.id } + + type.dataFetcher("issuesByIds") { env -> + env.getArgument>("id")?.map(issuesByIds::get) + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issuesByIds" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + identifiedBy: "id" + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + users: [User] + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("users") { env -> + listOf( + UserService_User(issueId = "issue-1"), + UserService_User(issueId = "issue-2"), + UserService_User(issueId = "issue-3"), + ) + } + } + }, + ), + ), +) { + private data class IssueService_Details( + val name: String? = null, + ) + + private data class IssueService_Issue( + val id: String? = null, + val details: IssueService_Details? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename snapshot.kt new file mode 100644 index 000000000..9697a33c4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename snapshot.kt @@ -0,0 +1,117 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside deep rename`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside deep rename snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-1") { + | __typename__deep_rename__assignee: __typename + | deep_rename__assignee__details: details { + | assignee { + | __typename + | friends { + | __typename + | } + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "deep_rename__assignee__details": { + | "assignee": { + | "name": "Franklin", + | "__typename": "User", + | "friends": [ + | { + | "__typename": "User" + | }, + | { + | "__typename": "User" + | } + | ] + | } + | }, + | "__typename__deep_rename__assignee": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issueById": { + * "assignee": { + * "name": "Franklin", + * "__typename": "IssueUser", + * "friends": [ + * { + * "__typename": "IssueUser" + * }, + * { + * "__typename": "IssueUser" + * } + * ] + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issueById": { + | "assignee": { + | "name": "Franklin", + | "__typename": "IssueUser", + | "friends": [ + | { + | "__typename": "IssueUser" + | }, + | { + | "__typename": "IssueUser" + | } + | ] + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename that returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename that returns null snapshot.kt new file mode 100644 index 000000000..6a0e9f7de --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename that returns null snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside deep rename that returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside deep rename that returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-1") { + | __typename__deep_rename__assignee: __typename + | deep_rename__assignee__details: details { + | assignee { + | __typename + | friends { + | __typename + | } + | name + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "deep_rename__assignee__details": { + | "assignee": null + | }, + | "__typename__deep_rename__assignee": "Issue" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issueById": { + * "assignee": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issueById": { + | "assignee": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename that returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename that returns null.kt new file mode 100644 index 000000000..a72481489 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename that returns null.kt @@ -0,0 +1,83 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside deep rename that returns null` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "issue-1") { + assignee { + name + __typename + friends { + __typename + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID!): Issue + } + type Issue { + assignee: IssueUser @renamed(from: "details.assignee") + } + type IssueUser @renamed(from: "User") { + name: String + friends: [IssueUser] + } + type IssueDetails @renamed(from: "Details") { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + details: Details + } + type Details { + name: String + assignee: User + } + type User { + name: String + friends: [User] + } + type Query { + issueById(id: ID!): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "issue-1") { + IssueService_Issue(details = IssueService_Details(assignee = null)) + } else { + null + } + } + } + }, + ), + ), +) { + private data class IssueService_Details( + val name: String? = null, + val assignee: IssueService_User? = null, + ) + + private data class IssueService_Issue( + val id: String? = null, + val details: IssueService_Details? = null, + ) + + private data class IssueService_User( + val name: String? = null, + val friends: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename.kt new file mode 100644 index 000000000..9e8a3a651 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside deep rename.kt @@ -0,0 +1,90 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside deep rename` : NadelLegacyIntegrationTest( + query = """ + query { + issueById(id: "issue-1") { + assignee { + name + __typename + friends { + __typename + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID!): Issue + } + type Issue { + assignee: IssueUser @renamed(from: "details.assignee") + } + type IssueUser @renamed(from: "User") { + name: String + friends: [IssueUser] + } + type IssueDetails @renamed(from: "Details") { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + details: Details + } + type Details { + name: String + assignee: User + } + type User { + name: String + friends: [User] + } + type Query { + issueById(id: ID!): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "issue-1") { + IssueService_Issue( + details = IssueService_Details( + assignee = IssueService_User( + friends = listOf(IssueService_User(), IssueService_User()), + name = "Franklin", + ), + ), + ) + } else { + null + } + } + } + }, + ), + ), +) { + private data class IssueService_Details( + val name: String? = null, + val assignee: IssueService_User? = null, + ) + + private data class IssueService_Issue( + val id: String? = null, + val details: IssueService_Details? = null, + ) + + private data class IssueService_User( + val name: String? = null, + val friends: List? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration snapshot.kt new file mode 100644 index 000000000..7b438319c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside hydration`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside hydration snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-2") { + | details { + | __typename + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": { + | "details": { + | "__typename": "Details", + | "name": "Issue two" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | me { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "me": { + | "hydration__issue__issueId": "issue-2", + | "__typename__hydration__issue": "User" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "me": { + * "issue": { + * "details": { + * "__typename": "IssueDetails", + * "name": "Issue two" + * } + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "me": { + | "issue": { + | "details": { + | "__typename": "IssueDetails", + | "name": "Issue two" + | } + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration that returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration that returns null snapshot.kt new file mode 100644 index 000000000..34cc1ae00 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration that returns null snapshot.kt @@ -0,0 +1,97 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside hydration that returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside hydration that returns null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issueById(id: "issue-2") { + | details { + | __typename + | name + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issueById": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "UserService", + query = """ + | { + | me { + | __typename__hydration__issue: __typename + | hydration__issue__issueId: issueId + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "me": { + | "hydration__issue__issueId": "issue-2", + | "__typename__hydration__issue": "User" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "me": { + * "issue": null + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "me": { + | "issue": null + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration that returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration that returns null.kt new file mode 100644 index 000000000..4e753e0d5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration that returns null.kt @@ -0,0 +1,104 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside hydration that returns null` : NadelLegacyIntegrationTest( + query = """ + query { + me { + issue { + details { + __typename + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID!): Issue + } + type Issue { + details: IssueDetails + } + type IssueDetails @renamed(from: "Details") { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + details: Details + } + type Details { + name: String + } + type Query { + issueById(id: ID!): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "issue-2") { + null + } else { + null + } + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + me: User + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issueById" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + me: User + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("me") { env -> + UserService_User(issueId = "issue-2") + } + } + }, + ), + ), +) { + private data class IssueService_Details( + val name: String? = null, + ) + + private data class IssueService_Issue( + val id: String? = null, + val details: IssueService_Details? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration.kt new file mode 100644 index 000000000..2722f1fca --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside hydration.kt @@ -0,0 +1,104 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside hydration` : NadelLegacyIntegrationTest( + query = """ + query { + me { + issue { + details { + __typename + name + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issueById(id: ID!): Issue + } + type Issue { + details: IssueDetails + } + type IssueDetails @renamed(from: "Details") { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Issue { + id: ID + details: Details + } + type Details { + name: String + } + type Query { + issueById(id: ID!): Issue + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issueById") { env -> + if (env.getArgument("id") == "issue-2") { + IssueService_Issue(details = IssueService_Details(name = "Issue two")) + } else { + null + } + } + } + }, + ), + Service( + name = "UserService", + overallSchema = """ + type Query { + me: User + } + type User { + issueId: ID + issue: Issue @hydrated( + service: "IssueService" + field: "issueById" + arguments: [ + {name: "id" value: "${'$'}source.issueId"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + me: User + } + type User { + issueId: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("me") { env -> + UserService_User(issueId = "issue-2") + } + } + }, + ), + ), +) { + private data class IssueService_Details( + val name: String? = null, + ) + + private data class IssueService_Issue( + val id: String? = null, + val details: IssueService_Details? = null, + ) + + private data class UserService_User( + val issueId: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside list snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside list snapshot.kt new file mode 100644 index 000000000..142075ee6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside list snapshot.kt @@ -0,0 +1,99 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside list`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside list snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | issues { + | __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "issues": [ + | { + | "__typename": "Issue" + | }, + | null, + | { + | "__typename": "Issue" + | }, + | { + | "__typename": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "__typename": "JiraIssue" + * }, + * null, + * { + * "__typename": "JiraIssue" + * }, + * { + * "__typename": "JiraIssue" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "__typename": "JiraIssue" + | }, + | null, + | { + | "__typename": "JiraIssue" + | }, + | { + | "__typename": "JiraIssue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside list.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside list.kt new file mode 100644 index 000000000..5b2a83b5d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside list.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside list` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + __typename + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issues: [JiraIssue] + } + type JiraIssue @renamed(from: "Issue") { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + issues: [Issue] + } + type Issue { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("issues") { env -> + listOf(IssueService_Issue(), null, IssueService_Issue(), IssueService_Issue()) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside renamed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside renamed field snapshot.kt new file mode 100644 index 000000000..236fc6408 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside renamed field snapshot.kt @@ -0,0 +1,99 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type inside renamed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type inside renamed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "IssueService", + query = """ + | { + | rename__issues__all: all { + | __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__issues__all": [ + | { + | "__typename": "Issue" + | }, + | null, + | { + | "__typename": "Issue" + | }, + | { + | "__typename": "Issue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "issues": [ + * { + * "__typename": "JiraIssue" + * }, + * null, + * { + * "__typename": "JiraIssue" + * }, + * { + * "__typename": "JiraIssue" + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "issues": [ + | { + | "__typename": "JiraIssue" + | }, + | null, + | { + | "__typename": "JiraIssue" + | }, + | { + | "__typename": "JiraIssue" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside renamed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside renamed field.kt new file mode 100644 index 000000000..ca150eee6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type inside renamed field.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type inside renamed field` : NadelLegacyIntegrationTest( + query = """ + query { + issues { + __typename + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "IssueService", + overallSchema = """ + type Query { + issues: [JiraIssue] @renamed(from: "all") + } + type JiraIssue @renamed(from: "Issue") { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + all: [Issue] + } + type Issue { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("all") { env -> + listOf(IssueService_Issue(), null, IssueService_Issue(), IssueService_Issue()) + } + } + }, + ), + ), +) { + private data class IssueService_Issue( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type is shared even deeper snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type is shared even deeper snapshot.kt new file mode 100644 index 000000000..540c4bf72 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type is shared even deeper snapshot.kt @@ -0,0 +1,106 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renamed type is shared even deeper`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renamed type is shared even deeper snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Nextgen", + query = """ + | { + | elements { + | __typename + | nodes { + | __typename + | other { + | __typename + | id + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "elements": { + | "__typename": "ElementConnection", + | "nodes": [ + | { + | "__typename": "Element", + | "other": { + | "__typename": "Other", + | "id": "OTHER-1" + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "elements": { + * "__typename": "ElementConnection", + * "nodes": [ + * { + * "__typename": "Element", + * "other": { + * "__typename": "RenamedOther", + * "id": "OTHER-1" + * } + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "elements": { + | "__typename": "ElementConnection", + | "nodes": [ + | { + | "__typename": "Element", + | "other": { + | "__typename": "RenamedOther", + | "id": "OTHER-1" + | } + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type is shared even deeper.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type is shared even deeper.kt new file mode 100644 index 000000000..5b851ca91 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/renamed type is shared even deeper.kt @@ -0,0 +1,183 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `renamed type is shared even deeper` : NadelLegacyIntegrationTest( + query = """ + query { + elements { + __typename + nodes { + __typename + other { + __typename + id + } + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "Nextgen", + overallSchema = """ + type Query { + elements: ElementConnection + } + """.trimIndent(), + underlyingSchema = """ + type Query { + elements: ElementConnection + } + type ElementConnection { + nodes: [Element] + } + type Element implements Node { + id: ID + other: Other + } + type Other { + id: ID! + } + interface Node { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("elements") { env -> + Nextgen_ElementConnection( + nodes = listOf( + Nextgen_Element( + other = Nextgen_Other( + id = "OTHER-1", + ), + ), + ), + ) + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "Service", + overallSchema = """ + type ElementConnection { + nodes: [Element] + } + type Element implements Node { + id: ID + other: RenamedOther + } + type RenamedOther @renamed(from: "Other") { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + type ElementConnection { + nodes: [Element] + } + type Element implements Node { + id: ID + other: Other + } + type Other { + id: ID! + } + interface Node { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + Service( + name = "Shared", + overallSchema = """ + interface Node { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + node(id: ID): Node + } + interface Node { + id: ID + } + type Stub implements Node { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private data class Nextgen_Element( + override val id: String? = null, + val other: Nextgen_Other? = null, + ) : Nextgen_Node + + private data class Nextgen_ElementConnection( + val nodes: List? = null, + ) + + private interface Nextgen_Node { + val id: String? + } + + private data class Nextgen_Other( + val id: String? = null, + ) + + private data class Service_Element( + override val id: String? = null, + val other: Service_Other? = null, + ) : Service_Node + + private data class Service_ElementConnection( + val nodes: List? = null, + ) + + private interface Service_Node { + val id: String? + } + + private data class Service_Other( + val id: String? = null, + ) + + private interface Shared_Node { + val id: String? + } + + private data class Shared_Stub( + override val id: String? = null, + ) : Shared_Node +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/repeated fragments with renamed types snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/repeated fragments with renamed types snapshot.kt new file mode 100644 index 000000000..8764ac13b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/repeated fragments with renamed types snapshot.kt @@ -0,0 +1,326 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`repeated fragments with renamed types`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `repeated fragments with renamed types snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Users", + query = """ + | { + | service(id: "service-1") { + | __typename + | dependedOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | dependedOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | dependsOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | id + | name + | } + | id + | startService { + | __typename + | dependedOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | dependsOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | id + | name + | } + | type + | } + | } + | dependsOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | dependedOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | dependsOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | id + | name + | } + | id + | startService { + | __typename + | dependedOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | dependsOn { + | __typename + | nodes { + | __typename + | endService { + | __typename + | id + | name + | } + | id + | startService { + | __typename + | id + | name + | } + | type + | } + | } + | id + | name + | } + | type + | } + | } + | id + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "service": { + | "__typename": "Service", + | "dependedOn": { + | "__typename": "RelationshipConnection", + | "nodes": [ + | { + | "__typename": "Relationship", + | "endService": null, + | "id": "relationship-1", + | "startService": { + | "__typename": "Service", + | "dependedOn": null, + | "dependsOn": null, + | "id": "service-1", + | "name": "GraphQL Gateway" + | }, + | "type": "unsure" + | } + | ] + | }, + | "dependsOn": { + | "__typename": "RelationshipConnection", + | "nodes": [] + | }, + | "id": "service-0", + | "name": "API Gateway" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "service": { + * "__typename": "MyService", + * "dependedOn": { + * "__typename": "ServiceRelationshipConnection", + * "nodes": [ + * { + * "__typename": "ServiceRelationship", + * "endService": null, + * "id": "relationship-1", + * "startService": { + * "__typename": "MyService", + * "dependedOn": null, + * "dependsOn": null, + * "id": "service-1", + * "name": "GraphQL Gateway" + * }, + * "type": "unsure" + * } + * ] + * }, + * "dependsOn": { + * "__typename": "ServiceRelationshipConnection", + * "nodes": [] + * }, + * "id": "service-0", + * "name": "API Gateway" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "service": { + | "__typename": "MyService", + | "dependedOn": { + | "__typename": "ServiceRelationshipConnection", + | "nodes": [ + | { + | "__typename": "ServiceRelationship", + | "endService": null, + | "id": "relationship-1", + | "startService": { + | "__typename": "MyService", + | "dependedOn": null, + | "dependsOn": null, + | "id": "service-1", + | "name": "GraphQL Gateway" + | }, + | "type": "unsure" + | } + | ] + | }, + | "dependsOn": { + | "__typename": "ServiceRelationshipConnection", + | "nodes": [] + | }, + | "id": "service-0", + | "name": "API Gateway" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/repeated fragments with renamed types.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/repeated fragments with renamed types.kt new file mode 100644 index 000000000..4c830690b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/types/repeated fragments with renamed types.kt @@ -0,0 +1,182 @@ +package graphql.nadel.tests.legacy.renames.types + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `repeated fragments with renamed types` : NadelLegacyIntegrationTest( + query = """ + query(${'$'}var1: ID!) { + service(id: ${'$'}var1) { + __typename + dependedOn { + __typename + ...ServiceRelationshipsWithGrandchildren + } + dependsOn { + __typename + ...ServiceRelationshipsWithGrandchildren + } + ...BaseServiceInfo + } + } + fragment BaseServiceInfo on MyService { + __typename + id + name + } + fragment BaseServiceRelationships on ServiceRelationshipConnection { + __typename + nodes { + __typename + endService { + __typename + ...BaseServiceInfo + } + id + startService { + __typename + ...BaseServiceInfo + } + type + } + } + fragment ServiceInfoWithChildren on MyService { + __typename + dependedOn { + __typename + ...BaseServiceRelationships + } + dependsOn { + __typename + ...BaseServiceRelationships + } + ...BaseServiceInfo + } + fragment ServiceRelationshipsWithGrandchildren on ServiceRelationshipConnection { + __typename + nodes { + __typename + endService { + __typename + ...ServiceInfoWithChildren + } + id + startService { + __typename + ...ServiceInfoWithChildren + } + type + } + } + """.trimIndent(), + variables = mapOf("var1" to "service-1"), + services = listOf( + Service( + name = "Users", + overallSchema = """ + type Query { + service(id: ID!): MyService + } + type MyService @renamed(from: "Service") { + id: ID! + name: String + dependedOn: ServiceRelationshipConnection + dependsOn: ServiceRelationshipConnection + } + type ServiceRelationshipConnection @renamed(from: "RelationshipConnection") { + nodes: [ServiceRelationship] + } + type ServiceRelationship implements Node @renamed(from: "Relationship") { + id: ID! + type: String + startService: MyService + endService: MyService + } + interface Node { + id: ID! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + service(id: ID!): Service + } + type Service { + id: ID! + name: String + dependedOn: RelationshipConnection + dependsOn: RelationshipConnection + } + type RelationshipConnection { + nodes: [Relationship] + } + type Relationship implements Node { + id: ID! + type: String + startService: Service + endService: Service + } + interface Node { + id: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("service") { env -> + if (env.getArgument("id") == "service-1") { + Users_Service( + dependedOn = Users_RelationshipConnection( + nodes = listOf( + Users_Relationship( + endService = null, + id = "relationship-1", + startService = Users_Service( + dependedOn = null, + dependsOn = null, + id = "service-1", + name = "GraphQL Gateway", + ), + type = "unsure", + ), + ), + ), + dependsOn = Users_RelationshipConnection(nodes = listOf()), + id = "service-0", + name = "API Gateway", + ) + } else { + null + } + } + } + wiring.type("Node") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private interface Users_Node { + val id: String? + } + + private data class Users_Relationship( + override val id: String? = null, + val type: String? = null, + val startService: Users_Service? = null, + val endService: Users_Service? = null, + ) : Users_Node + + private data class Users_RelationshipConnection( + val nodes: List? = null, + ) + + private data class Users_Service( + val id: String? = null, + val name: String? = null, + val dependedOn: Users_RelationshipConnection? = null, + val dependsOn: Users_RelationshipConnection? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/union rename direct works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/union rename direct works as expected snapshot.kt new file mode 100644 index 000000000..5932b94c5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/union rename direct works as expected snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`union rename direct works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `union rename direct works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | { + | rename__renameUnion__renameUnionUnderlying: renameUnionUnderlying { + | ... on XUnderlying { + | x + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__renameUnion__renameUnionUnderlying": { + | "x": 1 + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameUnion": { + * "x": 1 + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameUnion": { + | "x": 1 + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/union rename direct works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/union rename direct works as expected.kt new file mode 100644 index 000000000..c6f0221ec --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/union rename direct works as expected.kt @@ -0,0 +1,158 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `union rename direct works as expected` : NadelLegacyIntegrationTest( + query = """ + query { + renameUnion { + ... on X { + x + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameUnionUnderlying") { env -> + MyService_XUnderlying(x = 1) + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/variable referenced input types rename works as expected snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/variable referenced input types rename works as expected snapshot.kt new file mode 100644 index 000000000..66834ad06 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/variable referenced input types rename works as expected snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`variable referenced input types rename works as expected`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `variable referenced input types rename works as expected snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "MyService", + query = """ + | query X { + | renameInput(arg1: {inputVal : "x"}) + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "renameInput": "done" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "renameInput": "done" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "renameInput": "done" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/variable referenced input types rename works as expected.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/variable referenced input types rename works as expected.kt new file mode 100644 index 000000000..5c0978c7d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/renames/variable referenced input types rename works as expected.kt @@ -0,0 +1,158 @@ +package graphql.nadel.tests.legacy.renames + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `variable referenced input types rename works as expected` : NadelLegacyIntegrationTest( + query = """ + query X(${'$'}var1: InputOverall!, ${'$'}var2: URL, ${'$'}var3: EnumOverall) { + renameInput(arg1: ${'$'}var1, arg2: ${'$'}var2, arg3: ${'$'}var3) + } + """.trimIndent(), + variables = mapOf("var1" to mapOf("inputVal" to "x")), + services = listOf( + Service( + name = "MyService", + overallSchema = """ + type Query { + hello: World + renameObject: ObjectOverall @renamed(from: "renameObjectUnderlying") # the field is renamed + renameInterface: InterfaceOverall @renamed(from: "renameInterfaceUnderlying") + renameUnion: UnionOverall @renamed(from: "renameUnionUnderlying") + renameInput(arg1: InputOverall!, arg2: URL, arg3: EnumOverall): String + renameString: String @renamed(from: "renameStringUnderlying") + typenameTest: TypenameTest + } + type World { + id: ID + name: String + } + type ObjectOverall implements InterfaceOverall @renamed(from: "ObjectUnderlying") { + name: String + } + interface InterfaceOverall @renamed(from: "InterfaceUnderlying") { + name: String + } + union UnionOverall @renamed(from: "UnionUnderlying") = X | Y + type X @renamed(from: "XUnderlying") { + x: Int + } + type Y @renamed(from: "YUnderlying") { + y: Int + } + input InputOverall @renamed(from: "InputUnderlying") { + inputVal: String + } + scalar URL @renamed(from: "String") + enum EnumOverall @renamed(from: "EnumUnderlying") { + X, Y + } + type TypenameTest { + object: ObjectOverall + objects: [ObjectOverall] + } + """.trimIndent(), + underlyingSchema = """ + interface InterfaceUnderlying { + name: String + } + union UnionUnderlying = XUnderlying | YUnderlying + type ObjectUnderlying implements InterfaceUnderlying { + name: String + } + type Query { + hello: World + renameInput(arg1: InputUnderlying!, arg2: String, arg3: EnumUnderlying): String + renameInterfaceUnderlying: InterfaceUnderlying + renameObjectUnderlying: ObjectUnderlying + renameStringUnderlying: String + renameUnionUnderlying: UnionUnderlying + typenameTest: TypenameTest + } + type TypenameTest { + object: ObjectUnderlying + objects: [ObjectUnderlying] + } + type World { + id: ID + name: String + } + type XUnderlying { + x: Int + } + type YUnderlying { + y: Int + } + enum EnumUnderlying { + X + Y + } + input InputUnderlying { + inputVal: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("renameInput") { env -> + if (env.getArgument("arg1") == mapOf("inputVal" to "x")) { + "done" + } else { + null + } + } + } + wiring.type("InterfaceUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + + wiring.type("UnionUnderlying") { type -> + type.typeResolver { typeResolver -> + val obj = typeResolver.getObject() + val typeName = obj.javaClass.simpleName.substringAfter("_") + typeResolver.schema.getTypeAs(typeName) + } + } + }, + ), + ), +) { + private enum class MyService_EnumUnderlying { + X, + Y, + } + + private data class MyService_InputUnderlying( + val inputVal: String? = null, + ) + + private interface MyService_InterfaceUnderlying { + val name: String? + } + + private data class MyService_ObjectUnderlying( + override val name: String? = null, + ) : MyService_InterfaceUnderlying + + private data class MyService_TypenameTest( + val `object`: MyService_ObjectUnderlying? = null, + val objects: List? = null, + ) + + private sealed interface MyService_UnionUnderlying + + private data class MyService_World( + val id: String? = null, + val name: String? = null, + ) + + private data class MyService_XUnderlying( + val x: Int? = null, + ) : MyService_UnionUnderlying + + private data class MyService_YUnderlying( + val y: Int? = null, + ) : MyService_UnionUnderlying +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/calls to multiple services are merged snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/calls to multiple services are merged snapshot.kt new file mode 100644 index 000000000..4a6eed44b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/calls to multiple services are merged snapshot.kt @@ -0,0 +1,128 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`calls to multiple services are merged`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `calls to multiple services are merged snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "bar", + query = """ + | { + | bar(id: "1") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bar": { + | "name": "Bart" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "foo", + query = """ + | { + | foo(id: "1") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "name": "Hello" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "foo", + query = """ + | { + | loot: foo(id: "1") { + | name + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "loot": { + | "name": "World" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "loot": { + * "name": "World" + * }, + * "foo": { + * "name": "Hello" + * }, + * "bar": { + * "name": "Bart" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "loot": { + | "name": "World" + | }, + | "foo": { + | "name": "Hello" + | }, + | "bar": { + | "name": "Bart" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/calls to multiple services are merged.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/calls to multiple services are merged.kt new file mode 100644 index 000000000..84aaa79a5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/calls to multiple services are merged.kt @@ -0,0 +1,92 @@ +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `calls to multiple services are merged` : NadelLegacyIntegrationTest( + query = """ + query { + loot: foo(id: "1") { + name + } + foo(id: "1") { + name + } + bar(id: "1") { + name + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "foo", + overallSchema = """ + type Query { + foo(id: ID!): Foo + } + type Foo { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(id: ID!): Foo + } + type Foo { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("id") == "1" && env.field.alias == null) { + Foo_Foo(name = "Hello") + } else if (env.getArgument("id") == "1") { + Foo_Foo(name = "World") + } else { + null + } + } + } + }, + ), + Service( + name = "bar", + overallSchema = """ + type Query { + bar(id: ID!): Bar + } + type Bar { + name: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + bar(id: ID!): Bar + } + type Bar { + name: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bar") { env -> + if (env.getArgument("id") == "1") { + Bar_Bar(name = "Bart") + } else { + null + } + } + } + }, + ), + ), +) { + private data class Foo_Foo( + val name: String? = null, + ) + + private data class Bar_Bar( + val name: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on failed result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on failed result snapshot.kt new file mode 100644 index 000000000..31ac41d1a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on failed result snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`correct selection set on failed result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `correct selection set on failed result snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Test", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Test", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on failed result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on failed result.kt new file mode 100644 index 000000000..8a47ef477 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on failed result.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.NadelServiceExecutionResultImpl +import graphql.nadel.ServiceExecution +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import java.util.concurrent.CompletableFuture + +class `correct selection set on failed result` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + override fun makeServiceExecution(service: Service): ServiceExecution = ServiceExecution { + CompletableFuture.completedFuture( + NadelServiceExecutionResultImpl( + data = mutableMapOf(), + errors = mutableListOf( + mutableMapOf( + "message" to "Test", + ), + ), + ), + ) + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on partially failed result snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on partially failed result snapshot.kt new file mode 100644 index 000000000..4296c9ee8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on partially failed result snapshot.kt @@ -0,0 +1,84 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`correct selection set on partially failed result`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `correct selection set on partially failed result snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "bar", + query = """ + | { + | bar + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bar": "Hello" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "Test", + * "locations": [], + * "extensions": { + * "classification": "DataFetchingException" + * } + * } + * ], + * "data": { + * "foo": null, + * "bar": "Hello" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "Test", + | "locations": [], + | "extensions": { + | "classification": "DataFetchingException" + | } + | } + | ], + | "data": { + | "foo": null, + | "bar": "Hello" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on partially failed result.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on partially failed result.kt new file mode 100644 index 000000000..4f0740deb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/correct selection set on partially failed result.kt @@ -0,0 +1,72 @@ +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.NadelServiceExecutionResultImpl +import graphql.nadel.ServiceExecution +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import java.util.concurrent.CompletableFuture + +class `correct selection set on partially failed result` : NadelLegacyIntegrationTest( + query = """ + query { + foo + bar + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "foo", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + Service( + name = "bar", + overallSchema = """ + type Query { + bar: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + bar: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bar") { env -> + "Hello" + } + } + }, + ), + ), +) { + override fun makeServiceExecution(service: Service): ServiceExecution { + if (service.name == "foo") { + return ServiceExecution { + CompletableFuture.completedFuture( + NadelServiceExecutionResultImpl( + data = mutableMapOf(), + errors = mutableListOf( + mutableMapOf( + "message" to "Test", + ), + ), + ), + ) + } + } else { + return super.makeServiceExecution(service) + } + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field has null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field has null snapshot.kt new file mode 100644 index 000000000..f5dec462f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field has null snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`not nullable top level field has null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `not nullable top level field has null snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "The field at path '/foo' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'String' within parent type 'Query'", + | "path": [ + | "foo" + | ], + | "extensions": { + | "classification": "NullValueInNonNullableField" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "The field at path '/foo' was declared as a non null type, but the code + * involved in retrieving data has wrongly returned a null value. The graphql specification + * requires that the parent field be set to null, or if that is non nullable that it bubble up null + * to its parent and so on. The non-nullable type is 'String' within parent type 'Query'", + * "locations": [], + * "path": [ + * "foo" + * ], + * "extensions": { + * "classification": "NullValueInNonNullableField" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "The field at path '/foo' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'String' within parent type 'Query'", + | "locations": [], + | "path": [ + | "foo" + | ], + | "extensions": { + | "classification": "NullValueInNonNullableField" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field has null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field has null.kt new file mode 100644 index 000000000..54f9f27eb --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field has null.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `not nullable top level field has null` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field is absent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field is absent snapshot.kt new file mode 100644 index 000000000..d0d76f0b6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field is absent snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`not nullable top level field is absent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `not nullable top level field is absent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "errors": [ + | { + | "message": "The field at path '/foo' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'String' within parent type 'Query'", + | "path": [ + | "foo" + | ], + | "extensions": { + | "classification": "NullValueInNonNullableField" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "errors": [ + * { + * "message": "The field at path '/foo' was declared as a non null type, but the code + * involved in retrieving data has wrongly returned a null value. The graphql specification + * requires that the parent field be set to null, or if that is non nullable that it bubble up null + * to its parent and so on. The non-nullable type is 'String' within parent type 'Query'", + * "locations": [], + * "path": [ + * "foo" + * ], + * "extensions": { + * "classification": "NullValueInNonNullableField" + * } + * } + * ], + * "data": null + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "errors": [ + | { + | "message": "The field at path '/foo' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value. The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'String' within parent type 'Query'", + | "locations": [], + | "path": [ + | "foo" + | ], + | "extensions": { + | "classification": "NullValueInNonNullableField" + | } + | } + | ], + | "data": null + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field is absent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field is absent.kt new file mode 100644 index 000000000..eac6a9e2e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/result merging/not nullable top level field is absent.kt @@ -0,0 +1,34 @@ +package graphql.nadel.tests.legacy.`result merging` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `not nullable top level field is absent` : NadelLegacyIntegrationTest( + query = """ + query { + foo + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String! + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as input type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as input type snapshot.kt new file mode 100644 index 000000000..fcf79fed1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as input type snapshot.kt @@ -0,0 +1,79 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`custom json scalar as input type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `custom json scalar as input type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | query (${'$'}v0: JSON) { + | foo(input: ${'$'}v0) { + | id + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "something": true, + | "answer": "42" + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "foo": { + | "id": "10000" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "id": "10000" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "id": "10000" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as input type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as input type.kt new file mode 100644 index 000000000..716856e81 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as input type.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `custom json scalar as input type` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: {something: true answer: "42"}) { + id + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: JSON): Foo + } + type Foo { + id: ID! + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: JSON): Foo + } + type Foo { + id: ID! + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input") == mapOf("something" to true, "answer" to "42")) { + Service_Foo(id = "10000") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as output type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as output type snapshot.kt new file mode 100644 index 000000000..e0d79de00 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as output type snapshot.kt @@ -0,0 +1,130 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`custom json scalar as output type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `custom json scalar as output type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": "1000" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | bField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bField": 1000 + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | cField: bField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "cField": { + | "Something": "Cool" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | dField: aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "dField": false + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "1000", + * "bField": 1000, + * "cField": { + * "Something": "Cool" + * }, + * "dField": false + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "1000", + | "bField": 1000, + | "cField": { + | "Something": "Cool" + | }, + | "dField": false + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as output type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as output type.kt new file mode 100644 index 000000000..568915dc4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/custom json scalar as output type.kt @@ -0,0 +1,59 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `custom json scalar as output type` : NadelLegacyIntegrationTest( + query = """ + query { + aField + bField + cField: bField + dField: aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: JSON + bField: JSON + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: JSON + bField: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("aField") { env -> + if (env.field.resultKey == "aField") { + "1000" + } else if (env.field.resultKey == "dField") { + false + } else { + null + } + } + .dataFetcher("bField") { env -> + if (env.field.resultKey == "bField") { + 1_000 + } else if (env.field.resultKey == "cField") { + mapOf("Something" to "Cool") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as input type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as input type snapshot.kt new file mode 100644 index 000000000..0ddf728a2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as input type snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`date time scalar as input type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `date time scalar as input type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo(input: "2022-03-09T05:01:50Z") { + | thing + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "thing": "What, were you expecting something else?" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "thing": "What, were you expecting something else?" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "thing": "What, were you expecting something else?" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as input type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as input type.kt new file mode 100644 index 000000000..d3d97887f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as input type.kt @@ -0,0 +1,72 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.NadelSchemas +import graphql.nadel.tests.GatewaySchemaWiringFactory +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `date time scalar as input type` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: "2022-03-09T05:01:50Z") { + thing + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: DateTime): Foo + } + type Foo { + thing: JSON + } + scalar JSON + scalar DateTime + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: DateTime): Foo + } + type Foo { + thing: JSON + } + scalar JSON + scalar DateTime + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input") == "2022-03-09T05:01:50Z") { + Service_Foo(thing = "What, were you expecting something else?") + } else { + null + } + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("DateTime") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + override fun makeNadelSchemas(): NadelSchemas.Builder { + return super.makeNadelSchemas() + .overallWiringFactory(GatewaySchemaWiringFactory()) + .underlyingWiringFactory(GatewaySchemaWiringFactory()) + } + + private data class Service_Foo( + val thing: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as output type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as output type snapshot.kt new file mode 100644 index 000000000..67477dcdd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as output type snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`date time scalar as output type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `date time scalar as output type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": "2022-03-09T05:01:50Z" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "2022-03-09T05:01:50Z" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "2022-03-09T05:01:50Z" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as output type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as output type.kt new file mode 100644 index 000000000..62cea217e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar as output type.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `date time scalar as output type` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: DateTime + } + scalar DateTime + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: DateTime + } + scalar DateTime + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("aField") { env -> + "2022-03-09T05:01:50Z" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("DateTime") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar is passthrough and can be anything technically snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar is passthrough and can be anything technically snapshot.kt new file mode 100644 index 000000000..f34f5588e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar is passthrough and can be anything technically snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`date time scalar is passthrough and can be anything technically`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `date time scalar is passthrough and can be anything technically snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "KFC Good" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar is passthrough and can be anything technically.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar is passthrough and can be anything technically.kt new file mode 100644 index 000000000..ec6cc3bb5 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/date time scalar is passthrough and can be anything technically.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `date time scalar is passthrough and can be anything technically` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: DateTime + } + scalar DateTime + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: DateTime + } + scalar DateTime + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("aField") { env -> + "KFC Good" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("DateTime") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating json data snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating json data snapshot.kt new file mode 100644 index 000000000..742dc9ae8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating json data snapshot.kt @@ -0,0 +1,107 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydrating json data`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydrating json data snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Baz", + query = """ + | { + | otherFoo(id: "10000") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "otherFoo": { + | "id": "-10000" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | query (${'$'}v0: JSON) { + | foo(input: ${'$'}v0) { + | __typename__hydration__foo: __typename + | hydration__foo__id: id + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "something": true, + | "answer": "42" + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "foo": { + | "hydration__foo__id": "10000", + | "__typename__hydration__foo": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "foo": { + * "id": "-10000" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "foo": { + | "id": "-10000" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating json data.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating json data.kt new file mode 100644 index 000000000..dfca84a20 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating json data.kt @@ -0,0 +1,106 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `hydrating json data` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: {something: true answer: "42"}) { + foo { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: JSON): Foo + } + type Foo { + id: ID! + foo: Foo @hydrated( + service: "Baz" + field: "otherFoo" + arguments: [{ name: "id" value: "${'$'}source.id" }] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: JSON): Foo + } + type Foo { + id: ID! + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input") == mapOf("something" to true, "answer" to "42")) { + Service_Foo(id = "10000") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + Service( + name = "Baz", + overallSchema = """ + type Query { + otherFoo(id: ID!): Foo @hidden + } + """.trimIndent(), + underlyingSchema = """ + type Query { + otherFoo(id: ID!): Foo + } + type Foo { + id: ID! + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("otherFoo") { env -> + if (env.getArgument("id") == "10000") { + Baz_Foo(id = "-10000") + } else { + null + } + } + } + }, + ), + Service( + name = "Shared", + overallSchema = """ + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) + + private data class Baz_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using date time as arg snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using date time as arg snapshot.kt new file mode 100644 index 000000000..f41ebbe0d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using date time as arg snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydrating using date time as arg`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydrating using date time as arg snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__hydration__successor: __typename + | hydration__successor__createdAt: createdAt + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__successor__createdAt": "2022-03-09T05:01:50Z", + | "__typename__hydration__successor": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | successor(after: "2022-03-09T05:01:50Z") { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "successor": { + | "id": "2023" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "successor": { + * "id": "2023" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "successor": { + | "id": "2023" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using date time as arg.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using date time as arg.kt new file mode 100644 index 000000000..4592abdf0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using date time as arg.kt @@ -0,0 +1,80 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `hydrating using date time as arg` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + successor { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + successor(after: DateTime): Foo + } + type Foo { + id: ID + createdAt: DateTime + successor: Foo + @hydrated( + service: "service" + field: "successor" + arguments: [{ name: "after" value: "${'$'}source.createdAt" }] + ) + } + scalar DateTime + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + successor(after: DateTime): Foo + } + type Foo { + id: ID + createdAt: DateTime + successor: Foo + } + scalar DateTime + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Service_Foo(createdAt = "2022-03-09T05:01:50Z") + } + .dataFetcher("successor") { env -> + if (env.getArgument("after") == "2022-03-09T05:01:50Z") { + Service_Foo(id = "2023") + } else { + null + } + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("DateTime") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val createdAt: String? = null, + val successor: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using json data as arg snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using json data as arg snapshot.kt new file mode 100644 index 000000000..27010f61f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using json data as arg snapshot.kt @@ -0,0 +1,123 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydrating using json data as arg`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydrating using json data as arg snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Baz", + query = """ + | query (${'$'}v0: JSON!) { + | baz(data: ${'$'}v0) { + | id + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "id": "102", + | "appConfig": { + | "status": "active", + | "bounce": false + | } + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "baz": { + | "id": "10000" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | query (${'$'}v0: JSON) { + | foo(input: ${'$'}v0) { + | __typename__hydration__foo: __typename + | hydration__foo__baz: baz + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "something": true, + | "answer": "42" + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "foo": { + | "hydration__foo__baz": { + | "id": "102", + | "appConfig": { + | "status": "active", + | "bounce": false + | } + | }, + | "__typename__hydration__foo": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "foo": { + * "id": "10000" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "foo": { + | "id": "10000" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using json data as arg.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using json data as arg.kt new file mode 100644 index 000000000..7d969b8de --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using json data as arg.kt @@ -0,0 +1,129 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `hydrating using json data as arg` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: {something: true answer: "42"}) { + foo { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: JSON): Foo + } + type Foo { + id: ID! + baz: JSON @hidden + foo: Foo @hydrated( + service: "Baz" + field: "baz" + arguments: [{ name: "data" value: "${'$'}source.baz" }] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: JSON): Foo + } + type Foo { + id: ID! + baz: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input") == mapOf("something" to true, "answer" to "42")) { + Service_Foo( + baz = mapOf( + "id" to "102", + "appConfig" to mapOf( + "status" to "active", + "bounce" to false, + ), + ), + ) + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + Service( + name = "Baz", + overallSchema = """ + type Query { + baz(data: JSON!): Foo @hidden + } + """.trimIndent(), + underlyingSchema = """ + type Query { + baz(data: JSON!): Foo + } + type Foo { + id: ID! + baz: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("baz") { env -> + if (env.getArgument("data") == + mapOf( + "id" to "102", + "appConfig" to mapOf( + "status" to "active", + "bounce" to false, + ), + ) + ) { + Baz_Foo(id = "10000") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + Service( + name = "Shared", + overallSchema = """ + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val baz: Any? = null, + ) + + private data class Baz_Foo( + val id: String? = null, + val baz: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using long as arg snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using long as arg snapshot.kt new file mode 100644 index 000000000..0b69dd200 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using long as arg snapshot.kt @@ -0,0 +1,100 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydrating using long as arg`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydrating using long as arg snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__hydration__successor: __typename + | hydration__successor__createdAt: createdAt + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "hydration__successor__createdAt": 3000000000, + | "__typename__hydration__successor": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | successor(after: 3000000000) { + | id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "successor": { + | "id": "2023" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "successor": { + * "id": "2023" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "successor": { + | "id": "2023" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using long as arg.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using long as arg.kt new file mode 100644 index 000000000..5e7f2a657 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using long as arg.kt @@ -0,0 +1,81 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar +import java.math.BigInteger + +class `hydrating using long as arg` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + successor { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + successor(after: Long): Foo + } + type Foo { + id: ID + createdAt: Long + successor: Foo + @hydrated( + service: "service" + field: "successor" + arguments: [{ name: "after" value: "${'$'}source.createdAt" }] + ) + } + scalar Long + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + successor(after: Long): Foo + } + type Foo { + id: ID + createdAt: Long + successor: Foo + } + scalar Long + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Service_Foo(createdAt = 3_000_000_000) + } + .dataFetcher("successor") { env -> + if (env.getArgument("after") == BigInteger.valueOf(3_000_000_000)) { + Service_Foo(id = "2023") + } else { + null + } + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("Long") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val createdAt: Long? = null, + val successor: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using url as arg snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using url as arg snapshot.kt new file mode 100644 index 000000000..f1982d32e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using url as arg snapshot.kt @@ -0,0 +1,112 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`hydrating using url as arg`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `hydrating using url as arg snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__hydration__details: __typename + | url + | hydration__details__url: url + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "url": "https://github.com/atlassian-labs/nadel", + | "hydration__details__url": "https://github.com/atlassian-labs/nadel", + | "__typename__hydration__details": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | lookup(url: "https://github.com/atlassian-labs/nadel") { + | baseUrl + | createdAt + | owner + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "lookup": { + | "baseUrl": "https://github.com/", + | "owner": "amarek", + | "createdAt": "2018-02-13T06:23:41Z" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "url": "https://github.com/atlassian-labs/nadel", + * "details": { + * "baseUrl": "https://github.com/", + * "owner": "amarek", + * "createdAt": "2018-02-13T06:23:41Z" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "url": "https://github.com/atlassian-labs/nadel", + | "details": { + | "baseUrl": "https://github.com/", + | "owner": "amarek", + | "createdAt": "2018-02-13T06:23:41Z" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using url as arg.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using url as arg.kt new file mode 100644 index 000000000..50c96b4c2 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/hydrating using url as arg.kt @@ -0,0 +1,110 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `hydrating using url as arg` : NadelLegacyIntegrationTest( + query = """ + query { + foo { + url + details { + baseUrl + owner + createdAt + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + lookup(url: URL): Lookup @hidden + } + type Foo { + id: ID + url: URL + details: Lookup + @hydrated( + service: "service" + field: "lookup" + arguments: [{ name: "url" value: "${'$'}source.url" }] + ) + } + type Lookup { + baseUrl: URL + createdAt: DateTime + owner: String + } + scalar URL + scalar DateTime + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + lookup(url: URL): Lookup + } + type Foo { + id: ID + url: URL + } + type Lookup { + baseUrl: URL + createdAt: DateTime + owner: String + } + scalar URL + scalar DateTime + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("foo") { env -> + Service_Foo(url = "https://github.com/atlassian-labs/nadel") + } + .dataFetcher("lookup") { env -> + if (env.getArgument("url") == "https://github.com/atlassian-labs/nadel") { + Service_Lookup( + baseUrl = "https://github.com/", + createdAt = "2018-02-13T06:23:41Z", + owner = "amarek", + ) + } else { + null + } + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("DateTime") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + wiring.scalar( + AliasedScalar + .Builder() + .name("URL") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val url: String? = null, + ) + + private data class Service_Lookup( + val baseUrl: String? = null, + val createdAt: String? = null, + val owner: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/indexed hydrating using json data as arg snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/indexed hydrating using json data as arg snapshot.kt new file mode 100644 index 000000000..fea74c8b8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/indexed hydrating using json data as arg snapshot.kt @@ -0,0 +1,217 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`indexed hydrating using json data as arg`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `indexed hydrating using json data as arg snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "Baz", + query = """ + | query (${'$'}v0: [JSON!]!) { + | baz(data: ${'$'}v0) { + | id + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": [ + | { + | "app-config": { + | "status": "deactivated", + | "bounce": true + | } + | } + | ] + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "baz": [ + | { + | "id": "deactivated thing" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "Baz", + query = """ + | query (${'$'}v0: [JSON!]!) { + | baz(data: ${'$'}v0) { + | id + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": [ + | { + | "id": "102", + | "appConfig": { + | "status": "active", + | "bounce": false + | } + | }, + | { + | "ari": "ari:cloud:api-platform::thing/103", + | "config": { + | "status": "active", + | "bounce": true + | } + | } + | ] + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "baz": [ + | { + | "id": "102" + | }, + | { + | "id": "active bounce 103 thing" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | query (${'$'}v0: JSON) { + | foo(input: ${'$'}v0) { + | __typename__batch_hydration__foo: __typename + | batch_hydration__foo__baz: baz + | } + | } + """.trimMargin(), + variables = """ + | { + | "v0": { + | "something": true, + | "answer": "42" + | } + | } + """.trimMargin(), + result = """ + | { + | "data": { + | "foo": [ + | { + | "batch_hydration__foo__baz": { + | "id": "102", + | "appConfig": { + | "status": "active", + | "bounce": false + | } + | }, + | "__typename__batch_hydration__foo": "Foo" + | }, + | { + | "batch_hydration__foo__baz": { + | "ari": "ari:cloud:api-platform::thing/103", + | "config": { + | "status": "active", + | "bounce": true + | } + | }, + | "__typename__batch_hydration__foo": "Foo" + | }, + | { + | "batch_hydration__foo__baz": { + | "app-config": { + | "status": "deactivated", + | "bounce": true + | } + | }, + | "__typename__batch_hydration__foo": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": [ + * { + * "foo": { + * "id": "102" + * } + * }, + * { + * "foo": { + * "id": "active bounce 103 thing" + * } + * }, + * { + * "foo": { + * "id": "deactivated thing" + * } + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": [ + | { + | "foo": { + | "id": "102" + | } + | }, + | { + | "foo": { + | "id": "active bounce 103 thing" + | } + | }, + | { + | "foo": { + | "id": "deactivated thing" + | } + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/indexed hydrating using json data as arg.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/indexed hydrating using json data as arg.kt new file mode 100644 index 000000000..5e59e41c0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/indexed hydrating using json data as arg.kt @@ -0,0 +1,170 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `indexed hydrating using json data as arg` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: {something: true answer: "42"}) { + foo { + id + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: JSON): [Foo] + } + type Foo { + id: ID! + baz: JSON @hidden + foo: Foo @hydrated( + service: "Baz" + field: "baz" + arguments: [{ name: "data" value: "${'$'}source.baz" }] + indexed: true + batchSize: 2 + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: JSON): [Foo] + } + type Foo { + id: ID! + baz: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input") == mapOf("something" to true, "answer" to "42")) { + listOf( + Service_Foo( + baz = mapOf( + "id" to "102", + "appConfig" to mapOf( + "status" to "active", + "bounce" to false, + ), + ), + ), + Service_Foo( + baz = mapOf( + "ari" to "ari:cloud:api-platform::thing/103", + "config" to mapOf( + "status" to "active", + "bounce" to true, + ), + ), + ), + Service_Foo( + baz = mapOf( + "app-config" to mapOf( + "status" to "deactivated", + "bounce" to true, + ), + ), + ), + ) + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + Service( + name = "Baz", + overallSchema = """ + type Query { + baz(data: [JSON!]!): [Foo] @hidden + } + """.trimIndent(), + underlyingSchema = """ + type Query { + baz(data: [JSON!]!): [Foo] + } + type Foo { + id: ID! + baz: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("baz") { env -> + if (env.getArgument("data") == + listOf( + mapOf( + "id" to "102", + "appConfig" to mapOf( + "status" to "active", + "bounce" to false, + ), + ), + mapOf( + "ari" to "ari:cloud:api-platform::thing/103", + "config" to mapOf( + "status" to "active", + "bounce" to true, + ), + ), + ) + ) { + listOf(Baz_Foo(id = "102"), Baz_Foo(id = "active bounce 103 thing")) + } else if (env.getArgument("data") == + listOf( + mapOf( + "app-config" to mapOf( + "status" to "deactivated", + "bounce" to true, + ), + ), + ) + ) { + listOf(Baz_Foo(id = "deactivated thing")) + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + Service( + name = "Shared", + overallSchema = """ + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + echo: String + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val baz: Any? = null, + ) + + private data class Baz_Foo( + val id: String? = null, + val baz: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar argument with default values snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar argument with default values snapshot.kt new file mode 100644 index 000000000..4c4679418 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar argument with default values snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`long scalar argument with default values`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `long scalar argument with default values snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | getFoo(arg: 15) + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "getFoo": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "getFoo": "KFC Good" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "getFoo": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar argument with default values.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar argument with default values.kt new file mode 100644 index 000000000..773080c20 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar argument with default values.kt @@ -0,0 +1,50 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar +import java.math.BigInteger + +class `long scalar argument with default values` : NadelLegacyIntegrationTest( + query = """ + query { + getFoo(arg: 15) + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + getFoo(arg: Long = 123): String + } + scalar Long + """.trimIndent(), + underlyingSchema = """ + type Query { + getFoo(arg: Long = 123): String + } + scalar Long + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("getFoo") { env -> + if (env.getArgument("arg")?.toInt() == 15) { + "KFC Good" + } else { + null + } + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("Long") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as input type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as input type snapshot.kt new file mode 100644 index 000000000..456c5b436 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as input type snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`long scalar as input type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `long scalar as input type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo(input: 3000000000) { + | thing + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "thing": "What, were you expecting something else?" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "thing": "What, were you expecting something else?" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "thing": "What, were you expecting something else?" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as input type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as input type.kt new file mode 100644 index 000000000..abe4913c9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as input type.kt @@ -0,0 +1,65 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar +import java.math.BigInteger + +class `long scalar as input type` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: 3000000000) { + thing + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: Long): Foo + } + type Foo { + thing: JSON + } + scalar JSON + scalar Long + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: Long): Foo + } + type Foo { + thing: JSON + } + scalar JSON + scalar Long + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input")?.toLong() == 3_000_000_000L) { + Service_Foo(thing = "What, were you expecting something else?") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + wiring.scalar( + AliasedScalar + .Builder() + .name("Long") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) { + private data class Service_Foo( + val thing: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as output type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as output type snapshot.kt new file mode 100644 index 000000000..562a65146 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as output type snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`long scalar as output type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `long scalar as output type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": 3000000000 + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": 3000000000 + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": 3000000000 + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as output type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as output type.kt new file mode 100644 index 000000000..843ab3520 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar as output type.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `long scalar as output type` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: Long + } + scalar Long + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: Long + } + scalar Long + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("aField") { env -> + 3_000_000_000 + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("Long") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar is passthrough and can be anything technically snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar is passthrough and can be anything technically snapshot.kt new file mode 100644 index 000000000..9a751f71c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar is passthrough and can be anything technically snapshot.kt @@ -0,0 +1,65 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`long scalar is passthrough and can be anything technically`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `long scalar is passthrough and can be anything technically snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "KFC Good" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar is passthrough and can be anything technically.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar is passthrough and can be anything technically.kt new file mode 100644 index 000000000..9bd6e32ca --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/long scalar is passthrough and can be anything technically.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `long scalar is passthrough and can be anything technically` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: Long + } + scalar Long + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: Long + } + scalar Long + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("aField") { env -> + "KFC Good" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("Long") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming date time typed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming date time typed field snapshot.kt new file mode 100644 index 000000000..b8a4db070 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming date time typed field snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renaming date time typed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renaming date time typed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__aField__test: test + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__aField__test": "2022-03-09T05:01:50Z" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "2022-03-09T05:01:50Z" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "2022-03-09T05:01:50Z" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming date time typed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming date time typed field.kt new file mode 100644 index 000000000..93698bb38 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming date time typed field.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `renaming date time typed field` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: DateTime @renamed(from: "test") + } + scalar DateTime + """.trimIndent(), + underlyingSchema = """ + type Query { + test: DateTime + } + scalar DateTime + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("test") { env -> + "2022-03-09T05:01:50Z" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("DateTime") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming json typed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming json typed field snapshot.kt new file mode 100644 index 000000000..647f33713 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming json typed field snapshot.kt @@ -0,0 +1,90 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renaming json typed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renaming json typed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__aField__test: test + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__aField__test": { + | "object": "aField" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__test__test: test + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__test__test": false + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": { + * "object": "aField" + * }, + * "test": false + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": { + | "object": "aField" + | }, + | "test": false + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming json typed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming json typed field.kt new file mode 100644 index 000000000..e14165f56 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming json typed field.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars + +class `renaming json typed field` : NadelLegacyIntegrationTest( + query = """ + query { + aField + test: aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: JSON @renamed(from: "test") + } + scalar JSON + """.trimIndent(), + underlyingSchema = """ + type Query { + test: JSON + } + scalar JSON + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("test") { env -> + if (env.field.resultKey == "rename__aField__test") { + mapOf("object" to "aField") + } else if (env.field.resultKey == "rename__test__test") { + false + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming url typed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming url typed field snapshot.kt new file mode 100644 index 000000000..d7d006ab8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming url typed field snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`renaming url typed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `renaming url typed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__aField__test: test + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__aField__test": "https://github.com/atlassian-labs/nadel" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "https://github.com/atlassian-labs/nadel" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "https://github.com/atlassian-labs/nadel" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming url typed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming url typed field.kt new file mode 100644 index 000000000..ec127e83b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/renaming url typed field.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `renaming url typed field` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: URL @renamed(from: "test") + } + scalar URL + """.trimIndent(), + underlyingSchema = """ + type Query { + test: URL + } + scalar URL + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("test") { env -> + "https://github.com/atlassian-labs/nadel" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("URL") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as input type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as input type snapshot.kt new file mode 100644 index 000000000..a675e3672 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as input type snapshot.kt @@ -0,0 +1,72 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`url scalar as input type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `url scalar as input type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo(input: "https://atlassian.com") { + | thing + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "thing": "What, were you expecting something else?" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "thing": "What, were you expecting something else?" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "thing": "What, were you expecting something else?" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as input type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as input type.kt new file mode 100644 index 000000000..98dab651a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as input type.kt @@ -0,0 +1,64 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `url scalar as input type` : NadelLegacyIntegrationTest( + query = """ + query { + foo(input: "https://atlassian.com") { + thing + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo(input: URL): Foo + } + type Foo { + thing: JSON + } + scalar JSON + scalar URL + """.trimIndent(), + underlyingSchema = """ + type Query { + foo(input: URL): Foo + } + type Foo { + thing: JSON + } + scalar JSON + scalar URL + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + if (env.getArgument("input") == "https://atlassian.com") { + Service_Foo(thing = "What, were you expecting something else?") + } else { + null + } + } + } + wiring.scalar(ExtendedScalars.Json) + wiring.scalar( + AliasedScalar + .Builder() + .name("URL") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) { + private data class Service_Foo( + val thing: Any? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as output type snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as output type snapshot.kt new file mode 100644 index 000000000..63d0185df --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as output type snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`url scalar as output type`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `url scalar as output type snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": "https://atlassian.com" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "https://atlassian.com" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "https://atlassian.com" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as output type.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as output type.kt new file mode 100644 index 000000000..4f48cefe1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar as output type.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `url scalar as output type` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: URL + } + scalar URL + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: URL + } + scalar URL + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("aField") { env -> + "https://atlassian.com" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("URL") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar is passthrough and can be anything technically snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar is passthrough and can be anything technically snapshot.kt new file mode 100644 index 000000000..3ea3ddfdc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar is passthrough and can be anything technically snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`url scalar is passthrough and can be anything technically`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `url scalar is passthrough and can be anything technically snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | aField + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "aField": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "aField": "KFC Good" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "aField": "KFC Good" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar is passthrough and can be anything technically.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar is passthrough and can be anything technically.kt new file mode 100644 index 000000000..5d6903528 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/scalars/url scalar is passthrough and can be anything technically.kt @@ -0,0 +1,45 @@ +package graphql.nadel.tests.legacy.scalars + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar + +class `url scalar is passthrough and can be anything technically` : NadelLegacyIntegrationTest( + query = """ + query { + aField + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + aField: URL + } + scalar URL + """.trimIndent(), + underlyingSchema = """ + type Query { + aField: URL + } + scalar URL + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("aField") { env -> + "KFC Good" + } + } + wiring.scalar( + AliasedScalar + .Builder() + .name("URL") + .aliasedScalar(ExtendedScalars.Json) + .build(), + ) + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/schema/can delete fields and types snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/schema/can delete fields and types snapshot.kt new file mode 100644 index 000000000..ab54ed56d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/schema/can delete fields and types snapshot.kt @@ -0,0 +1,184 @@ +// @formatter:off +package graphql.nadel.tests.legacy.schema + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`can delete fields and types`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `can delete fields and types snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": { + * "__schema": { + * "types": [ + * { + * "name": "Bar" + * }, + * { + * "name": "Boolean" + * }, + * { + * "name": "Float" + * }, + * { + * "name": "Foo" + * }, + * { + * "name": "ID" + * }, + * { + * "name": "Int" + * }, + * { + * "name": "JSON" + * }, + * { + * "name": "NadelBatchObjectIdentifiedBy" + * }, + * { + * "name": "NadelHydrationArgument" + * }, + * { + * "name": "NadelHydrationCondition" + * }, + * { + * "name": "NadelHydrationResultCondition" + * }, + * { + * "name": "NadelHydrationResultFieldPredicate" + * }, + * { + * "name": "Query" + * }, + * { + * "name": "String" + * }, + * { + * "name": "__Directive" + * }, + * { + * "name": "__DirectiveLocation" + * }, + * { + * "name": "__EnumValue" + * }, + * { + * "name": "__Field" + * }, + * { + * "name": "__InputValue" + * }, + * { + * "name": "__Schema" + * }, + * { + * "name": "__Type" + * }, + * { + * "name": "__TypeKind" + * } + * ] + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "__schema": { + | "types": [ + | { + | "name": "Bar" + | }, + | { + | "name": "Boolean" + | }, + | { + | "name": "Float" + | }, + | { + | "name": "Foo" + | }, + | { + | "name": "ID" + | }, + | { + | "name": "Int" + | }, + | { + | "name": "JSON" + | }, + | { + | "name": "NadelBatchObjectIdentifiedBy" + | }, + | { + | "name": "NadelHydrationArgument" + | }, + | { + | "name": "NadelHydrationCondition" + | }, + | { + | "name": "NadelHydrationResultCondition" + | }, + | { + | "name": "NadelHydrationResultFieldPredicate" + | }, + | { + | "name": "Query" + | }, + | { + | "name": "String" + | }, + | { + | "name": "__Directive" + | }, + | { + | "name": "__DirectiveLocation" + | }, + | { + | "name": "__EnumValue" + | }, + | { + | "name": "__Field" + | }, + | { + | "name": "__InputValue" + | }, + | { + | "name": "__Schema" + | }, + | { + | "name": "__Type" + | }, + | { + | "name": "__TypeKind" + | } + | ] + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/schema/can delete fields and types.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/schema/can delete fields and types.kt new file mode 100644 index 000000000..8a99a4a78 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/schema/can delete fields and types.kt @@ -0,0 +1,58 @@ +package graphql.nadel.tests.legacy.schema + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `can delete fields and types` : NadelLegacyIntegrationTest( + query = """ + query GetTypes { + __schema { + types { + name + } + } + } + """.trimIndent(), + variables = emptyMap(), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + echo: String + } + type Foo { + id: ID + } + type Bar { + id: ID + foo: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + echo: String + } + type Foo { + id: ID + } + type Bar { + id: ID + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Service_Bar( + val id: String? = null, + val foo: Service_Foo? = null, + ) + + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns null snapshot.kt new file mode 100644 index 000000000..329b00b61 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns null snapshot.kt @@ -0,0 +1,67 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on single field whose parent returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on single field whose parent returns null snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns null.kt new file mode 100644 index 000000000..555f64280 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns null.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on single field whose parent returns null` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + id @include(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns object snapshot.kt new file mode 100644 index 000000000..d7906eee1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns object snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on single field whose parent returns object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on single field whose parent returns object snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns object.kt new file mode 100644 index 000000000..5762ba45d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field whose parent returns object.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on single field whose parent returns object` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + id @include(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field with subselection snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field with subselection snapshot.kt new file mode 100644 index 000000000..f6f2dc94f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field with subselection snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on single field with subselection`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on single field with subselection snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field with subselection.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field with subselection.kt new file mode 100644 index 000000000..21636f77b --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single field with subselection.kt @@ -0,0 +1,52 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on single field with subselection` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + foo @include(if: ${'$'}test) { + __typename + id + } + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val foo: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field snapshot.kt new file mode 100644 index 000000000..d868c0440 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field snapshot.kt @@ -0,0 +1,42 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on single top level field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on single top level field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": {} + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": {} + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field with subselections snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field with subselections snapshot.kt new file mode 100644 index 000000000..36a022f9a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field with subselections snapshot.kt @@ -0,0 +1,43 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on single top level field with subselections`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on single top level field with subselections snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": {} + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": {} + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field with subselections.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field with subselections.kt new file mode 100644 index 000000000..b5a22c9cf --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field with subselections.kt @@ -0,0 +1,41 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on single top level field with subselections` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo @include(if: ${'$'}test) { + id + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field.kt new file mode 100644 index 000000000..2325a13c6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles include directive on single top level field.kt @@ -0,0 +1,29 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on single top level field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo @include(if: ${'$'}test) + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns null snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns null snapshot.kt new file mode 100644 index 000000000..4a880d7d3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns null snapshot.kt @@ -0,0 +1,67 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip directive on single field whose parent returns null`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip directive on single field whose parent returns null snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": null + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": null + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns null.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns null.kt new file mode 100644 index 000000000..67053508e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns null.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip directive on single field whose parent returns null` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + id @skip(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + null + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns object snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns object snapshot.kt new file mode 100644 index 000000000..53fc4b96a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns object snapshot.kt @@ -0,0 +1,69 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip directive on single field whose parent returns object`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip directive on single field whose parent returns object snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns object.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns object.kt new file mode 100644 index 000000000..aca63ec60 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field whose parent returns object.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip directive on single field whose parent returns object` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + id @skip(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field with subselection snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field with subselection snapshot.kt new file mode 100644 index 000000000..80ca1d841 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field with subselection snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip directive on single field with subselection`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip directive on single field with subselection snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field with subselection.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field with subselection.kt new file mode 100644 index 000000000..d1b13229f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single field with subselection.kt @@ -0,0 +1,52 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip directive on single field with subselection` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + foo @skip(if: ${'$'}test) { + __typename + id + } + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + val foo: Service_Foo? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field snapshot.kt new file mode 100644 index 000000000..f36e7e9fd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field snapshot.kt @@ -0,0 +1,42 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip directive on single top level field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip directive on single top level field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": {} + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": {} + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field with subselections snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field with subselections snapshot.kt new file mode 100644 index 000000000..c84875126 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field with subselections snapshot.kt @@ -0,0 +1,43 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip directive on single top level field with subselections`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip directive on single top level field with subselections snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ) + + /** + * ```json + * { + * "data": {} + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": {} + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field with subselections.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field with subselections.kt new file mode 100644 index 000000000..d2ebb59e0 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field with subselections.kt @@ -0,0 +1,41 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip directive on single top level field with subselections` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo @skip(if: ${'$'}test) { + id + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field.kt new file mode 100644 index 000000000..5f0e821cd --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on single top level field.kt @@ -0,0 +1,29 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip directive on single top level field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo @skip(if: ${'$'}test) + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on top level field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on top level field snapshot.kt new file mode 100644 index 000000000..c8b2135e1 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on top level field snapshot.kt @@ -0,0 +1,64 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip directive on top level field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip directive on top level field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | bar + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "bar": "Bar" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "bar": "Bar" + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "bar": "Bar" + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on top level field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on top level field.kt new file mode 100644 index 000000000..19040f6e6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip directive on top level field.kt @@ -0,0 +1,37 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip directive on top level field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo @skip(if: ${'$'}test) + bar @include(if: ${'$'}test) + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: String + bar: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: String + bar: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bar") { env -> + "Bar" + } + } + }, + ), + ), +) diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field snapshot.kt new file mode 100644 index 000000000..0e1796a12 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field snapshot.kt @@ -0,0 +1,92 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip include directive on field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip include directive on field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | foo { + | __typename + | } + | bar: foo { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "foo": { + | "__typename": "Foo" + | }, + | "bar": { + | "id": "FOO-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "foo": { + * "__typename": "Foo" + * }, + * "bar": { + * "id": "FOO-1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "foo": { + | "__typename": "Foo" + | }, + | "bar": { + | "id": "FOO-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field with subselections snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field with subselections snapshot.kt new file mode 100644 index 000000000..6a7ba234c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field with subselections snapshot.kt @@ -0,0 +1,81 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles skip include directive on field with subselections`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles skip include directive on field with subselections snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | bar: foo { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "id": "FOO-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": { + * "id": "FOO-1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": { + | "id": "FOO-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field with subselections.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field with subselections.kt new file mode 100644 index 000000000..a176788c8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field with subselections.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip include directive on field with subselections` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!, ${'$'}invertTest: Boolean! = false, ${'$'}other: Boolean! = true) { + foo { + foo @skip(if: ${'$'}test) { + __typename @skip(if: ${'$'}invertTest) + id @include(if: ${'$'}test) + } + bar: foo @include(if: ${'$'}other) { + id + } + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + foo: Foo + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo(foo = Service_Foo(id = "FOO-1")) + } + } + }, + ), + ), +) { + private data class Service_Foo( + val foo: Service_Foo? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field.kt new file mode 100644 index 000000000..1fb9f700c --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/handles skip include directive on field.kt @@ -0,0 +1,55 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles skip include directive on field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + foo { + __typename @include(if: ${'$'}test) + id @skip(if: ${'$'}test) + } + bar: foo @include(if: ${'$'}test) { + id + } + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + foo: Foo + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo(foo = Service_Foo(id = "FOO-1")) + } + } + }, + ), + ), +) { + private data class Service_Foo( + val foo: Service_Foo? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive field with hydrated parent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive field with hydrated parent snapshot.kt new file mode 100644 index 000000000..db343fc14 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive field with hydrated parent snapshot.kt @@ -0,0 +1,96 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive field with hydrated parent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive field with hydrated parent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | fooById(id: "Foo-1") { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "fooById": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__foo__bar: bar { + | __typename__hydration__water: __typename + | hydration__water__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__foo__bar": { + | "hydration__water__id": "Foo-1", + | "__typename__hydration__water": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "water": {} + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "water": {} + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive field with hydrated parent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive field with hydrated parent.kt new file mode 100644 index 000000000..043879b02 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive field with hydrated parent.kt @@ -0,0 +1,65 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive field with hydrated parent` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + water { + id @include(if: ${'$'}test) + } + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo @renamed(from: "bar") + fooById(id: ID): Foo + } + type Foo { + id: String + water: Foo @hydrated( + service: "service" + field: "fooById" + arguments: [ + {name: "id" value: "${'$'}source.id"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + bar: Foo + fooById(id: ID): Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type + .dataFetcher("bar") { env -> + Service_Foo(id = "Foo-1") + } + .dataFetcher("fooById") { env -> + if (env.getArgument("id") == "Foo-1") { + Service_Foo() + } else { + null + } + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on batch hydrated field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on batch hydrated field snapshot.kt new file mode 100644 index 000000000..ea51086b7 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on batch hydrated field snapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on batch hydrated field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on batch hydrated field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foos { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "__typename__skip_include____skip": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * {} + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | {} + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on batch hydrated field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on batch hydrated field.kt new file mode 100644 index 000000000..a9e0f41a8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on batch hydrated field.kt @@ -0,0 +1,67 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on batch hydrated field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foos { + test @include(if: ${'$'}test) { + id + } + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foos: [Foo] + tests(ids: [ID]): [Test] + } + type Foo { + test: Test @hydrated( + service: "service" + field: "tests" + arguments: [ + {name: "ids" value: "${'$'}source.id"} + ] + identifiedBy: "id" + ) + } + type Test { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foos: [Foo] + tests(ids: [ID]): [Test] + } + type Foo { + id: String + } + type Test { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foos") { env -> + listOf(Service_Foo()) + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) + + private data class Service_Test( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on field with batch hydrated parent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on field with batch hydrated parent snapshot.kt new file mode 100644 index 000000000..3deb701df --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on field with batch hydrated parent snapshot.kt @@ -0,0 +1,121 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on field with batch hydrated parent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on field with batch hydrated parent snapshot` : + TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foos { + | __typename__batch_hydration__test: __typename + | batch_hydration__test__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foos": [ + | { + | "batch_hydration__test__id": "Foo-3", + | "__typename__batch_hydration__test": "Foo" + | }, + | { + | "batch_hydration__test__id": "Foo-4", + | "__typename__batch_hydration__test": "Foo" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ExpectedServiceCall( + service = "service", + query = """ + | { + | tests(ids: ["Foo-3", "Foo-4"]) { + | __typename__skip_include____skip: __typename + | batch_hydration__test__id: id + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "tests": [ + | { + | "__typename__skip_include____skip": "Test", + | "batch_hydration__test__id": "Foo-3" + | }, + | { + | "__typename__skip_include____skip": "Test", + | "batch_hydration__test__id": "Foo-4" + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foos": [ + * { + * "test": {} + * }, + * { + * "test": {} + * } + * ] + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foos": [ + | { + | "test": {} + | }, + | { + | "test": {} + | } + | ] + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on field with batch hydrated parent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on field with batch hydrated parent.kt new file mode 100644 index 000000000..8a9fbe95a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on field with batch hydrated parent.kt @@ -0,0 +1,76 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on field with batch hydrated parent` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foos { + test { + id @include(if: ${'$'}test) + } + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foos: [Foo] + tests(ids: [ID]): [Test] + } + type Foo { + test: Test @hydrated( + service: "service" + field: "tests" + arguments: [ + {name: "ids" value: "${'$'}source.id"} + ] + identifiedBy: "id" + ) + } + type Test { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foos: [Foo] + tests(ids: [ID]): [Test] + } + type Foo { + id: String + } + type Test { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + val testById = listOf( + Service_Test(id = "Foo-4"), + Service_Test(id = "Foo-3"), + ).associateBy { it.id } + + type + .dataFetcher("foos") { env -> + listOf(Service_Foo(id = "Foo-3"), Service_Foo(id = "Foo-4")) + } + .dataFetcher("tests") { env -> + env.getArgument>("ids")?.map(testById::get) + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) + + private data class Service_Test( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on hydrated field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on hydrated field snapshot.kt new file mode 100644 index 000000000..49a2c1906 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on hydrated field snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on hydrated field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on hydrated field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on hydrated field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on hydrated field.kt new file mode 100644 index 000000000..a0e6ae55a --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/hydration/handles include directive on hydrated field.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.hydration + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on hydrated field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + name @include(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + test(id: ID): String + } + type Foo { + name: String @hydrated( + service: "service" + field: "test" + arguments: [ + {name: "id" value: "${'$'}source.id"} + ] + ) + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + test(id: ID): String + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on deep renamed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on deep renamed field snapshot.kt new file mode 100644 index 000000000..8ca566c16 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on deep renamed field snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on deep renamed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on deep renamed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on deep renamed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on deep renamed field.kt new file mode 100644 index 000000000..267d227b9 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on deep renamed field.kt @@ -0,0 +1,53 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on deep renamed field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + name @include(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: ID @renamed(from: "details.id") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + details: FooDetails + } + type FooDetails { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val details: Service_FooDetails? = null, + ) + + private data class Service_FooDetails( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with deep renamed parent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with deep renamed parent snapshot.kt new file mode 100644 index 000000000..294d773d6 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with deep renamed parent snapshot.kt @@ -0,0 +1,83 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on field with deep renamed parent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on field with deep renamed parent snapshot` : TestSnapshot() + { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__deep_rename__bar: __typename + | deep_rename__bar__details: details { + | bar { + | __typename__skip_include____skip: __typename + | } + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "deep_rename__bar__details": { + | "bar": { + | "__typename__skip_include____skip": "Bar" + | } + | }, + | "__typename__deep_rename__bar": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "bar": {} + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "bar": {} + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with deep renamed parent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with deep renamed parent.kt new file mode 100644 index 000000000..77805cc61 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with deep renamed parent.kt @@ -0,0 +1,65 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on field with deep renamed parent` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + bar { + id @include(if: ${'$'}test) + } + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + bar: Bar @renamed(from: "details.bar") + } + type Bar { + id: ID + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + details: FooDetails + } + type FooDetails { + bar: Bar + } + type Bar { + id: ID + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo(details = Service_FooDetails(bar = Service_Bar())) + } + } + }, + ), + ), +) { + private data class Service_Bar( + val id: String? = null, + ) + + private data class Service_Foo( + val details: Service_FooDetails? = null, + ) + + private data class Service_FooDetails( + val bar: Service_Bar? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with renamed parent snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with renamed parent snapshot.kt new file mode 100644 index 000000000..1e271f914 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with renamed parent snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on field with renamed parent`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on field with renamed parent snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | rename__foo__bar: bar { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "rename__foo__bar": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with renamed parent.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with renamed parent.kt new file mode 100644 index 000000000..4c89e4f1e --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on field with renamed parent.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on field with renamed parent` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + id @include(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo @renamed(from: "bar") + } + type Foo { + id: String + } + """.trimIndent(), + underlyingSchema = """ + type Query { + bar: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("bar") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on renamed field snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on renamed field snapshot.kt new file mode 100644 index 000000000..28e40744d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on renamed field snapshot.kt @@ -0,0 +1,68 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`handles include directive on renamed field`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `handles include directive on renamed field snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | __typename__skip_include____skip: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": {} + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": {} + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on renamed field.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on renamed field.kt new file mode 100644 index 000000000..f96fa38cc --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/renamed/handles include directive on renamed field.kt @@ -0,0 +1,46 @@ +package graphql.nadel.tests.legacy.`skip-include-fields`.renamed + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `handles include directive on renamed field` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + name @include(if: ${'$'}test) + } + } + """.trimIndent(), + variables = mapOf("test" to false), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + name: String @renamed(from: "id") + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo() + } + } + }, + ), + ), +) { + private data class Service_Foo( + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/skip include does not affect other transforms snapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/skip include does not affect other transforms snapshot.kt new file mode 100644 index 000000000..6e4ae90f4 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/skip include does not affect other transforms snapshot.kt @@ -0,0 +1,88 @@ +// @formatter:off +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.next.ExpectedNadelResult +import graphql.nadel.tests.next.ExpectedServiceCall +import graphql.nadel.tests.next.TestSnapshot +import graphql.nadel.tests.next.listOfJsonStrings +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.listOf + +private suspend fun main() { + graphql.nadel.tests.next.update<`skip include does not affect other transforms`>() +} + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class `skip include does not affect other transforms snapshot` : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "service", + query = """ + | { + | foo { + | foo { + | __typename__skip_include____skip: __typename + | } + | bar: foo { + | id + | } + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "foo": { + | "foo": { + | "__typename__skip_include____skip": "Foo" + | }, + | "bar": { + | "id": "FOO-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "foo": { + * "foo": {}, + * "bar": { + * "id": "FOO-1" + * } + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "foo": { + | "foo": {}, + | "bar": { + | "id": "FOO-1" + | } + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/skip include does not affect other transforms.kt b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/skip include does not affect other transforms.kt new file mode 100644 index 000000000..e8ed4b90d --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/legacy/skip-include-fields/skip include does not affect other transforms.kt @@ -0,0 +1,54 @@ +package graphql.nadel.tests.legacy.`skip-include-fields` + +import graphql.nadel.tests.legacy.NadelLegacyIntegrationTest + +class `skip include does not affect other transforms` : NadelLegacyIntegrationTest( + query = """ + query (${'$'}test: Boolean!) { + foo { + foo { + id @skip(if: ${'$'}test) + } + bar: foo @include(if: ${'$'}test) { + id + } + } + } + """.trimIndent(), + variables = mapOf("test" to true), + services = listOf( + Service( + name = "service", + overallSchema = """ + type Query { + foo: Foo + } + type Foo { + id: String + foo: Foo + } + """.trimIndent(), + underlyingSchema = """ + type Query { + foo: Foo + } + type Foo { + foo: Foo + id: String + } + """.trimIndent(), + runtimeWiring = { wiring -> + wiring.type("Query") { type -> + type.dataFetcher("foo") { env -> + Service_Foo(foo = Service_Foo(id = "FOO-1")) + } + } + }, + ), + ), +) { + private data class Service_Foo( + val foo: Service_Foo? = null, + val id: String? = null, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/MigrateTests.kt b/test/src/test/kotlin/graphql/nadel/tests/next/MigrateTests.kt new file mode 100644 index 000000000..cdd3e6866 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/next/MigrateTests.kt @@ -0,0 +1,956 @@ +package graphql.nadel.tests.next + +import com.fasterxml.jackson.module.kotlin.readValue +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.MemberName +import com.squareup.kotlinpoet.ParameterSpec +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asTypeName +import com.squareup.kotlinpoet.joinToCode +import graphql.ExecutionResult +import graphql.GraphQLError +import graphql.Scalars.GraphQLBoolean +import graphql.Scalars.GraphQLFloat +import graphql.Scalars.GraphQLID +import graphql.Scalars.GraphQLInt +import graphql.Scalars.GraphQLString +import graphql.execution.DataFetcherResult +import graphql.execution.RawVariables +import graphql.introspection.Introspection +import graphql.nadel.engine.util.JsonMap +import graphql.nadel.engine.util.toGraphQLError +import graphql.nadel.engine.util.unwrapOne +import graphql.nadel.engine.util.whenType +import graphql.nadel.schema.NeverWiringFactory +import graphql.nadel.tests.ServiceCall +import graphql.nadel.tests.TestFixture +import graphql.nadel.tests.yamlObjectMapper +import graphql.normalized.ExecutableNormalizedField +import graphql.normalized.ExecutableNormalizedOperationFactory.createExecutableNormalizedOperationWithRawVariables +import graphql.scalars.ExtendedScalars +import graphql.scalars.alias.AliasedScalar +import graphql.schema.GraphQLFieldDefinition +import graphql.schema.GraphQLImplementingType +import graphql.schema.GraphQLInterfaceType +import graphql.schema.GraphQLNamedType +import graphql.schema.GraphQLScalarType +import graphql.schema.GraphQLSchema +import graphql.schema.GraphQLType +import graphql.schema.GraphQLUnionType +import graphql.schema.idl.RuntimeWiring +import graphql.schema.idl.ScalarInfo +import graphql.schema.idl.SchemaGenerator +import graphql.schema.idl.SchemaParser +import java.io.File + +const val specificTest = "" + +fun main() { + val testSrc = File("/Users/fwang/Documents/Atlassian/nadel/test/src/test/kotlin") + val fixtures = File("/Users/fwang/Documents/Atlassian/nadel/test/src/test/resources/fixtures") + + fixtures + .walkTopDown() + .filter { + it.extension == "yaml" || it.extension == "yml" + } + .filterNot { + it.name == "schema-transformation-is-applied.yml" + || it.name == "dynamic-service-resolution-directive-not-in-interface.yml" + } + .filterNot { + // Literally impossible to auto convert + it.name == "one-synthetic-hydration-call-with-longer-path-and-same-named-overall-field.yml" + || it.name == "one-hydration-call-with-longer-path-and-same-named-overall-field.yml" + } + .filter { + specificTest.isBlank() || it.name == specificTest + } + .onEach { + val file = it.relativeTo(fixtures).path + println("Porting $file") + } + .forEach { fixtureFile -> + val fixtureSubpackage = fixtureFile.parentFile.relativeTo(fixtures) + .path + .trim('/') + .replace("/", ".") + + val packageName = "graphql.nadel.tests.legacy.$fixtureSubpackage" + val testFixture = yamlObjectMapper.readValue(fixtureFile.inputStream()) + val typeSpec = makeTestTypeSpec(packageName, testFixture) + + if (typeSpec != null) { + val testClassName = ClassName(packageName, typeSpec.name!!) + FileSpec.builder(testClassName) + .addType(typeSpec) + .build() + .writeTo(testSrc) + + writeTestSnapshotClass( + testClassName, + captured = makeTestExecutionCapture(testFixture), + sourceRoot = testSrc, + ) + } + } +} + +fun makeTestExecutionCapture(fixture: TestFixture): TestExecutionCapture { + val capture = TestExecutionCapture() + + fun toExecutionResult(result: JsonMap?): ExecutionResult { + return object : ExecutionResult { + override fun getErrors(): MutableList { + return (result?.get("errors") as List?)?.mapTo(mutableListOf(), ::toGraphQLError) + ?: mutableListOf() + } + + override fun getData(): T { + return result?.get("data") as T + } + + override fun isDataPresent(): Boolean { + return result?.contains("data") == true + } + + override fun getExtensions(): MutableMap? { + return result?.get("extensions") as MutableMap? + } + + override fun toSpecification(): MutableMap { + return (result as MutableMap? ?: mutableMapOf()) + .also { + it.remove("extensions") + if (errors.isEmpty()) { + it.remove("errors") + } + } + } + } + } + + fixture.serviceCalls.forEach { + capture.capture( + service = it.serviceName, + query = it.request.query, + variables = it.request.variables, + result = toExecutionResult(it.response) + ) + } + + capture.capture(toExecutionResult(fixture.response)) + + return capture +} + +data class MigrateTestsContext( + val packageName: String, + /** + * Service -> Typename -> TypeSpec + */ + val typeSpecs: Map>, +) + +fun makeTestTypeSpec( + packageName: String, + fixture: TestFixture, +): TypeSpec? { + if (!fixture.enabled || fixture.ignored) { + return null + } + + val simpleName = fixture.name + .filter { + it.isLetter() || it.isWhitespace() + } + .trim() + + val testClassName = ClassName(packageName, simpleName) + val typeSpecs = createServiceTypes(testClassName, fixture) + val context = MigrateTestsContext(packageName, typeSpecs) + + return with(context) { + createTestClass(testClassName, fixture) + .toBuilder() + .also { builder -> + typeSpecs.values + .asSequence() + .flatMap { it.values } + .forEach(builder::addType) + } + .build() + } +} + +fun createServiceTypes( + testClassName: ClassName, + fixture: TestFixture, +): Map> { + return fixture.underlyingSchema + .entries + .associate { (serviceName, schemaText) -> + val schema = SchemaGenerator() + .makeExecutableSchema( + SchemaParser() + .parse(schemaText), + RuntimeWiring.newRuntimeWiring() + .wiringFactory(NeverWiringFactory()) + .build(), + ) + + serviceName to schema + .typeMap + .values + .asSequence() + .filterNot { + Introspection.isIntrospectionTypes(it.name) + || it == schema.queryType + || it == schema.mutationType + || it == schema.subscriptionType + } + .mapNotNull { type -> + constructType( + parentClassName = testClassName, + service = serviceName, + schema = schema, + type = type, + )?.let { type.name to it } + } + .toMap() + } +} + +context(MigrateTestsContext) +fun createTestClass(className: ClassName, fixture: TestFixture): TypeSpec { + val services = fixture.overallSchema.keys + .map { service -> + makeService(fixture, service) + } + .joinToCode(separator = ", ") + + val variablesLiteral = if (fixture.variables.isEmpty()) { + CodeBlock.Builder() + .add("emptyMap()") + .build() + } else { + javaValueToCodeLiteral(fixture.variables) + } + + return TypeSpec.classBuilder(className) + .superclass(ClassName("graphql.nadel.tests.legacy", "NadelLegacyIntegrationTest")) + .addSuperclassConstructorParameter("query = %S", fixture.query) + .addSuperclassConstructorParameter("variables = %L", variablesLiteral) + .addSuperclassConstructorParameter("services = listOf(%L)", services) + .build() +} + +context(MigrateTestsContext) +fun makeService(fixture: TestFixture, serviceName: String): CodeBlock { + val overallSchemaText = fixture.overallSchema[serviceName] + val underlyingSchemaText = fixture.underlyingSchema[serviceName] + + val underlyingSchema = SchemaGenerator() + .makeExecutableSchema( + SchemaParser() + .parse(underlyingSchemaText), + RuntimeWiring.newRuntimeWiring() + .wiringFactory(NeverWiringFactory()) + .build(), + ) + + val calls = fixture.serviceCalls + .filter { + it.serviceName == serviceName + } + + val runtimeWiring = createRuntimeWiring(serviceName, underlyingSchema, calls) + + return CodeBlock.Builder() + .addStatement( + "Service(name=%S, overallSchema=%S, underlyingSchema=%S, runtimeWiring = %L)", + serviceName, + overallSchemaText, + underlyingSchemaText, + runtimeWiring, + ) + .build() +} + +context(MigrateTestsContext) +private fun createRuntimeWiring( + serviceName: String, + underlyingSchema: GraphQLSchema, + calls: List, +): CodeBlock { + data class DataFetcherReturns( + val field: ExecutableNormalizedField, + val result: Any?, + val errors: List?, + ) + + val dataFetcherReturnsByContainerTypeName = calls + .flatMap { call -> + val operation = createExecutableNormalizedOperationWithRawVariables( + underlyingSchema, + call.request.document, + call.request.operationName, + RawVariables.of(call.request.variables), + ) + + val isNamespaceChild = fun(child: ExecutableNormalizedField): Boolean { + return child.objectTypeNames.size == 1 && child.normalizedArguments.isNotEmpty() + } + + val errors = call.response?.get("errors") as List? + + operation.topLevelFields + .flatMap { topLevelField -> + val topLevelResult = (call.response?.get("data") as? JsonMap)?.get(topLevelField.resultKey) + if (topLevelField.normalizedArguments.isEmpty()) { + if (topLevelField.children.any(isNamespaceChild)) { + topLevelField.children + .map { child -> + DataFetcherReturns( + field = child, + result = (topLevelResult as JsonMap?)?.get(child.resultKey), + errors = errors, + ) + } + } else { + listOf( + DataFetcherReturns( + field = topLevelField, + result = topLevelResult, + errors = errors, + ) + ) + } + } else { + listOf( + DataFetcherReturns( + field = topLevelField, + result = topLevelResult, + errors = errors, + ), + ) + } + } + } + .groupBy { + it.field.objectTypeNames.single() + } + + val namespacedDataFetchersBlock = dataFetcherReturnsByContainerTypeName + .asSequence() + .filter { (_, dataFetcherReturns) -> + dataFetcherReturns.first().field.parent != null + } + .map { (containerType, dataFetcherReturns) -> + val parent = dataFetcherReturns.first().field.parent + val parentParentObjectTypeName = parent.objectTypeNames.single() + + val dataFetcher = CodeBlock.Builder() + .beginControlFlow("type.dataFetcher(%S)", parent.name) + .add("%T", Unit::class) + .endControlFlow() + .build() + + CodeBlock.Builder() + .beginControlFlow("wiring.type(%S) { type ->", parentParentObjectTypeName) + .add(dataFetcher) + .endControlFlow() + .build() + } + .joinToCode(separator = "\n") + + val toGraphQLError = MemberName("graphql.nadel.engine.util", "toGraphQLError") + + fun getResultObject(result: DataFetcherReturns): CodeBlock { + val data = getResultObject( + serviceName = serviceName, + underlyingSchema = underlyingSchema, + parent = result.field, + children = result.field.children, + result = result.result + ) + + return if (result.errors.isNullOrEmpty()) { + data + } else { + val errors = CodeBlock.Builder() + .add( + "listOf(%L)", + result.errors + .map { + CodeBlock.Builder() + .add( + "%M(%L)", + toGraphQLError, + javaValueToCodeLiteral(it, explicitEmptyGenerics = true), + ) + .build() + } + .joinToCode(separator = ", ") + ) + .build() + + CodeBlock.Builder() + .add("%T.newResult<%T>()", DataFetcherResult::class, Any::class) + .add(".data(%L)", data) + .add(".errors(%L)", errors) + .add(".build()", data) + .build() + } + } + + val dataFetchersBlock = dataFetcherReturnsByContainerTypeName + .asSequence() + .map { (containerType, dataFetcherReturns) -> + val typeWiring = dataFetcherReturns + .groupBy { it.field.name } + .map { (fieldName, dataFetcherReturns) -> + val dataFetcher = if (dataFetcherReturns.isNotEmpty()) { + if (dataFetcherReturns.size == 1 && dataFetcherReturns.single().field.resolvedArguments.isEmpty()) { + val dataFetcherReturn = dataFetcherReturns.single() + + getResultObject(dataFetcherReturn) + } else { + dataFetcherReturns + .map { dataFetcherReturn -> + val result = getResultObject(dataFetcherReturn) + + val condition = getFieldCondition(dataFetcherReturn.field) + + CodeBlock.Builder() + .beginControlFlow("if (%L)", condition) + .add(result) + .endControlFlow() + .build() + } + .joinToCode(separator = "else ") // Keep space to ensure it doesn't merge with if keyword + .toBuilder() + .beginControlFlow("else") + .add("%L", null) + .endControlFlow() + .build() + } + } else { + CodeBlock.Builder() + .add("%L", null) + .build() + } + + CodeBlock.Builder() + .beginControlFlow(".dataFetcher(%S) { env ->", fieldName) + .add(dataFetcher) + .endControlFlow() + .build() + } + .joinToCode( + prefix = "type", + separator = "\n", + ) + + CodeBlock.Builder() + .beginControlFlow("wiring.type(%S) { type ->", containerType) + .add(typeWiring) + .endControlFlow() + .build() + } + .joinToCode(separator = "\n") + + val typeResolversBlock = underlyingSchema.typeMap.values + .asSequence() + .filter { + it is GraphQLInterfaceType || it is GraphQLUnionType + } + .map { abstractType -> + val typeResolver = CodeBlock.Builder() + .add("val obj = typeResolver.getObject()\n") + .add("val typeName = obj.javaClass.simpleName.substringAfter(%S)\n", "_") + .add("typeResolver.schema.getTypeAs(typeName)\n") + .build() + + val typeWiring = CodeBlock.Builder() + .beginControlFlow("type.typeResolver { typeResolver ->") + .add(typeResolver) + .endControlFlow() + .build() + + CodeBlock.Builder() + .beginControlFlow("wiring.type(%S) { type ->", abstractType.name) + .add(typeWiring) + .endControlFlow() + .build() + } + .joinToCode(separator = "\n") + + val scalarBlock = underlyingSchema.typeMap.values + .asSequence() + .filterIsInstance() + .mapNotNull { + when (it.name) { + ExtendedScalars.Json.name -> CodeBlock.Builder() + .add("wiring.scalar(%T.Json)", ExtendedScalars::class) + .build() + else -> { + if (ScalarInfo.isGraphqlSpecifiedScalar(it)) { + null + } else { + val realScalar = when (it.name) { + else -> "Json" + } + + CodeBlock.Builder() + .add( + "wiring.scalar(%T.Builder().name(%S).aliasedScalar(%T.%L).build())", + AliasedScalar::class, + it.name, + ExtendedScalars::class, + realScalar, + ) + .build() + } + } + } + } + .joinToCode(separator = "\n") + + return CodeBlock.Builder() + .beginControlFlow("{ wiring ->") + .add(namespacedDataFetchersBlock) + .add(dataFetchersBlock) + .add(typeResolversBlock) + .add(scalarBlock) + .endControlFlow() + .build() +} + +private fun Sequence.joinToCode( + separator: String = ", ", + prefix: String = "", + suffix: String = "", +): CodeBlock { + val builder = CodeBlock.Builder() + builder.add(prefix) + forEachIndexed { index, codeBlock -> + if (index > 0) { + builder.add(separator) + } + builder.add(codeBlock) + } + builder.add(suffix) + return builder.build() +} + +context(MigrateTestsContext) +private fun getResultObject( + serviceName: String, + underlyingSchema: GraphQLSchema, + parent: ExecutableNormalizedField, + children: List, + result: Any?, +): CodeBlock { + if (result == null || children.isEmpty()) { + return javaValueToCodeLiteral(result) + } + + if (result is List<*>) { + val listElements = result + .map { + getResultObject( + serviceName = serviceName, + underlyingSchema = underlyingSchema, + parent = parent, + children = children, + result = it, + ) + } + .joinToCode(separator = ", ") + + return CodeBlock.Builder() + .add("listOf(%L)", listElements) + .build() + } + + val jsonObject = @Suppress("UNCHECKED_CAST") (result as JsonMap) + val objectTypeName: String = inferTypename(children, jsonObject) + val objectTypeSpec = typeSpecs[serviceName]!![objectTypeName]!! + + val params = children + .asSequence() + .filterNot { + it.name == Introspection.TypeNameMetaFieldDef.name + } + .groupBy { + it.name + } + .asSequence() + .mapNotNull { (k, fields) -> + fields + .filter { field -> + field.objectTypeNames.contains(objectTypeName) + } + .takeIf { + it.isNotEmpty() + } + ?.let { + k to it + } + } + .map { (_, fields) -> + val result = if (fields.size > 1 && fields.any(ExecutableNormalizedField::hasChildren)) { + fields.fold(null as JsonMap?) { acc, field -> + val map = (jsonObject[field.resultKey] as JsonMap?) + if (map == null) { + acc + } else { + (acc ?: emptyMap()) + map + } + } + } else { + jsonObject[fields.first().resultKey] + } + + val value = getResultObject( + serviceName = serviceName, + underlyingSchema = underlyingSchema, + parent = fields.first(), + children = fields.flatMap { it.children }, + result = result, + ) + + CodeBlock.Builder() + .add("%N = %L", fields.first().name, value) + .build() + } + .joinToCode(separator = ", ") + + return CodeBlock.Builder() + .add("%N(%L)", objectTypeSpec, params) + .build() +} + +context(MigrateTestsContext) +private fun inferTypename( + children: List, + jsonObject: JsonMap, +): String { + // Directly specified by __typename + return children + .asSequence() + .filter { + it.fieldName == Introspection.TypeNameMetaFieldDef.name + } + .mapNotNull { + jsonObject[it.resultKey] as String? + } + .singleOrNull() + ?: children + .flatMap { field -> + field.objectTypeNames + .map { objectTypeName -> + objectTypeName to field + } + } + .groupBy( + keySelector = { (objectTypeName) -> + objectTypeName + }, + valueTransform = { (_, listOfFields) -> + listOfFields + }, + ) + .entries + .groupBy( + keySelector = { (_, fields) -> + fields.mapTo(mutableSetOf()) { it.resultKey } + }, + valueTransform = { (objectTypeName) -> + objectTypeName + }, + ) + .asSequence() + .mapNotNull { (resultKeySet, objectTypeNames) -> + objectTypeNames.singleOrNull()?.let { it to resultKeySet } + } + .filter { (_, resultKeySet) -> + jsonObject.keys == resultKeySet + } + .map { (objectType) -> + objectType + } + .singleOrNull() + ?: jsonObject[Introspection.TypeNameMetaFieldDef.name] as String +} + +context(MigrateTestsContext) +private fun getFieldCondition(field: ExecutableNormalizedField): CodeBlock { + if (field.resolvedArguments.isEmpty()) { + return CodeBlock.Builder() + .add("env.field.resultKey == %S", field.resultKey + "") + .build() + } + + return field.resolvedArguments + .map { (name, value) -> + CodeBlock.Builder() + .add( + "env.getArgument<%T?>(%S) == %L", + Any::class, + name, + javaValueToCodeLiteral(value, explicitEmptyGenerics = true), + ) + .build() + } + .joinToCode(separator = " && ") +} + +context(MigrateTestsContext) +private fun javaValueToCodeLiteral( + value: Any?, + explicitEmptyGenerics: Boolean = false, +): CodeBlock { + return when (value) { + is Map<*, *> -> { + if (value.isEmpty()) { + if (explicitEmptyGenerics) { + val anything = Any::class.asTypeName().copy(nullable = true) + CodeBlock.Builder() + .add("emptyMap<%T, %T>()", anything, anything) + .build() + } else { + CodeBlock.Builder() + .add("emptyMap()") + .build() + } + } else { + val params = value + .map { (key, value) -> + CodeBlock.Builder() + .add("%S to %L", key, javaValueToCodeLiteral(value, explicitEmptyGenerics = true)) + .build() + } + .joinToCode(separator = ", ") + + CodeBlock.Builder() + .add("mapOf(%L)", params) + .build() + } + } + is List<*> -> { + if (value.isEmpty()) { + if (explicitEmptyGenerics) { + val anything = Any::class.asTypeName().copy(nullable = true) + CodeBlock.Builder() + .add("emptyList<%T>()", anything) + .build() + } else { + CodeBlock.Builder() + .add("emptyList()") + .build() + } + } else { + val params = value + .map { + javaValueToCodeLiteral(it, explicitEmptyGenerics = true) + } + .joinToCode(separator = ", ") + + CodeBlock.Builder() + .add("listOf(%L)", params) + .build() + } + } + is String -> { + CodeBlock.Builder() + .add("%S", value) + .build() + } + is Boolean, is Number -> { + CodeBlock.Builder() + .add("%L", value) + .build() + } + else -> { + CodeBlock.Builder() + .add("%L", null) + .build() + } + } +} + +private fun needsOverride(type: GraphQLImplementingType, field: GraphQLFieldDefinition): Boolean { + return type + .interfaces + .any { superType -> + (superType as GraphQLInterfaceType).getField(field.name) != null + } +} + +private fun PropertySpec.Builder.overrideIfAbstract( + type: GraphQLImplementingType, + field: GraphQLFieldDefinition, +): PropertySpec.Builder { + if (needsOverride(type, field)) { + addModifiers(KModifier.OVERRIDE) + } + return this +} + +private fun constructType( + parentClassName: ClassName, + service: String, + schema: GraphQLSchema, + type: GraphQLNamedType, +): TypeSpec? { + val classPrefix = service.replaceFirstChar(Char::uppercase) + '_' + + fun getTypename(type: GraphQLType): TypeName { + return type.whenType( + listType = { + val inner = it.unwrapOne() + List::class.asTypeName() + .parameterizedBy(getTypename(inner)) + .copy(nullable = true) // Nullable by default, unless ! overrides this + }, + nonNull = { + val inner = it.unwrapOne() + getTypename(inner).copy(nullable = false) + }, + unmodifiedType = { + when (it.name) { + GraphQLInt.name -> Int::class.asTypeName() + GraphQLFloat.name -> Double::class.asTypeName() + GraphQLString.name -> String::class.asTypeName() + GraphQLBoolean.name -> Boolean::class.asTypeName() + GraphQLID.name -> String::class.asTypeName() + ExtendedScalars.Json.name -> Any::class.asTypeName() + ExtendedScalars.DateTime.name -> String::class.asTypeName() + ExtendedScalars.GraphQLLong.name -> Long::class.asTypeName() + ExtendedScalars.Url.name, "URL" -> String::class.asTypeName() + else -> { + parentClassName.nestedClass(classPrefix + it.name) + } + }.copy(nullable = true) // Nullable by default, unless ! overrides this + }, + ) + } + + return type.whenType( + enumType = { enumType -> + val type = TypeSpec.enumBuilder(classPrefix + type.name) + .addModifiers(KModifier.PRIVATE) + enumType.values.forEach { value -> + type.addEnumConstant(value.name) + } + type.build() + }, + inputObjectType = { inputObjectType -> + TypeSpec.classBuilder(classPrefix + type.name) + .addModifiers(KModifier.PRIVATE, KModifier.DATA) + .primaryConstructor( + FunSpec.constructorBuilder() + .addParameters( + inputObjectType.fields + .map { field -> + ParameterSpec.builder(field.name, getTypename(field.type).copy(nullable = true)) + .defaultValue("%L", null) + .build() + } + ) + .build() + ) + .addProperties( + inputObjectType.fields + .map { field -> + PropertySpec.builder(field.name, getTypename(field.type).copy(nullable = true)) + .initializer(field.name) + .build() + } + ) + .build() + }, + interfaceType = { interfaceType -> + TypeSpec.interfaceBuilder(classPrefix + type.name) + .addModifiers(KModifier.PRIVATE) + .addProperties( + interfaceType.fields + .map { field -> + PropertySpec.builder(field.name, getTypename(field.type).copy(nullable = true)) + .overrideIfAbstract(interfaceType, field) + .build() + } + ) + .addSuperinterfaces( + interfaceType.interfaces + .map { + getTypename(it).copy(nullable = false) + } + ) + .build() + }, + objectType = { objectType -> + TypeSpec.classBuilder(classPrefix + type.name) + .addModifiers(KModifier.PRIVATE, KModifier.DATA) + .primaryConstructor( + FunSpec.constructorBuilder() + .addParameters( + objectType.fields + .map { field -> + ParameterSpec.builder(field.name, getTypename(field.type).copy(nullable = true)) + .defaultValue("%L", null) + .build() + } + ) + .build() + ) + .addProperties( + objectType.fields + .map { field -> + PropertySpec.builder(field.name, getTypename(field.type).copy(nullable = true)) + .overrideIfAbstract(objectType, field) + .initializer(field.name) + .build() + } + ) + .addSuperinterfaces( + objectType.interfaces + .map { + getTypename(it).copy(nullable = false) + } + ) + .addSuperinterfaces( + schema + .typeMap + .values + .asSequence() + .filterIsInstance() + .filter { union -> + union.types.contains(type) + } + .map { union -> + getTypename(union).copy(nullable = false) + } + .toList() + ) + .build() + }, + scalarType = { + null + }, + unionType = { unionType -> + TypeSpec.interfaceBuilder(classPrefix + unionType.name) + .addModifiers(KModifier.PRIVATE, KModifier.SEALED) + .build() + }, + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/NadelIntegrationTest.kt b/test/src/test/kotlin/graphql/nadel/tests/next/NadelIntegrationTest.kt index 00f32e3d6..cc8c8477c 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/NadelIntegrationTest.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/NadelIntegrationTest.kt @@ -1,5 +1,6 @@ package graphql.nadel.tests.next +import com.squareup.kotlinpoet.asClassName import graphql.ExecutionResult import graphql.GraphQL import graphql.execution.DataFetcherExceptionHandler @@ -12,6 +13,7 @@ import graphql.execution.instrumentation.parameters.InstrumentationExecutionPara import graphql.incremental.DelayedIncrementalPartialResult import graphql.incremental.IncrementalExecutionResult import graphql.language.AstPrinter +import graphql.language.AstSorter import graphql.nadel.Nadel import graphql.nadel.NadelExecutionHints import graphql.nadel.NadelExecutionInput @@ -26,6 +28,7 @@ import graphql.nadel.tests.compareJsonObject import graphql.nadel.tests.jsonObjectMapper import graphql.nadel.tests.withPrettierPrinter import graphql.nadel.validation.NadelSchemaValidation +import graphql.nadel.validation.NadelSchemaValidationError import graphql.nadel.validation.NadelSchemaValidationFactory import graphql.parser.Parser import graphql.schema.idl.RuntimeWiring @@ -68,7 +71,15 @@ abstract class NadelIntegrationTest( val executionInput = makeExecutionInput().build() // When - val result = nadel.execute(executionInput).await() + val result = try { + nadel.execute(executionInput).await() + } catch (e: Exception) { + // Let tests expect Exception + if (assertFailure(e)) { + return@runTest + } + throw e + } val incrementalResults = if (result is IncrementalExecutionResult) { result.incrementalItemPublisher @@ -186,7 +197,7 @@ abstract class NadelIntegrationTest( val schemas = makeNadelSchemas().build() val nadelSchemaValidation = makeNadelSchemaValidation() val schemaErrors = nadelSchemaValidation.validate(schemas) - assertTrue(schemaErrors.map { it.message }.isEmpty()) + assertSchemaErrors(schemaErrors) return Nadel.newNadel() .schemas(schemas) @@ -194,6 +205,10 @@ abstract class NadelIntegrationTest( .schemaValidation(nadelSchemaValidation) } + open fun assertSchemaErrors(errors: Set) { + assertTrue(errors.map { it.message }.isEmpty()) + } + open fun makeNadelSchemas(): NadelSchemas.Builder { require(services.asSequence().map { it.name }.toSet().size == services.size) @@ -284,7 +299,7 @@ abstract class NadelIntegrationTest( */ private val _testSnapshot = lazy { try { - Class.forName(this::class.qualifiedName + "Snapshot") + Class.forName(getSnapshotClassName(this::class.asClassName()).canonicalName) .getDeclaredConstructor() .newInstance() as TestSnapshot } catch (e: ClassNotFoundException) { @@ -296,12 +311,25 @@ abstract class NadelIntegrationTest( return _testSnapshot.value } + /** + * Allows for a chance to recover from an [Exception] if it is expected + * + * @return true to pass the test + */ + open fun assertFailure(e: Exception): Boolean { + return false + } + open fun assert(result: ExecutionResult, incrementalResults: List?) { } private fun assertServiceCalls(testSnapshot: TestSnapshot) { fun getCanonicalQuery(query: String): String { - return AstPrinter.printAstCompact(Parser().parseDocument(query)) + return AstPrinter.printAstCompact( + AstSorter().sort( + Parser().parseDocument(query), + ), + ) } fun isDelayedResultsEqual( diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/TestExecutionCapture.kt b/test/src/test/kotlin/graphql/nadel/tests/next/TestExecutionCapture.kt index 648095617..cc03a935a 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/TestExecutionCapture.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/TestExecutionCapture.kt @@ -5,8 +5,11 @@ import graphql.ExecutionResult import graphql.incremental.DelayedIncrementalPartialResult import graphql.incremental.IncrementalExecutionResult import graphql.incremental.IncrementalExecutionResultImpl +import graphql.language.AstPrinter +import graphql.language.AstSorter import graphql.nadel.engine.util.JsonMap import graphql.nadel.tests.jsonObjectMapper +import graphql.parser.Parser import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.reactive.asFlow import kotlinx.coroutines.reactive.asPublisher @@ -40,10 +43,16 @@ class TestExecutionCapture { ): ExecutionResult { val delayedResults = synchronizedMutableListOf() + val canonicalQuery = AstPrinter.printAst( + AstSorter().sort( + Parser().parseDocument(query) + ), + ) + _calls.add( Call( service = service, - query = query, + query = canonicalQuery, variables = variables, result = deepClone(result), delayedResults = delayedResults, diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/UpdateTestSnapshots.kt b/test/src/test/kotlin/graphql/nadel/tests/next/UpdateTestSnapshots.kt index 264e73bb6..303fe4f95 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/UpdateTestSnapshots.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/UpdateTestSnapshots.kt @@ -42,12 +42,10 @@ private suspend fun main(vararg args: String) { .filter { args.isEmpty() || args.contains(it.qualifiedName) } - .toList() - .let { klasses -> - // Running this wll first generate snapshots for tests that do not have snapshots - // If all tests have snapshots, then we update them all - getNonExistentOrAll(klasses) - .asSequence() + // Only process non-existent by default + .filter { klass -> + classForNameOrNull(getSnapshotClassName(klass.asClassName()).reflectionName()) == null + || (args.isNotEmpty() && klass.qualifiedName in args) } .onEach { klass -> println("Loading ${klass.qualifiedName}") @@ -59,22 +57,31 @@ private suspend fun main(vararg args: String) { .forEach { (klass, test) -> println("Recording ${klass.qualifiedName}") - val captured = test.capture() + try { + val captured = test.capture() - writeTestSnapshotClass(klass, captured, sourceRoot) + writeTestSnapshotClass( + testClassName = klass.asClassName(), + captured = captured, + sourceRoot = sourceRoot, + ) + } catch (e: Exception) { + e.printStackTrace() + } } } fun writeTestSnapshotClass( - klass: KClass, + testClassName: ClassName, captured: TestExecutionCapture, sourceRoot: File, ) { - val outputFile = FileSpec.builder(ClassName.bestGuess(klass.qualifiedName!! + "Snapshot")) + val snapshotClassName = getSnapshotClassName(testClassName) + val outputFile = FileSpec.builder(snapshotClassName) .indent(' '.toString().repeat(4)) .addFileComment(FORMATTER_OFF) - .addFunction(makeUpdateSnapshotFunction(klass)) - .addType(makeTestSnapshotClass(klass, captured)) + .addFunction(makeUpdateSnapshotFunction(testClassName)) + .addType(makeTestSnapshotClass(testClassName, captured)) .build() .writeTo(sourceRoot) @@ -93,25 +100,24 @@ fun writeTestSnapshotClass( ) } -private fun getNonExistentOrAll(klasses: List>): List> { - return klasses - .filter { klass -> - classForNameOrNull(klass.qualifiedName + "Snapshot") == null - } - .takeIf { - it.isNotEmpty() - } - ?: klasses +fun getSnapshotClassName(className: ClassName): ClassName { + val suffix = if (className.simpleName.contains(" ") || className.simpleName.none(Char::isUpperCase)) { + " snapshot" + } else { + "Snapshot" + } + + return ClassName(className.packageName, className.simpleName + suffix) } -fun makeUpdateSnapshotFunction(klass: KClass): FunSpec { +fun makeUpdateSnapshotFunction(testClassName: ClassName): FunSpec { return FunSpec.builder("main") .addModifiers(KModifier.PRIVATE, KModifier.SUSPEND) - .addCode("graphql.nadel.tests.next.update<%T>()", klass) + .addCode("graphql.nadel.tests.next.update<%T>()", testClassName) .build() } -private fun getTestClassSequence(): Sequence> { +private fun getTestClassSequence(): Sequence> { return ClassPath.from(ClassLoader.getSystemClassLoader()) .getTopLevelClassesRecursive("graphql.nadel.tests") .asSequence() @@ -127,12 +133,12 @@ private fun getTestClassSequence(): Sequence> { } private fun makeTestSnapshotClass( - klass: KClass, + testClassName: ClassName, captured: TestExecutionCapture, ): TypeSpec { - return TypeSpec.classBuilder(klass.simpleName + "Snapshot") + return TypeSpec.classBuilder(getSnapshotClassName(testClassName)) .superclass(TestSnapshot::class) - .addKdoc("This class is generated. Do NOT modify.\n\nRefer to [graphql.nadel.tests.next.UpdateTestSnapshots") + .addKdoc("This class is generated. Do NOT modify.\n\nRefer to [graphql.nadel.tests.next.UpdateTestSnapshots]") .addAnnotation(AnnotationSpec.builder(Suppress::class).addMember("%S", "unused").build()) .addProperty(makeServiceCallsProperty(captured)) .addProperty(makeNadelResultProperty(captured)) @@ -244,6 +250,10 @@ private fun makeConstructorInvocationToExpectedServiceCall(call: TestExecutionCa } private fun writeResultJson(result: JsonMap): String { + if (result.isEmpty()) { + return "{}" + } + return jsonObjectMapper .withPrettierPrinter() .writeValueAsString(result) @@ -251,17 +261,11 @@ private fun writeResultJson(result: JsonMap): String { } private fun writeResultJson(result: ExecutionResult): String { - return jsonObjectMapper - .withPrettierPrinter() - .writeValueAsString(result.toSpecification()) - .replaceIndent(" ") + return writeResultJson(result.toSpecification()) } private fun writeResultJson(result: DelayedIncrementalPartialResult): String { - return jsonObjectMapper - .withPrettierPrinter() - .writeValueAsString(result.toSpecification()) - .replaceIndent(" ") + return writeResultJson(result.toSpecification()) } private fun classForNameOrNull(name: String): Class<*>? { diff --git a/test/src/test/resources/fixtures/basic/schema-transformation-is-applied.yml b/test/src/test/resources/fixtures/basic/schema-transformation-is-applied.yml index 9c95035a3..1a010f433 100644 --- a/test/src/test/resources/fixtures/basic/schema-transformation-is-applied.yml +++ b/test/src/test/resources/fixtures/basic/schema-transformation-is-applied.yml @@ -1,5 +1,5 @@ name: "schema transformation is applied" -enabled: true +enabled: false # language=GraphQL overallSchema: MyService: | diff --git a/test/src/test/resources/fixtures/basic/service-types-are-completely-filtered.yml b/test/src/test/resources/fixtures/basic/service-types-are-completely-filtered.yml index 7b77da164..f71ef3060 100644 --- a/test/src/test/resources/fixtures/basic/service-types-are-completely-filtered.yml +++ b/test/src/test/resources/fixtures/basic/service-types-are-completely-filtered.yml @@ -128,9 +128,11 @@ serviceCalls: { "data": { "test": { - "extensions": { - "__typename__type_filter__statusCode": "GenericQueryErrorExtension" - } + "extensions": [ + { + "__typename__type_filter__statusCode": "GenericQueryErrorExtension" + } + ] } }, "extensions": {} @@ -140,7 +142,9 @@ response: |- { "data": { "test": { - "extensions": {} + "extensions": [ + {} + ] } }, "extensions": {} diff --git a/test/src/test/resources/fixtures/defer/defer-is-disabled.yml b/test/src/test/resources/fixtures/defer/defer-is-disabled.yml deleted file mode 100644 index 776ff0e98..000000000 --- a/test/src/test/resources/fixtures/defer/defer-is-disabled.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: "defer is disabled" -enabled: true -overallSchema: - service: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - defer: DeferApi - } - - type DeferApi { - hello: String - slow: String - } -underlyingSchema: - service: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - defer: DeferApi - } - - type DeferApi { - hello: String - slow: String - } -query: | - query { - defer { - hello - ... @defer(label: "slow-defer") { - slow - } - } - } -variables: { } -serviceCalls: - - serviceName: "service" - request: - query: | - query { - defer { - hello - slow - } - } - variables: { } - # language=JSON - response: |- - { - "data": { - "defer": { - "hello": "world", - "slow": "🐌" - } - }, - "extensions": {} - } -# language=JSON -response: |- - { - "data": { - "defer": { - "hello": "world", - "slow": "🐌" - } - }, - "extensions": {} - } diff --git a/test/src/test/resources/fixtures/defer/defer-no-label.yml b/test/src/test/resources/fixtures/defer/defer-no-label.yml deleted file mode 100644 index 280ce2486..000000000 --- a/test/src/test/resources/fixtures/defer/defer-no-label.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: "defer no label" -enabled: true -overallSchema: - service: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - defer: DeferApi - } - - type DeferApi { - hello: String - slow: String - } -underlyingSchema: - service: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - defer: DeferApi - } - - type DeferApi { - hello: String - slow: String - } -query: | - query { - defer { - hello - ... @defer { - slow - } - } - } -variables: { } -serviceCalls: - - serviceName: "service" - request: - query: | - query { - defer { - hello - ... @defer { - slow - } - } - } - variables: { } - # language=JSON - - incrementalResponse: - initialResponse: |- - { - "hasNext": true, - "data": { - "defer": { - "hello": "world" - } - }, - "extensions": {} - } - delayedResponses: |- - [{ - "hasNext": false, - "incremental": [{ - "path": ["defer"], - "data": { - "slow": "snail" - - } - }] - }] -# language=JSON -incrementalResponse: - initialResponse: |- - { - "hasNext": true, - "data": { - "defer": { - "hello": "world" - } - }, - "extensions": {} - } - delayedResponses: |- - [{ - "hasNext": false, - "incremental": [{ - "path": ["defer"], - "data": { - "slow": "snail" - - } - }] - }] \ No newline at end of file diff --git a/test/src/test/resources/fixtures/defer/defer-on-hydrated-field.yml b/test/src/test/resources/fixtures/defer/defer-on-hydrated-field.yml deleted file mode 100644 index dc4f309a4..000000000 --- a/test/src/test/resources/fixtures/defer/defer-on-hydrated-field.yml +++ /dev/null @@ -1,147 +0,0 @@ -name: "defer on hydrated field" -enabled: false -overallSchema: - petService: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - pet(id: ID!): Pet - } - type Pet { - name: String - owner: Person @hydrated(service: "personService" field: "person" arguments: [{name: "id" value: "$source.ownerId"}]) - } - personService: | - type Query { - person(id: ID!): Person - } - type Person { - firstname: String - lastname: String - } -underlyingSchema: - petService: | - type Query { - pet(id: ID!): Pet - } - type Pet { - name: String - ownerId: ID - } - personService: | - type Query { - person(id: ID!): Person - } - type Person { - firstname: String - lastname: String - } -query: | - query { - pet(id: "1") { - name - ... @defer { # the @defer on the hydrated field has no effect at the moment - owner { - firstname - ... @defer { - lastname - } - } - } - } - } -variables: { } -serviceCalls: - - serviceName: "petService" - request: - query: | - query { - pet(id: "1") { - __typename__hydration__owner: __typename - name - hydration__owner__ownerId: ownerId - } - } - variables: { } - # language=JSON - - # This is just checking that can generate queries containing @defer. - # The response below will change once defer work is implemented. - response: |- - { - "data": { - "pet": { - "name": "Figaro", - "hydration__owner__ownerId": "100", - "__typename__hydration__owner": "Pet" - } - }, - "extensions": {} - } - - serviceName: "personService" - request: - query: | - query { - person(id: "100") { - firstname - ... @defer { - lastname - } - } - } - variables: { } - # language=JSON -# response: |- -# { -# "data": { -# "person": { -# "firstname": "Ziggy" -# } -# }, -# "extensions": {} -# } - incrementalResponse: - initialResponse: |- - { - "hasNext": true, - "data": { - "person": { - "firstname": "Ziggy" - } - }, - "extensions": {} - } - delayedResponses: |- - [{ - "hasNext": false, - "incremental": [{ - "path": ["person"], - "data": { - "lastname": "Meowmeow" - - } - }] - }] -# language=JSON -incrementalResponse: - initialResponse: |- - { - "hasNext": true, - "data": { - "person": { - "firstname": "Ziggy" - } - }, - "extensions": {} - } - delayedResponses: |- - [{ - "hasNext": false, - "incremental": [{ - "path": ["person"], - "data": { - "lastname": "Meowmeow" - - } - }] - }] diff --git a/test/src/test/resources/fixtures/defer/defer-with-label.yml b/test/src/test/resources/fixtures/defer/defer-with-label.yml deleted file mode 100644 index a70b0dcdc..000000000 --- a/test/src/test/resources/fixtures/defer/defer-with-label.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: "defer with label" -enabled: true -overallSchema: - service: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - defer: DeferApi - } - - type DeferApi { - hello: String - slow: String - } -underlyingSchema: - service: | - directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT - - type Query { - defer: DeferApi - } - - type DeferApi { - hello: String - slow: String - } -query: | - query { - defer { - hello - ... @defer(label: "slow-defer") { - slow - } - } - } -variables: { } -serviceCalls: - - serviceName: "service" - request: - query: | - query { - defer { - hello - ... @defer(label: "slow-defer") { - slow - } - } - } - variables: { } - # language=JSON - incrementalResponse: - initialResponse: |- - { - "hasNext": true, - "data": { - "defer": { - "hello": "world" - } - }, - "extensions": {} - } - delayedResponses: |- - [{ - "hasNext": false, - "incremental": [{ - "label": "slow-defer", - "path": ["defer"], - "data": { - "slow": "snail" - } - }] - }] - -# language=JSON -incrementalResponse: - initialResponse: |- - { - "hasNext": true, - "data": { - "defer": { - "hello": "world" - } - }, - "extensions": {} - } - delayedResponses: |- - [{ - "hasNext": false, - "incremental": [{ - "label": "slow-defer", - "path": ["defer"], - "data": { - "slow": "snail" - } - }] - }] diff --git a/test/src/test/resources/fixtures/dynamic service resolution/dynamic-service-resolution-directive-not-in-interface.yml b/test/src/test/resources/fixtures/dynamic service resolution/dynamic-service-resolution-directive-not-in-interface.yml index 8145dd203..5734b42b1 100644 --- a/test/src/test/resources/fixtures/dynamic service resolution/dynamic-service-resolution-directive-not-in-interface.yml +++ b/test/src/test/resources/fixtures/dynamic service resolution/dynamic-service-resolution-directive-not-in-interface.yml @@ -31,14 +31,7 @@ query: |- } } variables: { } -serviceCalls: - - serviceName: "RepoService" - request: - # language=GraphQL - query: "" - variables: { } - # language=JSON - response: "" +serviceCalls: [ ] # language=JSON response: null exception: diff --git a/test/src/test/resources/fixtures/field removed/all-fields-in-a-selection-set-are-removed.yml b/test/src/test/resources/fixtures/field removed/all-fields-in-a-selection-set-are-removed.yml index 8a1379c99..b3f645f4e 100644 --- a/test/src/test/resources/fixtures/field removed/all-fields-in-a-selection-set-are-removed.yml +++ b/test/src/test/resources/fixtures/field removed/all-fields-in-a-selection-set-are-removed.yml @@ -137,7 +137,7 @@ serviceCalls: "issueById": { "id": "I1", "epic": { - "empty_selection_set_typename__UUID": "Issue" + "empty_selection_set_typename__UUID": "Epic" } } }, diff --git a/test/src/test/resources/fixtures/field removed/top-level-field-is-removed-hint-is-off.yml b/test/src/test/resources/fixtures/field removed/top-level-field-is-removed-hint-is-off.yml index 3b58fdb9d..adf0db905 100644 --- a/test/src/test/resources/fixtures/field removed/top-level-field-is-removed-hint-is-off.yml +++ b/test/src/test/resources/fixtures/field removed/top-level-field-is-removed-hint-is-off.yml @@ -1,4 +1,4 @@ -name: "top-level-field-is-removed-hint-is-off" +name: "top level field is removed hint is off" enabled: true # language=GraphQL overallSchema: diff --git a/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-in-cf-within-instrumentation-still-calls-enhancing-instrumentation.yml b/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-in-cf-within-instrumentation-still-calls-enhancing-instrumentation.yml index 7e4e3448d..b8de11d34 100644 --- a/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-in-cf-within-instrumentation-still-calls-enhancing-instrumentation.yml +++ b/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-in-cf-within-instrumentation-still-calls-enhancing-instrumentation.yml @@ -44,7 +44,9 @@ serviceCalls: [ ] # language=JSON response: |- { - "data": "enhanced beginExecute", + "data": { + "step": "beginExecute" + }, "errors": [ { "message": "beginExecute", diff --git a/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-within-instrumentation-still-calls-enhancing-instrumentation.yml b/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-within-instrumentation-still-calls-enhancing-instrumentation.yml index 185eb6432..6f5d3c59b 100644 --- a/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-within-instrumentation-still-calls-enhancing-instrumentation.yml +++ b/test/src/test/resources/fixtures/instrumentation/abort-begin-execute-within-instrumentation-still-calls-enhancing-instrumentation.yml @@ -44,7 +44,9 @@ serviceCalls: [ ] # language=JSON response: |- { - "data": "enhanced beginExecute", + "data": { + "step": "beginExecute" + }, "errors": [ { "message": "beginExecute", diff --git a/test/src/test/resources/fixtures/instrumentation/abort-begin-query-execution-within-instrumentation-still-calls-enhancing-instrumentation.yml b/test/src/test/resources/fixtures/instrumentation/abort-begin-query-execution-within-instrumentation-still-calls-enhancing-instrumentation.yml index f24a99b6b..7ad05d4a7 100644 --- a/test/src/test/resources/fixtures/instrumentation/abort-begin-query-execution-within-instrumentation-still-calls-enhancing-instrumentation.yml +++ b/test/src/test/resources/fixtures/instrumentation/abort-begin-query-execution-within-instrumentation-still-calls-enhancing-instrumentation.yml @@ -44,7 +44,9 @@ serviceCalls: [ ] # language=JSON response: |- { - "data": "enhanced beginQueryExecution", + "data": { + "step": "beginQueryExecution" + }, "errors": [ { "message": "beginQueryExecution", diff --git a/test/src/test/resources/fixtures/instrumentation/abort-begin-validation-within-instrumentation-still-calls-enhancing-instrumentation.yml b/test/src/test/resources/fixtures/instrumentation/abort-begin-validation-within-instrumentation-still-calls-enhancing-instrumentation.yml index a756f9d1a..ca7fd9ad8 100644 --- a/test/src/test/resources/fixtures/instrumentation/abort-begin-validation-within-instrumentation-still-calls-enhancing-instrumentation.yml +++ b/test/src/test/resources/fixtures/instrumentation/abort-begin-validation-within-instrumentation-still-calls-enhancing-instrumentation.yml @@ -44,7 +44,9 @@ serviceCalls: [ ] # language=JSON response: |- { - "data": "enhanced beginValidation", + "data": { + "step": "beginValidation" + }, "errors": [ { "message": "beginValidation", diff --git a/test/src/test/resources/fixtures/new hydration/polymorphic hydrations/batch-polymorphic-hydration-with-rename.yml b/test/src/test/resources/fixtures/new hydration/polymorphic hydrations/batch-polymorphic-hydration-with-rename.yml index b23d28a4d..61cf913de 100644 --- a/test/src/test/resources/fixtures/new hydration/polymorphic hydrations/batch-polymorphic-hydration-with-rename.yml +++ b/test/src/test/resources/fixtures/new hydration/polymorphic hydrations/batch-polymorphic-hydration-with-rename.yml @@ -204,13 +204,13 @@ serviceCalls: "data": { "humanById": [ { - "__typename": "Human", + "__typename": "Person", "id": "HUMAN-0", "batch_hydration__data__id": "HUMAN-0", "name": "Fanny Longbottom" }, { - "__typename": "Human", + "__typename": "Person", "id": "HUMAN-1", "batch_hydration__data__id": "HUMAN-1", "name": "John Doe" diff --git a/test/src/test/resources/fixtures/new hydration/top-level-field-is-null-in-synthetic-hydration.yml b/test/src/test/resources/fixtures/new hydration/top-level-field-is-null-in-synthetic-hydration.yml index 0e4c29f57..734de8561 100644 --- a/test/src/test/resources/fixtures/new hydration/top-level-field-is-null-in-synthetic-hydration.yml +++ b/test/src/test/resources/fixtures/new hydration/top-level-field-is-null-in-synthetic-hydration.yml @@ -99,7 +99,9 @@ serviceCalls: response: |- { "data": { - "projects": null + "projects": { + "project": null + } }, "extensions": {} } diff --git a/test/src/test/resources/fixtures/renames/rename-on-shared-abstract-type.yml b/test/src/test/resources/fixtures/renames/rename-on-shared-abstract-type.yml index 169ae51fc..cf64edc5b 100644 --- a/test/src/test/resources/fixtures/renames/rename-on-shared-abstract-type.yml +++ b/test/src/test/resources/fixtures/renames/rename-on-shared-abstract-type.yml @@ -8,7 +8,7 @@ overallSchema: } worlds: | type Query { - node(id: ID): [Node] + node(id: ID): Node } type World implements Node { id: ID! @@ -32,7 +32,7 @@ underlyingSchema: } worlds: | type Query { - node(id: ID): [Node] + node(id: ID): Node worlds: [World] } type World implements Node { diff --git a/test/src/test/resources/fixtures/renames/types/renamed-interface-type-is-shared.yml b/test/src/test/resources/fixtures/renames/types/renamed-interface-type-is-shared.yml index 98773aa3d..489ff68d2 100644 --- a/test/src/test/resources/fixtures/renames/types/renamed-interface-type-is-shared.yml +++ b/test/src/test/resources/fixtures/renames/types/renamed-interface-type-is-shared.yml @@ -28,6 +28,9 @@ underlyingSchema: type NextgenIssue implements Node { id: ID } + interface Node { + id: ID + } IssueService: |- type Query { issue(id: ID): Issue diff --git a/test/src/test/resources/fixtures/renames/types/renamed-type-in-union.yml b/test/src/test/resources/fixtures/renames/types/renamed-type-in-union.yml index 2500ca978..b9b487716 100644 --- a/test/src/test/resources/fixtures/renames/types/renamed-type-in-union.yml +++ b/test/src/test/resources/fixtures/renames/types/renamed-type-in-union.yml @@ -84,15 +84,18 @@ serviceCalls: "rename__nodes__all": [ { "__typename": "Issue", + "id": "1", "links": null }, null, { "__typename": "Issue", + "id": "2", "links": [] }, { "__typename": "Issue", + "id": "3", "links": [ { "__typename": "User" @@ -106,10 +109,12 @@ serviceCalls: ] }, { - "__typename": "Monkey" + "__typename": "Monkey", + "id": "4" }, { - "__typename": "User" + "__typename": "User", + "id": "8" } ] }, @@ -122,15 +127,18 @@ response: |- "nodes": [ { "__typename": "JiraIssue", + "id": "1", "links": null }, null, { "__typename": "JiraIssue", + "id": "2", "links": [] }, { "__typename": "JiraIssue", + "id": "3", "links": [ { "__typename": "User" @@ -144,10 +152,12 @@ response: |- ] }, { - "__typename": "Donkey" + "__typename": "Donkey", + "id": "4" }, { - "__typename": "User" + "__typename": "User", + "id": "8" } ] }, diff --git a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-but-not-renamed-in-one-service.yml b/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-but-not-renamed-in-one-service.yml deleted file mode 100644 index ed3f800a7..000000000 --- a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-but-not-renamed-in-one-service.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: "renamed type is shared but not renamed in one service" -# Not supported -enabled: false -# language=GraphQL -overallSchema: - NextgenIssues: |- - type Query { - fastIssue(id: ID!): JiraIssue - } - IssueService: |- - type Query { - issue(id: ID): JiraIssue - } - type JiraIssue @renamed(from: "Issue") { - id: ID - } -# language=GraphQL -underlyingSchema: - NextgenIssues: |- - type Query { - fastIssue(id: ID!): JiraIssue - } - type JiraIssue { - id: ID - } - IssueService: |- - type Query { - issue(id: ID): Issue - } - type Issue { - id: ID - } -# language=GraphQL -query: | - query TestyMctest { - fastIssue(id: "ISSUE-1") { - type: __typename - id - } - } -variables: { } -serviceCalls: - - serviceName: "NextgenIssues" - request: - # language=GraphQL - query: | - query TestyMctest { - fastIssue(id: "ISSUE-1") { - type: __typename - id - } - } - variables: { } - operationName: "TestyMctest" - # language=JSON - response: |- - { - "data": { - "fastIssue": { - "type": "JiraIssue", - "id": "ISSUE-1" - } - }, - "extensions": {} - } -# language=JSON -response: |- - { - "data": { - "fastIssue": { - "type": "JiraIssue", - "id": "ISSUE-1" - } - }, - "extensions": {} - } diff --git a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-deeper.yml b/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-deeper.yml deleted file mode 100644 index a3ce1e7b9..000000000 --- a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-deeper.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: "renamed type is shared deeper" -# Doesn't even get past validation -enabled: false -# language=GraphQL -overallSchema: - NextgenIssues: |- - type Query { - issue(id: ID!): Issue - } - IssueService: |- - type Issue { - id: ID - assignee: User - } - type User @renamed(from: "Account") { - id: ID - } -# language=GraphQL -underlyingSchema: - NextgenIssues: |- - type Query { - issue(id: ID!): Issue - } - type Issue { - id: ID - assignee: NextgenAccount - } - type NextgenAccount { - id: ID - } - IssueService: |- - type Query { - issue(id: ID!): Issue - } - type Issue { - id: ID - assignee: Account - } - type Account { - id: ID - } -# language=GraphQL -query: | - query { - issue(id: "ISSUE-1") { - __typename - id - assignee { - __typename - id - } - } - } -variables: { } -serviceCalls: - - serviceName: "NextgenIssues" - request: - # language=GraphQL - query: | - query { - issue(id: "ISSUE-1") { - __typename - assignee { - __typename - id - } - id - } - } - variables: { } - # language=JSON - response: |- - { - "data": { - "issue": { - "__typename": "Issue", - "id": "ISSUE-1", - "assignee": { - "__typename": "NextgenAccount", - "id": "USER-1" - } - } - }, - "extensions": {} - } -# language=JSON -response: |- - { - "data": { - "issue": { - "__typename": "Issue", - "id": "ISSUE-1", - "assignee": { - "__typename": "User", - "id": "USER-1" - } - } - }, - "extensions": {} - } diff --git a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-with-random-type-name.yml b/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-with-random-type-name.yml deleted file mode 100644 index 86dbcf4f3..000000000 --- a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared-with-random-type-name.yml +++ /dev/null @@ -1,216 +0,0 @@ -name: "renamed type is shared with random type name" -enabled: true -# We do not allow implicit renames, enable this test once we have explicit renames for shared types -ignored: true -# language=GraphQL -overallSchema: - Nextgen: |- - type Query { - elements: ElementConnection - } - Service: |- - type Query { - old: ElementConnection - } - type ElementConnection { - nodes: [Element] - } - type Element implements Node { - id: ID - other: RenamedOther - } - type RenamedOther @renamed(from: "Other") { - id: ID! - } - Shared: |- - interface Node { - id: ID - } -# language=GraphQL -underlyingSchema: - Nextgen: |- - type Query { - elements: NextgenElementConnection - } - type NextgenElementConnection { - nodes: [NextgenElement] - } - type NextgenElement implements Node { - id: ID - other: NextgenOther - } - type NextgenOther { - id: ID! - } - interface Node { - id: ID - } - Service: |- - type Query { - old: ElementConnection - } - type ElementConnection { - nodes: [Element] - } - type Element implements Node { - id: ID - other: Other - } - type Other { - id: ID! - } - interface Node { - id: ID - } - Shared: |- - type Query { - node(id: ID): Node - } - interface Node { - id: ID - } -# language=GraphQL -query: | - query { - elements { - __typename - nodes { - __typename - other { - __typename - id - } - } - } - old { - __typename - nodes { - __typename - other { - __typename - id - } - } - } - } -variables: { } -serviceCalls: - - serviceName: "Nextgen" - request: - # language=GraphQL - query: |- - query { - ... on Query { - elements { - ... on NextgenElementConnection { - __typename - nodes { - ... on NextgenElement { - __typename - other { - ... on NextgenOther { - __typename - id - } - } - } - } - } - } - } - } - variables: { } - # language=JSON - response: |- - { - "data": { - "elements": { - "__typename": "NextgenElementConnection", - "nodes": [ - { - "__typename": "NextgenElement", - "other": { - "__typename": "NextgenOther", - "id": "OTHER-1" - } - } - ] - } - }, - "extensions": {} - } - - serviceName: "Service" - request: - # language=GraphQL - query: |- - query { - ... on Query { - old { - ... on ElementConnection { - __typename - nodes { - ... on Element { - __typename - other { - ... on Other { - __typename - id - } - } - } - } - } - } - } - } - variables: { } - # language=JSON - response: |- - { - "data": { - "old": { - "__typename": "ElementConnection", - "nodes": [ - { - "__typename": "Element", - "other": { - "__typename": "Other", - "id": "OTHER-2" - } - } - ] - } - }, - "extensions": {} - } -# language=JSON -response: |- - { - "data": { - "elements": { - "__typename": "ElementConnection", - "nodes": [ - { - "__typename": "Element", - "other": { - "__typename": "RenamedOther", - "id": "OTHER-1" - } - } - ] - }, - "old": { - "__typename": "ElementConnection", - "nodes": [ - { - "__typename": "Element", - "other": { - "__typename": "RenamedOther", - "id": "OTHER-2" - } - } - ] - } - }, - "extensions": {} - } diff --git a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared.yml b/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared.yml deleted file mode 100644 index 58d9cfa88..000000000 --- a/test/src/test/resources/fixtures/renames/types/renamed-type-is-shared.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: "renamed type is shared" -# Not supported, currently blocked by validation -enabled: false -# language=GraphQL -overallSchema: - NextgenIssues: |- - type Query { - fastIssue(id: ID!): JiraIssue - } - IssueService: |- - type Query { - issue(id: ID): JiraIssue - } - type JiraIssue @renamed(from: "Issue") { - id: ID - } -# language=GraphQL -underlyingSchema: - NextgenIssues: |- - type Query { - fastIssue(id: ID!): NextgenIssue - } - type NextgenIssue { - id: ID - } - IssueService: |- - type Query { - issue(id: ID): Issue - } - type Issue { - id: ID - } -# language=GraphQL -query: | - query { - fastIssue(id: "ISSUE-1") { - __typename - id - } - } -variables: { } -serviceCalls: - - serviceName: "NextgenIssues" - request: - # language=GraphQL - query: | - query { - fastIssue(id: "ISSUE-1") { - __typename - id - } - } - variables: { } - # language=JSON - response: |- - { - "data": { - "fastIssue": { - "__typename": "NextgenIssue", - "id": "ISSUE-1" - } - }, - "extensions": {} - } -# language=JSON -response: |- - { - "data": { - "fastIssue": { - "__typename": "JiraIssue", - "id": "ISSUE-1" - } - }, - "extensions": {} - } diff --git a/test/src/test/resources/fixtures/renames/types/repeated-fragments-with-renamed-types.yml b/test/src/test/resources/fixtures/renames/types/repeated-fragments-with-renamed-types.yml index f7398b4bc..dd58f0db1 100644 --- a/test/src/test/resources/fixtures/renames/types/repeated-fragments-with-renamed-types.yml +++ b/test/src/test/resources/fixtures/renames/types/repeated-fragments-with-renamed-types.yml @@ -337,7 +337,7 @@ serviceCalls: "type": "unsure", "endService": null, "startService": { - "__typename": "MyService", + "__typename": "Service", "id": "service-1", "name": "GraphQL Gateway", "dependsOn": null, diff --git a/test/src/test/resources/fixtures/scalars/custom-json-scalar-as-input-type.yml b/test/src/test/resources/fixtures/scalars/custom-json-scalar-as-input-type.yml index d4fffef15..a0e75af8f 100644 --- a/test/src/test/resources/fixtures/scalars/custom-json-scalar-as-input-type.yml +++ b/test/src/test/resources/fixtures/scalars/custom-json-scalar-as-input-type.yml @@ -22,7 +22,7 @@ underlyingSchema: scalar JSON query: | query { - foo(input: {something: true answer: 42}) { + foo(input: {something: true answer: "42"}) { id } } @@ -40,7 +40,7 @@ serviceCalls: variables: v0: something: true - answer: 42 + answer: "42" # language=JSON response: |- { diff --git a/test/src/test/resources/fixtures/scalars/hydrating-json-data.yml b/test/src/test/resources/fixtures/scalars/hydrating-json-data.yml index 4ad1c15fd..481e492a2 100644 --- a/test/src/test/resources/fixtures/scalars/hydrating-json-data.yml +++ b/test/src/test/resources/fixtures/scalars/hydrating-json-data.yml @@ -44,7 +44,7 @@ underlyingSchema: scalar JSON query: | query { - foo(input: {something: true answer: 42}) { + foo(input: {something: true answer: "42"}) { foo { id } @@ -65,7 +65,7 @@ serviceCalls: variables: v0: something: true - answer: 42 + answer: "42" # language=JSON response: |- { diff --git a/test/src/test/resources/fixtures/scalars/hydrating-using-json-data-as-arg.yml b/test/src/test/resources/fixtures/scalars/hydrating-using-json-data-as-arg.yml index a19a0ad5c..a4f958366 100644 --- a/test/src/test/resources/fixtures/scalars/hydrating-using-json-data-as-arg.yml +++ b/test/src/test/resources/fixtures/scalars/hydrating-using-json-data-as-arg.yml @@ -48,7 +48,7 @@ underlyingSchema: scalar JSON query: | query { - foo(input: {something: true answer: 42}) { + foo(input: {something: true answer: "42"}) { foo { id } @@ -69,7 +69,7 @@ serviceCalls: variables: v0: something: true - answer: 42 + answer: "42" # language=JSON response: |- { diff --git a/test/src/test/resources/fixtures/scalars/indexed-hydrating-using-json-data-as-arg.yml b/test/src/test/resources/fixtures/scalars/indexed-hydrating-using-json-data-as-arg.yml index ef478defe..e973d56ca 100644 --- a/test/src/test/resources/fixtures/scalars/indexed-hydrating-using-json-data-as-arg.yml +++ b/test/src/test/resources/fixtures/scalars/indexed-hydrating-using-json-data-as-arg.yml @@ -50,7 +50,7 @@ underlyingSchema: scalar JSON query: | query { - foo(input: {something: true answer: 42}) { + foo(input: {something: true answer: "42"}) { foo { id } @@ -71,7 +71,7 @@ serviceCalls: variables: v0: something: true - answer: 42 + answer: "42" # language=JSON response: |- {