-
Notifications
You must be signed in to change notification settings - Fork 23
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
Refactor instruction definitions #644
base: improve-factory
Are you sure you want to change the base?
Changes from all commits
fefdb01
e9ea792
d193124
a19a800
0c3259f
dcd0883
24e5d26
ba57d73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package graphql.nadel.definition | ||
|
||
interface NadelInstructionDefinition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed from File too small for Git to pick up on the rename. |
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 = instructionDefinitions.getUnderlyingTypeName(overallType.unwrapAll()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the util into |
||
) | ||
} | ||
|
||
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 = instructionDefinitions.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, | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed for clarity as I have also created a
NadelInstructionDefinitionRegistry