@@ -397,43 +397,53 @@ however, that such a visitor cannot change the schema. See
397
397
[[execution.graphqlsource.schema-mapping-inspection]]
398
398
==== Schema Mapping Inspection
399
399
400
- If a a query, mutation, or subscription operation does not have a `DataFetcher`, it won't
401
- return any data, and won't do anything useful. Fields on schema types returned by
402
- an operation should be covered by an explicit `DataFetcher` registration, or implicitly by
403
- the default `PropertyDataFetcher`, which looks for a matching Java object property, or
404
- otherwise they will always be `null`.
405
-
406
- GraphQL Java does not perform checks to ensure every schema field is covered one way or
407
- another, and that means at runtime you'll get either an error for a non-null field, or
408
- a "silent" `null`. As a lower level library, GraphQL Java simply does not know enough
409
- about `DataFetcher` implementations and their return types, and can't effectively compare
410
- schema types against Java objects.
400
+ If a query, mutation, or subscription operation does not have a `DataFetcher`, it won't
401
+ return any data, and won't do anything useful. Likewise, fields on schema types returned
402
+ by an operation that are covered neither explicitly through a `DataFetcher`
403
+ registration, nor implicitly by the default `PropertyDataFetcher`, which looks for a
404
+ matching Java object property, will always be `null`.
405
+
406
+ GraphQL Java does not perform checks to ensure every schema field is covered, and that
407
+ can result in gaps that might not be discovered depending on test coverage. At runtime
408
+ you may get a "silent" `null`, or an error if the field is not nullable. As a lower level
409
+ library, GraphQL Java simply does not know enough about `DataFetcher` implementations and
410
+ their return types, and therefore can't compare schema type structure against Java object
411
+ structure.
411
412
412
413
Spring for GraphQL defines the `SelfDescribingDataFetcher` interface to allow a
413
414
`DataFetcher` to expose return type information. All Spring `DataFetcher` implementations
414
- including those for <<controllers>>, and for <<data.querydsl>> and <<data.querybyexample>>
415
- implement this interface. For annotated controllers, the return type is
416
- transparently sourced from `@SchemaMapping` method signature.
415
+ implement this interface. That includes those for <<controllers>>, and those for
416
+ <<data.querydsl>> and <<data.querybyexample>> Spring Data repositories. For annotated
417
+ controllers, the return type is derived from the declared return type on `@SchemaMapping`
418
+ methods.
417
419
418
- On startup, Spring for GraphQL checks schema mappings to ensure every field has either an
419
- explicit `DataFetcher`, or a matching Java object property. The inspection is performed
420
- automatically, and results in a report logged at INFO level. For example:
420
+ On startup, Spring for GraphQL inspects all schema fields, `DataFetcher` registrations,
421
+ and the properties of Java objects returned from `DataFetcher` implementations in order
422
+ to ensure that every schema field has either an explicitly registered `DataFetcher`, or
423
+ a matching Java object property. This inspection is performed automatically, and results
424
+ in a report that is always logged on startup at INFO level. For example:
421
425
422
426
----
423
427
GraphQL schema inspection:
424
428
Unmapped fields: {Book=[title], Author[firstName, lastName]} // <1>
425
429
Skipped types: [BookOrAuthor] // <2>
426
430
----
427
431
428
- <1> List of schema fields ( and source types) that are not mapped
429
- <2> List of schema types that are skipped ( explained next)
432
+ <1> List of schema fields and their source types that are not mapped
433
+ <2> List of schema types that are skipped, as explained next
430
434
431
- There are limits to what the inspection can do, mainly when there is insufficient Java
435
+ There are limits to what schema mappings inspection can do, in particular when there is insufficient Java
432
436
type information. This is the case if an annotated controller method returns
433
437
`java.lang.Object` such as for a `union` type, or if a `DataFetcher` does not implement
434
- `SelfDescribingDataFetcher`. If a type is skipped it is included as such in the
435
- report summary. For `interface` types, the inspection checks only interface declared
436
- fields against the properties of the `DataFetcher` declared Java return type.
438
+ `SelfDescribingDataFetcher`. If a schema type is skipped, its name is listed as such in
439
+ the report, and a DEBUG message is logged to provide a reason for why it was skipped.
440
+
441
+ For schema `interface` types, the inspection currently checks only fields declared
442
+ directly on the interface against properties of the Java return type declared by the
443
+ `DataFetcher`. Additional fields on concrete implementations are not inspected, as there
444
+ is insufficient information about what Java types may be returned at runtime. This could
445
+ be improved in a future release to extend inspection to schema `interface` implementing
446
+ types to look for a match among implementation classes of the Java interface.
437
447
438
448
439
449
[[execution.graphqlsource.operation-caching]]
0 commit comments