@@ -1259,6 +1259,7 @@ You can use `@Argument` on a `Map<String, Object>` argument, to obtain all argum
1259
1259
values. The name attribute on `@Argument` must not be set.
1260
1260
1261
1261
1262
+
1262
1263
[[controllers-schema-mapping-arguments]]
1263
1264
==== `@Arguments`
1264
1265
@@ -1271,53 +1272,6 @@ case, top-level arguments are bound to `BookInput` properties.
1271
1272
1272
1273
1273
1274
1274
- [[controllers-schema-mapping-validation]]
1275
- ==== `@Argument(s)` Validation
1276
-
1277
- If a {spring-framework-ref-docs}/core.html#validation-beanvalidation-overview[Bean Validation]
1278
- `Validator` (or typically, a `LocalValidatorFactoryBean`) bean is present in the application context,
1279
- the `AnnotatedControllerConfigurer` will auto-detect it and configure support for validation.
1280
- Controller arguments annotated with `@Valid` and `@Validated` are then validated before method invocation.
1281
-
1282
- Bean Validation lets you declare constraints on types, as the following example shows:
1283
-
1284
- [source,java,indent=0,subs="verbatim,quotes"]
1285
- ----
1286
- public class BookInput {
1287
-
1288
- @NotNull
1289
- private String title;
1290
-
1291
- @NotNull
1292
- @Size(max=13)
1293
- private String isbn;
1294
- }
1295
- ----
1296
-
1297
- We can then mark our argument for validation with `@Valid`:
1298
-
1299
- [source,java,indent=0,subs="verbatim,quotes"]
1300
- ----
1301
- @Controller
1302
- public class BookController {
1303
-
1304
- @MutationMapping
1305
- public Book addBook(@Argument @Valid BookInput bookInput) {
1306
- // ...
1307
- }
1308
- }
1309
- ----
1310
-
1311
- If an error occurs during validation, a `ConstraintViolationException` is thrown and can be
1312
- later <<execution-exceptions,resolved with a custom `DataFetcherExceptionResolver`>>.
1313
-
1314
- [TIP]
1315
- ====
1316
- Unlike Spring MVC, handler method signatures do not support the injection of `BindingResult`
1317
- for reacting to validation errors: those are globally dealt with as exceptions.
1318
- ====
1319
-
1320
-
1321
1275
[[controllers-schema-mapping-projectedpayload-argument]]
1322
1276
==== `@ProjectedPayload` Interface
1323
1277
@@ -1368,6 +1322,7 @@ For example:
1368
1322
----
1369
1323
1370
1324
1325
+
1371
1326
[[controllers-schema-mapping-source]]
1372
1327
==== Source
1373
1328
@@ -1436,6 +1391,56 @@ delegates to a `DataLoader`, you can reduce boilerplate by using a
1436
1391
<<controllers-batch-mapping,@BatchMapping>> method as described in the next section.
1437
1392
1438
1393
1394
+ [[controllers-schema-mapping-validation]]
1395
+ ==== Validation
1396
+
1397
+ When a `javax.validation.Validator` bean is found, `AnnotatedControllerConfigurer` enables support for
1398
+ {spring-framework-ref-docs}/core.html#validation-beanvalidation-overview[Bean Validation]
1399
+ on annotated controller methods. Typically, the bean is of type `LocalValidatorFactoryBean`.
1400
+
1401
+ Bean validation lets you declare constraints on types:
1402
+
1403
+ [source,java,indent=0,subs="verbatim,quotes"]
1404
+ ----
1405
+ public class BookInput {
1406
+
1407
+ @NotNull
1408
+ private String title;
1409
+
1410
+ @NotNull
1411
+ @Size(max=13)
1412
+ private String isbn;
1413
+ }
1414
+ ----
1415
+
1416
+ You can then annotate a controller method parameter with `@Valid` to validate it before
1417
+ method invocation:
1418
+
1419
+ [source,java,indent=0,subs="verbatim,quotes"]
1420
+ ----
1421
+ @Controller
1422
+ public class BookController {
1423
+
1424
+ @MutationMapping
1425
+ public Book addBook(@Argument @Valid BookInput bookInput) {
1426
+ // ...
1427
+ }
1428
+ }
1429
+ ----
1430
+
1431
+ If an error occurs during validation, a `ConstraintViolationException` is raised.
1432
+ You can use the <<execution-exceptions>> chain to decide how to present that to clients
1433
+ by turning it into an error to include in the GraphQL response.
1434
+
1435
+ TIP: In addition to `@Valid`, you can also use Spring's `@Validated` that allows
1436
+ specifying validation groups.
1437
+
1438
+ Bean validation is useful for <<controllers-schema-mapping-argument>>,
1439
+ <<controllers-schema-mapping-arguments>>, and
1440
+ <<controllers-schema-mapping-projectedpayload-argument,@ProjectedPayload>>
1441
+ method parameters, but applies more generally to any method parameter.
1442
+
1443
+
1439
1444
1440
1445
[[controllers-batch-mapping]]
1441
1446
=== `@BatchMapping`
0 commit comments