-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve schema validation factory (#638)
* Improve factory and dependency flow * Replace context overloads with archunit test * Fix stuff * Update doco
- Loading branch information
Showing
17 changed files
with
340 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/src/main/java/graphql/nadel/validation/NadelAssignableTypeValidation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package graphql.nadel.validation | ||
|
||
import graphql.nadel.engine.util.unwrapAll | ||
import graphql.schema.GraphQLType | ||
|
||
class NadelAssignableTypeValidation internal constructor( | ||
private val typeWrappingValidation: NadelTypeWrappingValidation, | ||
) { | ||
context(NadelValidationContext) | ||
fun isOutputTypeAssignable( | ||
overallType: GraphQLType, | ||
underlyingType: GraphQLType, | ||
): Boolean { | ||
// Note: the (supplied) value comes from the underlying service, and that value needs to fit the (required) overall field's type | ||
return isTypeAssignable( | ||
suppliedType = underlyingType, | ||
requiredType = overallType, | ||
// Compare underlying type names | ||
suppliedTypeName = underlyingType.unwrapAll().name, | ||
requiredTypeName = getUnderlyingTypeName(overallType.unwrapAll()), | ||
) | ||
} | ||
|
||
context(NadelValidationContext) | ||
fun isInputTypeAssignable( | ||
overallType: GraphQLType, | ||
underlyingType: GraphQLType, | ||
): Boolean { | ||
// Note: the (supplied) value comes from the user (overall schema) and needs to be assigned to the (required) underlying type | ||
return isTypeAssignable( | ||
suppliedType = overallType, | ||
requiredType = underlyingType, | ||
// Compare underlying type names | ||
suppliedTypeName = getUnderlyingTypeName(overallType.unwrapAll()), | ||
requiredTypeName = underlyingType.unwrapAll().name, | ||
) | ||
} | ||
|
||
context(NadelValidationContext) | ||
fun isTypeAssignable( | ||
suppliedType: GraphQLType, | ||
requiredType: GraphQLType, | ||
suppliedTypeName: String, | ||
requiredTypeName: String, | ||
): Boolean { | ||
return suppliedTypeName == requiredTypeName && isTypeWrappingValid(suppliedType, requiredType) | ||
} | ||
|
||
private fun isTypeWrappingValid( | ||
suppliedType: GraphQLType, | ||
requiredType: GraphQLType, | ||
): Boolean { | ||
return typeWrappingValidation.isTypeWrappingValid( | ||
lhs = suppliedType, | ||
rhs = requiredType, | ||
rule = NadelTypeWrappingValidation.Rule.LHS_MUST_BE_STRICTER_OR_SAME, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.