Skip to content

Commit

Permalink
Extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf committed Dec 14, 2023
1 parent 18add14 commit 7dc7862
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal class NadelHydrationValidation(
hydrations: List<UnderlyingServiceHydration>,
): List<NadelSchemaValidationError> {
if (hydrations.size > 1) {
val hasListSourceInputField = hydrations
val anyListSourceInputField = hydrations
.any { hydration ->
val parentType = parent.underlying as GraphQLFieldsContainer
hydration
Expand All @@ -119,7 +119,7 @@ internal class NadelHydrationValidation(
}
}

if (hasListSourceInputField) {
if (anyListSourceInputField) {
val sourceFields = hydrations
.flatMapTo(LinkedHashSet()) { hydration ->
hydration.arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7dc7862

Please sign in to comment.