diff --git a/lib/src/main/java/graphql/nadel/validation/NadelHydrationValidation.kt b/lib/src/main/java/graphql/nadel/validation/NadelHydrationValidation.kt index 79aa90969..ec660b7da 100644 --- a/lib/src/main/java/graphql/nadel/validation/NadelHydrationValidation.kt +++ b/lib/src/main/java/graphql/nadel/validation/NadelHydrationValidation.kt @@ -98,7 +98,7 @@ internal class NadelHydrationValidation( hydrations: List, ): List { if (hydrations.size > 1) { - val hasListSourceInputField = hydrations + val anyListSourceInputField = hydrations .any { hydration -> val parentType = parent.underlying as GraphQLFieldsContainer hydration @@ -112,7 +112,7 @@ internal class NadelHydrationValidation( } } - if (hasListSourceInputField) { + if (anyListSourceInputField) { val sourceFields = hydrations .flatMapTo(LinkedHashSet()) { hydration -> hydration.arguments diff --git a/lib/src/test/kotlin/graphql/nadel/validation/NadelHydrationValidationTest2.kt b/lib/src/test/kotlin/graphql/nadel/validation/NadelHydrationValidationTest2.kt index fa32fb850..d8c2265d2 100644 --- a/lib/src/test/kotlin/graphql/nadel/validation/NadelHydrationValidationTest2.kt +++ b/lib/src/test/kotlin/graphql/nadel/validation/NadelHydrationValidationTest2.kt @@ -170,6 +170,94 @@ class NadelHydrationValidationTest2 { assertTrue(errors.single().subject.name == "data") } + @Test + fun `prohibit mixing list and non-list source input fields`() { + val fixture = NadelValidationTestFixture( + overallSchema = mapOf( + "activity" to /* language=GraphQL*/ """ + type Query { + myActivity: [Activity] + } + union ActivityContent = User | Issue + type Activity { + id: ID! + data: [ActivityContent] + @hydrated( + service: "users" + field: "usersByIds" + arguments: [ + {name: "ids", value: "$source.userIds"} + ] + ) + @hydrated( + service: "issues" + field: "issuesByIds" + arguments: [ + {name: "ids", value: "$source.issueId"} + ] + ) + } + """.trimIndent(), + "users" to /* language=GraphQL*/ """ + type Query { + usersByIds(ids: [ID]!): [User] + } + type User { + id: ID! + name: String! + } + """.trimIndent(), + "issues" to /* language=GraphQL*/ """ + type Query { + issuesByIds(ids: [ID]!): [Issue] + } + type Issue { + id: ID! + key: String + } + """.trimIndent(), + ), + underlyingSchema = mapOf( + "activity" to /* language=GraphQL*/ """ + type Query { + myActivity: [Activity] + } + type Activity { + id: ID! + userIds: [ID] + issueId: ID + } + """.trimIndent(), + "users" to /* language=GraphQL*/ """ + type Query { + usersByIds(ids: [ID]!): [User] + } + type User { + id: ID! + name: String! + } + type Account { + id: ID! + } + """.trimIndent(), + "issues" to /* language=GraphQL*/ """ + type Query { + issuesByIds(ids: [ID]!): [Issue] + } + type Issue { + id: ID! + key: String + } + """.trimIndent(), + ), + ) + + val errors = validate(fixture) + assertTrue(errors.map { it.message }.isNotEmpty()) + assertTrue(errors.single() is NadelSchemaValidationError.MultipleHydrationSourceInputFields) + assertTrue(errors.single().subject.name == "data") + } + @Test fun `permit multiple source fields if source input field is not list type`() { val fixture = NadelValidationTestFixture(