Commit 998d188
committed
Add schema inspection support on startup
Prior to this commit, a Spring for GraphQL application could be started
with a schema and an incomplete set of data fetchers, as the schema
would describe:
* Queries/Mutations/Subscriptions that are not backed by any
`@Controller` method, any Spring Data repository nor any custom
`DataFetcher`
* type fields that are not backed by any Java Type property nor any
registered `DataFetcher`
This problem can be noticed at runtime when a request is sent to the
API. The response can contain a `null` field where data was expected, or
even a GraphQL error because the field was non nullable.
This often happens during development time while developers are
implementing the schema.
This commit adds a new `SchemaInspector` type that visits the GraphQL
schema during the startup phase and looks into the `RuntimeWiring` for
registered `DataFetcher` instances. Because data fetchers can be simple
lambdas and do not require to expose a concrete return type, this also
introduces a new `TypedDataFetcher` interface that returns a
`ResolvableType`. This type is only declared by the data fetcher
implementation, but does not necessarily reflects the concrete type
of the returned instances.
This inspection is best effort and has known limitations, such as Union
types (those will not be inspected). Because of those, the inspection
will not fail the application startup.
The `SchemaInspector` collects all missing fields into a report and its
output is logged at startup at the INFO level. As a first step, the
inspector is package private and is only used by the
`DefaultSchemaResourceGraphQlSourceBuilder`. The inspection cannot be
disabled nor customized. We can expand this feature in future releases
as the team collects feedback from the community.
Closes gh-3861 parent 0f9581d commit 998d188
File tree
7 files changed
+930
-9
lines changed- spring-graphql/src
- main/java/org/springframework/graphql
- data
- method/annotation/support
- query
- execution
- test/java/org/springframework/graphql/execution
7 files changed
+930
-9
lines changedLines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
538 | 540 | | |
539 | 541 | | |
540 | 542 | | |
541 | | - | |
| 543 | + | |
542 | 544 | | |
543 | 545 | | |
544 | 546 | | |
| |||
629 | 631 | | |
630 | 632 | | |
631 | 633 | | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
632 | 639 | | |
633 | 640 | | |
634 | 641 | | |
| |||
spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java
Lines changed: 24 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
441 | 442 | | |
442 | 443 | | |
443 | 444 | | |
444 | | - | |
| 445 | + | |
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
| |||
480 | 481 | | |
481 | 482 | | |
482 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
483 | 488 | | |
484 | 489 | | |
485 | 490 | | |
486 | | - | |
| 491 | + | |
487 | 492 | | |
488 | 493 | | |
489 | 494 | | |
| |||
522 | 527 | | |
523 | 528 | | |
524 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
525 | 535 | | |
526 | 536 | | |
527 | 537 | | |
528 | | - | |
| 538 | + | |
529 | 539 | | |
530 | 540 | | |
531 | 541 | | |
| |||
564 | 574 | | |
565 | 575 | | |
566 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
567 | 582 | | |
568 | 583 | | |
569 | 584 | | |
570 | | - | |
| 585 | + | |
571 | 586 | | |
572 | 587 | | |
573 | 588 | | |
| |||
606 | 621 | | |
607 | 622 | | |
608 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
609 | 629 | | |
610 | 630 | | |
611 | 631 | | |
Lines changed: 25 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
538 | 540 | | |
539 | 541 | | |
540 | 542 | | |
541 | | - | |
| 543 | + | |
542 | 544 | | |
543 | 545 | | |
544 | 546 | | |
| |||
581 | 583 | | |
582 | 584 | | |
583 | 585 | | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
584 | 590 | | |
585 | 591 | | |
586 | 592 | | |
587 | | - | |
| 593 | + | |
588 | 594 | | |
589 | 595 | | |
590 | 596 | | |
| |||
625 | 631 | | |
626 | 632 | | |
627 | 633 | | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
628 | 639 | | |
629 | 640 | | |
630 | 641 | | |
631 | | - | |
| 642 | + | |
632 | 643 | | |
633 | 644 | | |
634 | 645 | | |
| |||
670 | 681 | | |
671 | 682 | | |
672 | 683 | | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
673 | 689 | | |
674 | 690 | | |
675 | 691 | | |
676 | | - | |
| 692 | + | |
677 | 693 | | |
678 | 694 | | |
679 | 695 | | |
| |||
715 | 731 | | |
716 | 732 | | |
717 | 733 | | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
718 | 739 | | |
719 | 740 | | |
720 | 741 | | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
142 | 148 | | |
143 | 149 | | |
144 | 150 | | |
| |||
0 commit comments