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

Ready - Improved hydration validation #463

Merged
merged 34 commits into from
Oct 17, 2023
Merged

Conversation

sbarker2
Copy link
Collaborator

@sbarker2 sbarker2 commented Oct 9, 2023

Merged: https://github.com/atlassian-labs/nadel/pull/461/files/e3ff70e3eb4a60f03f1fed2a6e014dc2775de069

This PR is Ready For Review and not awaiting any other PRs 👍

Tested in central schema ✅
Passed Engine Tests ✅
Added unit tests covering all cases ✅

@sbarker2 sbarker2 requested a review from gnawf October 9, 2023 03:20
@sbarker2 sbarker2 self-assigned this Oct 11, 2023
null
StaticArgument -> {
val staticArg = remoteArgSource.staticValue
if (!validationUtil.isValidLiteralValue(
Copy link
Collaborator Author

@sbarker2 sbarker2 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note / context:

isValidLiteralValue is a public function from this class in graphql-java:
https://github.com/graphql-java/graphql-java/blob/dd50648b5e178f965918d0c352787bd81654c7fe/src/main/java/graphql/validation/ValidationUtil.java

This is an internal class, but I have checked over the code and confirmed it is what we want, including recursively checking inner types of objects/functions and everything.
Have also added extensive tests for static args to check this in NadelHydrationArgumentValidationTest.kt
It is an internal class in

if (actorFieldArgType.isNonNull && !hydrationSourceFieldType.isNonNull) {
//need to check null compatibility
val sourceType = remoteArg.remoteArgumentSource.sourceType
if (sourceType != ObjectField && actorFieldArgType.isNonNull && !hydrationSourceFieldType.isNonNull) {
Copy link
Collaborator Author

@sbarker2 sbarker2 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added sourceType != ObjectField so that it ignores null compatibility for $source arguments as that is handled differently by nadel.

(As discussed in the live PR review)

@sbarker2 sbarker2 changed the title WIP - Improved hydration validation Ready - Improved hydration validation Oct 12, 2023
//could have ID feed into [ID] (as a possible batch hydration case).
// in this case we need to unwrap the list and check types
if (isBatchHydration && (!unwrappedHydrationSourceFieldType.isList && unwrappedActorFieldArgType.isList)) {
val error = getHydrationInputErrors(
Copy link
Collaborator Author

@sbarker2 sbarker2 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:

a recurring theme here is:
val error = getErrors()
if (error != null) { return Error(blah)}

the reason we cant just simplify this to return getErrors() is because we are recursively unwrapping the supplied & actor arg types, but for the error, it is generally more helpful for the message to display the original type, not some inner type that we have unwrapped

@@ -142,50 +139,51 @@ internal class NadelHydrationValidation(
}

private fun getArgumentErrors(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual added logic for this file is in this function

(typeToAssign.name == Scalars.GraphQLString.name || typeToAssign.name == Scalars.GraphQLInt.name)) {
return true
}
if (targetType.name == Scalars.GraphQLString.name && typeToAssign.name == Scalars.GraphQLID.name) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I agree with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we'll have a discussion on the page

bbakerman
bbakerman previously approved these changes Oct 16, 2023
(typeToAssign.name == Scalars.GraphQLString.name || typeToAssign.name == Scalars.GraphQLInt.name)) {
return true
}
if (targetType.name == Scalars.GraphQLString.name && typeToAssign.name == Scalars.GraphQLID.name) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I agree with this.


// scalar feed into scalar
if (unwrappedHydrationSourceFieldType is GraphQLScalarType && unwrappedActorFieldArgType is GraphQLScalarType) {
return validateScalarArg(hydrationSourceFieldType, actorFieldArgType, parent, overallField, remoteArg, actorFieldName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before, can you pass in unwrappedHydrationSourceFieldType here instead of passing in the raw GraphQLType and then unwrapping it inside the function?

Copy link
Collaborator Author

@sbarker2 sbarker2 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing in wrapped type because we want to preserve the wrapped type to print in the error message to avoid any confusion from the user

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only reason we could pass in the unwrapped type previously (in the case that its an object) is because we do not show the type in that one error message

@sbarker2 sbarker2 merged commit 8844fb9 into master Oct 17, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants