Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make union validation a soft error i.e. can still create instruction #666

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import graphql.nadel.validation.isRenamed
import graphql.nadel.validation.ok
import graphql.nadel.validation.onError
import graphql.nadel.validation.onErrorCast
import graphql.nadel.validation.results
import graphql.nadel.validation.toResult
import graphql.schema.GraphQLDirectiveContainer
import graphql.schema.GraphQLFieldDefinition
Expand Down Expand Up @@ -118,18 +119,23 @@ class NadelHydrationValidation internal constructor() {
.onError { return it }
limitSourceField(parent, virtualField, hydrations)
.onError { return it }
validateUnion(parent, virtualField, hydrations)
.onError { return it }

return hydrations
.map { hydration ->
validate(parent, virtualField, hydration, hasMoreThanOneHydration)
}
.toResult()
return results(
validateUnionMembersBacked(parent, virtualField, hydrations), // Do this instead of .onError for a soft error
hydrations
.map { hydration ->
validate(parent, virtualField, hydration, hasMoreThanOneHydration)
}
.toResult(),
)
}

/**
* Checks that if the virtual field outputs a union, that all of its union members have
* a corresponding backing field that can resolve it.
*/
context(NadelValidationContext)
private fun validateUnion(
private fun validateUnionMembersBacked(
parent: NadelServiceSchemaElement.FieldsContainer,
virtualField: GraphQLFieldDefinition,
hydrations: List<NadelHydrationDefinition>,
Expand Down
Loading