Skip to content

Support checks if GraphQL argument was set to null or omitted entirely #518

New issue

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

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

Already on GitHub? # to your account

Closed
rstoyanchev opened this issue Oct 21, 2022 · 2 comments
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Oct 21, 2022

By default input arguments in GraphQL are nullable and optional, see Nullable vs Optional, which means an argument can be set to null, or not provided at all. The distinction enables partial updates in mutations where the underlying data storage can also be either set to null or not changed at all.

As described in #140 and #228, when binding an argument via @Argument, there is no way to make such a distinction. You can get a null or an empty Optional for the resulting value, but no way to check if the argument was omitted or not.

We can provide ArgumentValue as a simple container for the underlying value along with a flag for whether it was omitted or not. This could be used as an alternative to @Argument on controller method parameters, or nested within the structure of an @Argument object.

@rstoyanchev rstoyanchev added the type: enhancement A general enhancement label Oct 21, 2022
@rstoyanchev rstoyanchev added this to the 1.1.0 milestone Oct 21, 2022
@rstoyanchev rstoyanchev self-assigned this Oct 21, 2022
@rstoyanchev rstoyanchev changed the title Support checking if an argument was omitted Support checking if a GraphQL argument was omitted Oct 21, 2022
@jord1e
Copy link
Contributor

jord1e commented Oct 24, 2022

@rstoyanchev typo at
d9f815e#diff-99d081232dfcf90f7ad4241a7e5ad145df4f8166f2bf13d5ab2b0e0775130cbbR1409

should be

- if (!bookInput.isOmitted) {
+ if (!bookInput.isOmitted()) {

@rstoyanchev
Copy link
Contributor Author

Updated in be9a215.

@rstoyanchev rstoyanchev changed the title Support checking if a GraphQL argument was omitted Support checks if GraphQL argument was set to null or omitted entirely Nov 9, 2022
koenpunt pushed a commit to koenpunt/spring-graphql that referenced this issue Feb 2, 2023
josianyman pushed a commit to josianyman/spring-graphql that referenced this issue May 13, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants