Revert ArgumentValue->FieldValue changes

See gh-1187
See gh-1190
See gh-1174
This commit is contained in:
Brian Clozel
2025-04-15 12:01:40 +02:00
parent 179929a298
commit ac9616fd9f
34 changed files with 105 additions and 1181 deletions

View File

@@ -393,47 +393,6 @@ include-code::UseInterceptor[tag=register,indent=0]
[[client.fieldvalue]]
== `FieldValue`
By default, input types in GraphQL are nullable and optional, an input value (or any of its fields)
can be set to the `null` literal, or not provided at all. This distinction is useful for
partial updates with a mutation where the underlying data may also be, either set to
`null` or not changed at all accordingly.
Similar to the xref:controllers.adoc#controllers.schema-mapping.fieldvalue[`FieldValue<T> support in controllers`],
we can wrap an Input type with `FieldValue<T>` or use it at the level of class attributes on the client side.
Given a `ProjectInput` class like:
include-code::ProjectInput[indent=0]
We can use our client to send a mutation request:
include-code::FieldValueClient[tag=fieldvalue,indent=0]
For this to work, the client must use Jackson for JSON (de)serialization and must be configured
with the `org.springframework.graphql.client.json.GraphQlModule`.
This can be registered manually on the underlying HTTP client like so:
include-code::FieldValueClient[tag=createclient,indent=0]
This `GraphQlModule` can be globally registered in Spring Boot applications by contributing it as a bean:
[source,java,indent=0,subs="verbatim,quotes"]
----
@Configuration
public class GraphQlJsonConfiguration {
@Bean
public GraphQLModule graphQLModule() {
return new GraphQLModule();
}
}
----
[[client.dgsgraphqlclient]]
== DGS Codegen

View File

@@ -143,11 +143,11 @@ See xref:controllers.adoc#controllers.schema-mapping.argument[`@Argument`].
See xref:controllers.adoc#controllers.schema-mapping.argument[`@Argument`].
| `FieldValue`
| `ArgumentValue`
| For access to a named field argument bound to a higher-level, typed Object along
with a flag to indicate if the input argument was omitted vs set to `null`.
See xref:controllers.adoc#controllers.schema-mapping.field-value[`FieldValue`].
See xref:controllers.adoc#controllers.schema-mapping.argument-value[`ArgumentValue`].
| `@Arguments`
| For access to all field arguments bound to a higher-level, typed Object.
@@ -403,8 +403,8 @@ specified in the annotation, or to the parameter name. For access to the full ar
map, please use xref:controllers.adoc#controllers.schema-mapping.arguments[`@Arguments`] instead.
[[controllers.schema-mapping.fieldvalue]]
=== `FieldValue`
[[controllers.schema-mapping.argument-value]]
=== `ArgumentValue`
By default, input arguments in GraphQL are nullable and optional, which means an argument
can be set to the `null` literal, or not provided at all. This distinction is useful for
@@ -414,7 +414,7 @@ there is no way to make such a distinction, because you would get `null` or an e
`Optional` in both cases.
If you want to know not whether a value was not provided at all, you can declare an
`FieldValue` method parameter, which is a simple container for the resulting value,
`ArgumentValue` method parameter, which is a simple container for the resulting value,
along with a flag to indicate whether the input argument was omitted altogether. You
can use this instead of `@Argument`, in which case the argument name is determined from
the method parameter name, or together with `@Argument` to specify the argument name.
@@ -426,31 +426,20 @@ For example:
@Controller
public class BookController {
@QueryMapping
public List<Book> searchBook(@Argument String search, FieldValue<Genre> genre) {
if (!genre.isOmitted()) {
// genre has been set but might hold a "null" value
Genre genreValue = genre.value();
}
}
@MutationMapping
public void addBook(@Argument BookInput bookInput) {
FieldValue<String> genre = bookInput.genre();
genre.ifPresent(genre -> {
//...
});
public void addBook(ArgumentValue<BookInput> bookInput) {
if (!bookInput.isOmitted()) {
BookInput value = bookInput.value();
// ...
}
}
}
----
`FieldValue` is also supported as a field within the object structure of an `@Argument`
`ArgumentValue` is also supported as a field within the object structure of an `@Argument`
method parameter, either initialized via a constructor argument or via a setter, including
as a field of an object nested at any level below the top level object.
This is also supported on the client side with a dedicated Jackson Module,
see the xref:client.adoc#client.fieldvalue[`FieldValue` support for clients] section.
[[controllers.schema-mapping.arguments]]
=== `@Arguments`