From b74f47141a818c614e22aaf1e090ad97806b5aa2 Mon Sep 17 00:00:00 2001 From: Steven Barker Date: Thu, 27 Jun 2024 10:24:47 +1200 Subject: [PATCH] add seaparate test suite for deferred transforms --- .../DeferredFieldIsRenamedTest.kt | 2 +- .../DeferredFieldIsRenamedTestSnapshot.kt | 2 +- ...tipleRenamedFieldsAreDeferredSeparately.kt | 77 ++++++++++++++++++ ...amedFieldsAreDeferredSeparatelySnapshot.kt | 74 +++++++++++++++++ ...ultipleRenamedFieldsAreDeferredTogether.kt | 75 +++++++++++++++++ ...enamedFieldsAreDeferredTogetherSnapshot.kt | 80 +++++++++++++++++++ ...ngDeferButNonDeferredFieldIsRenamedTest.kt | 2 +- ...utNonDeferredFieldIsRenamedTestSnapshot.kt | 2 +- 8 files changed, 310 insertions(+), 4 deletions(-) rename test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/{ => transforms}/DeferredFieldIsRenamedTest.kt (97%) rename test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/{ => transforms}/DeferredFieldIsRenamedTestSnapshot.kt (97%) create mode 100644 test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparately.kt create mode 100644 test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparatelySnapshot.kt create mode 100644 test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogether.kt create mode 100644 test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogetherSnapshot.kt rename test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/{ => transforms}/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt (97%) rename test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/{ => transforms}/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt (98%) diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/DeferredFieldIsRenamedTest.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsRenamedTest.kt similarity index 97% rename from test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/DeferredFieldIsRenamedTest.kt rename to test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsRenamedTest.kt index c3ae4af65..7bdd37bf0 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/DeferredFieldIsRenamedTest.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsRenamedTest.kt @@ -1,4 +1,4 @@ -package graphql.nadel.tests.next.fixtures.defer +package graphql.nadel.tests.next.fixtures.defer.transforms import graphql.nadel.NadelExecutionHints import graphql.nadel.tests.next.NadelIntegrationTest diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/DeferredFieldIsRenamedTestSnapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsRenamedTestSnapshot.kt similarity index 97% rename from test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/DeferredFieldIsRenamedTestSnapshot.kt rename to test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsRenamedTestSnapshot.kt index f27698c7a..4a87be995 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/DeferredFieldIsRenamedTestSnapshot.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsRenamedTestSnapshot.kt @@ -1,5 +1,5 @@ // @formatter:off -package graphql.nadel.tests.next.fixtures.defer +package graphql.nadel.tests.next.fixtures.defer.transforms import graphql.nadel.tests.next.ExpectedNadelResult import graphql.nadel.tests.next.ExpectedServiceCall diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparately.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparately.kt new file mode 100644 index 000000000..2687ac9d3 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparately.kt @@ -0,0 +1,77 @@ +package graphql.nadel.tests.next.fixtures.defer.transforms + +import graphql.nadel.NadelExecutionHints +import graphql.nadel.tests.next.NadelIntegrationTest + +open class MultipleRenamedFieldsAreDeferredSeparately : NadelIntegrationTest( + query = """ + query { + defer { + hello + ...@defer(label: "defer1") { + overallString + } + ...@defer(label: "defer2") { + overallString + } + } + } + """.trimIndent(), + services = listOf( + Service( + name = "defer", + overallSchema = """ + directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT + + type Query { + defer: DeferApi + } + type DeferApi { + hello: String + overallString: String @renamed(from: "underlyingString") + overallString2: String @renamed(from: "underlyingString2") + } + + """.trimIndent(), + underlyingSchema = """ + directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT + + type Query { + defer: DeferApi + } + type DeferApi { + hello: String + underlyingString: String + underlyingString2: String + } + + """.trimIndent(), + runtimeWiring = { wiring -> + wiring + .type("Query") { type -> + type + .dataFetcher("defer") { env -> + Any() + } + } + .type("DeferApi") { type -> + type + .dataFetcher("hello") { env -> + "hello there" + } + .dataFetcher("underlyingString") { env -> + "deferred string 1" + } + .dataFetcher("underlyingString2") { env -> + "deferred string 2" + } + } + }, + ), + ), +) { + override fun makeExecutionHints(): NadelExecutionHints.Builder { + return super.makeExecutionHints() + .deferSupport { true } + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparatelySnapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparatelySnapshot.kt new file mode 100644 index 000000000..cc88dc1d8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredSeparatelySnapshot.kt @@ -0,0 +1,74 @@ +// @formatter:off +package graphql.nadel.tests.next.fixtures.defer.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 + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class MultipleRenamedFieldsAreDeferredSeparatelySnapshot : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "defer", + query = """ + | { + | defer { + | hello + | rename__overallString__underlyingString: underlyingString + | __typename__rename__overallString: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "defer": { + | "hello": "hello there", + | "rename__overallString__underlyingString": "deferred string 1", + | "__typename__rename__overallString": "DeferApi" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "defer": { + * "hello": "hello there", + * "overallString": "deferred string 1" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "defer": { + | "hello": "hello there", + | "overallString": "deferred string 1" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogether.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogether.kt new file mode 100644 index 000000000..4dc9432f8 --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogether.kt @@ -0,0 +1,75 @@ +package graphql.nadel.tests.next.fixtures.defer.transforms + +import graphql.nadel.NadelExecutionHints +import graphql.nadel.tests.next.NadelIntegrationTest + +open class MultipleRenamedFieldsAreDeferredTogether : NadelIntegrationTest( + query = """ + query { + defer { + hello + ...@defer { + overallString + overallString2 + } + } + } + """.trimIndent(), + services = listOf( + Service( + name = "defer", + overallSchema = """ + directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT + + type Query { + defer: DeferApi + } + type DeferApi { + hello: String + overallString: String @renamed(from: "underlyingString") + overallString2: String @renamed(from: "underlyingString2") + } + + """.trimIndent(), + underlyingSchema = """ + directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT + + type Query { + defer: DeferApi + } + type DeferApi { + hello: String + underlyingString: String + underlyingString2: String + } + + """.trimIndent(), + runtimeWiring = { wiring -> + wiring + .type("Query") { type -> + type + .dataFetcher("defer") { env -> + Any() + } + } + .type("DeferApi") { type -> + type + .dataFetcher("hello") { env -> + "hello there" + } + .dataFetcher("underlyingString") { env -> + "deferred string 1" + } + .dataFetcher("underlyingString2") { env -> + "deferred string 2" + } + } + }, + ), + ), +) { + override fun makeExecutionHints(): NadelExecutionHints.Builder { + return super.makeExecutionHints() + .deferSupport { true } + } +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogetherSnapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogetherSnapshot.kt new file mode 100644 index 000000000..dccfbdb4f --- /dev/null +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/MultipleRenamedFieldsAreDeferredTogetherSnapshot.kt @@ -0,0 +1,80 @@ +// @formatter:off +package graphql.nadel.tests.next.fixtures.defer.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 + +/** + * This class is generated. Do NOT modify. + * + * Refer to [graphql.nadel.tests.next.UpdateTestSnapshots + */ +@Suppress("unused") +public class MultipleRenamedFieldsAreDeferredTogetherSnapshot : TestSnapshot() { + override val calls: List = listOf( + ExpectedServiceCall( + service = "defer", + query = """ + | { + | defer { + | hello + | rename__overallString__underlyingString: underlyingString + | __typename__rename__overallString: __typename + | rename__overallString2__underlyingString2: underlyingString2 + | __typename__rename__overallString2: __typename + | } + | } + """.trimMargin(), + variables = "{}", + result = """ + | { + | "data": { + | "defer": { + | "hello": "hello there", + | "rename__overallString__underlyingString": "deferred string 1", + | "__typename__rename__overallString": "DeferApi", + | "rename__overallString2__underlyingString2": "deferred string 2", + | "__typename__rename__overallString2": "DeferApi" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ), + ) + + /** + * ```json + * { + * "data": { + * "defer": { + * "hello": "hello there", + * "overallString": "deferred string 1", + * "overallString2": "deferred string 2" + * } + * } + * } + * ``` + */ + override val result: ExpectedNadelResult = ExpectedNadelResult( + result = """ + | { + | "data": { + | "defer": { + | "hello": "hello there", + | "overallString": "deferred string 1", + | "overallString2": "deferred string 2" + | } + | } + | } + """.trimMargin(), + delayedResults = listOfJsonStrings( + ), + ) +} diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt similarity index 97% rename from test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt rename to test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt index ac2e9c47b..a63b2de3e 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/QueryContainingDeferButNonDeferredFieldIsRenamedTest.kt @@ -1,4 +1,4 @@ -package graphql.nadel.tests.next.fixtures.defer +package graphql.nadel.tests.next.fixtures.defer.transforms import graphql.nadel.NadelExecutionHints import graphql.nadel.tests.next.NadelIntegrationTest diff --git a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt similarity index 98% rename from test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt rename to test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt index 9b1282017..246ff76cc 100644 --- a/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt +++ b/test/src/test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/QueryContainingDeferButNonDeferredFieldIsRenamedTestSnapshot.kt @@ -1,5 +1,5 @@ // @formatter:off -package graphql.nadel.tests.next.fixtures.defer +package graphql.nadel.tests.next.fixtures.defer.transforms import graphql.nadel.tests.next.ExpectedNadelResult import graphql.nadel.tests.next.ExpectedServiceCall