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

Support oneOf directive on input objects #1119

Merged
merged 9 commits into from
Jul 22, 2024

Conversation

asteinwedel
Copy link

@asteinwedel asteinwedel commented Jul 18, 2024

Issue:
#1068

WIP.

The main thing I'm missing is when checking that there's "exactly one non-null field" on a query (I have the ExactlyOneOfFieldGiven rule), I'm struggling with validating against ast.VariableValue (since I need the unmarshalled input for that). (and considering default values for VariableDefinition -- though that seems easier than getting the actual input)

was wondering if it needs to go in the execution part for checking variables, but that seems a bit messier.

Trying to figure it out...but feel free to contribute if you have a way to go about that

@yanns
Copy link
Contributor

yanns commented Jul 18, 2024

first of all, thanks for your contribution!
I see it's already going well, with good test coverage.

For the missing validation, do you already have failing tests for it? It would save me time.

@asteinwedel
Copy link
Author

asteinwedel commented Jul 18, 2024

first of all, thanks for your contribution! I see it's already going well, with good test coverage.

For the missing validation, do you already have failing tests for it? It would save me time.

I do not, as the tests I have setup aren't setup for variables.

Testing something like this would be a basic case (and then also default values, if you get something setup I can add extra test cases)

val schema = gql"""
   type Query {
      oneOfQuery(input: OneOfInput!)
  }
  
  input OneOfInput @oneOf {
    foo: String
    bar: Int
  }
"""

val query = """
  query Test($foo: String) {
    oneOfQuery(input: { foo: $foo, bar: 123 })
  }
"""

val variables = """{ "foo": "testing" }"""

@@ -29,107 +29,116 @@ case class Executor[Ctx, Root](
operationName: Option[String] = None,
variables: Input = emptyMapVars
)(implicit um: InputUnmarshaller[Input]): Future[PreparedQuery[Ctx, Root, Input]] = {
val (violations, validationTiming) =
Copy link
Author

@asteinwedel asteinwedel Jul 19, 2024

Choose a reason for hiding this comment

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

this is mostly just moving things around so queryValidator.validateQuery has access to unmarshalledVariables (split view might be easier)

same with similar places where things moved like this

@asteinwedel asteinwedel force-pushed the oneOf-input-obj branch 2 times, most recently from 01da0f8 to c8ef4bd Compare July 19, 2024 11:58
@asteinwedel
Copy link
Author

asteinwedel commented Jul 19, 2024

@yanns I got something working (well passes the tests I added), though it causes some breaking changes with QueryValidator needing variable values now, and had to move things around for that

working on making sure build / tests passes

but that change is in its own commit

@asteinwedel asteinwedel force-pushed the oneOf-input-obj branch 2 times, most recently from bea2b56 to 0d0929a Compare July 19, 2024 12:09
@asteinwedel
Copy link
Author

asteinwedel commented Jul 19, 2024

hmm moving validation after variable coercion (since we need that) needs a bit more tuning to make sure validation errors get thrown before variable coercion errors

@asteinwedel asteinwedel force-pushed the oneOf-input-obj branch 2 times, most recently from 1087841 to 0388cef Compare July 19, 2024 12:27
QueryValidator needs access to variables now, so this causes a breaking change.
@asteinwedel
Copy link
Author

alright...seems passing now

@asteinwedel asteinwedel marked this pull request as ready for review July 19, 2024 12:41
@asteinwedel
Copy link
Author

let me know if think of a better way to check the variable values

@yanns
Copy link
Contributor

yanns commented Jul 22, 2024

Just taking notes:

  • we need to validate: "making a OneOf Input Object into a regular Input Object is a non-breaking change (the reverse is a breaking change)"
  • would it be better to follow all test cases documented in the spec?
  • about the validation of variables with the QueryValidator: it's indeed quite a big change. But I don't see how we can do without this. We could split the validation in 2: one without and one with the variables. But I found it's quite nice to have all validations inside ExactlyOneOfFieldGiven. Maybe I could release a release candidate version, and we could check if we're breaking much.

@yanns yanns force-pushed the oneOf-input-obj branch 2 times, most recently from 305bb0b to 2fb639d Compare July 22, 2024 10:48
Copy link
Contributor

@yanns yanns left a comment

Choose a reason for hiding this comment

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

looking good to me. I'll release a RC to test that with more code.

@yanns
Copy link
Contributor

yanns commented Jul 22, 2024

I almost forgot: we need to test for breaking changes (

)

@asteinwedel
Copy link
Author

asteinwedel commented Jul 22, 2024

ah thanks for the spec link!

looks like the official spec doesn't like null values either which is the main difference (counts as >1 still), updated tests and made sure those cases were all covered

(from spec: I didn't do type checking since that's another area of sangria validation)

will work on the breaking change one now

edit: wait saw you did some commits already

@yanns
Copy link
Contributor

yanns commented Jul 22, 2024

yes sorry, it was easier for me to push some changes directly. I've also pushed the changes for the breaking changes.

@asteinwedel
Copy link
Author

asteinwedel commented Jul 22, 2024

yes sorry, it was easier for me to push some changes directly. I've also pushed the changes for the breaking changes.

got it thanks! I pushed the null check change + tests now

@yanns yanns force-pushed the oneOf-input-obj branch from 4758e42 to 49b8b01 Compare July 22, 2024 12:13
@yanns
Copy link
Contributor

yanns commented Jul 22, 2024

oh miss, I force pushed some changes as the last commit from me was not complete (was missing the exceptions for the mina checks).
Now I'm over.
Can you push your changes again?
Edit: i see you did, thanks!

Copy link
Contributor

@yanns yanns left a comment

Choose a reason for hiding this comment

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

Is there anything left you'd like to add / change?

@asteinwedel
Copy link
Author

Is there anything left you'd like to add / change?

nope think this covers it all! thanks for the help!

@yanns yanns added this pull request to the merge queue Jul 22, 2024
Merged via the queue into sangria-graphql:main with commit 65a6c5e Jul 22, 2024
4 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.

2 participants