{"id":471246,"date":"2025-08-19T15:01:02","date_gmt":"2025-08-19T15:01:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=471246"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=471246","title":{"rendered":"<span>\u0413\u0430\u0439\u0434 \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Spring GraphQL. \u0427\u0430\u0441\u0442\u044c 3<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439, \u044f \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 <a href=\"https:\/\/t.me\/it_sense\" rel=\"noopener noreferrer nofollow\">SENSE<\/a> \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 10 \u043b\u0435\u0442 \u043f\u0438\u0448\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430 Java. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f\u00a0\u2014 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0438\u0438 \u0433\u0430\u0439\u0434\u043e\u0432 \u043f\u043e Spring GraphQL, \u0433\u0434\u0435 <a href=\"https:\/\/habr.com\/ru\/companies\/it_sense\/articles\/932054\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u0441 \u043d\u0443\u043b\u044f \u043f\u043e\u0434\u043d\u044f\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 GraphQL \u043a Spring Boot, \u0430 <a href=\"https:\/\/habr.com\/ru\/companies\/it_sense\/articles\/937128\/\" rel=\"noopener noreferrer nofollow\">\u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439<\/a> \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 SchemaMapping, DataLoader \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435: \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 (headers), \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432 \u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432. \u0410 \u0435\u0449\u0451 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0438 union-\u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f GraphQL-\u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h2>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0412\u044b \u0443\u0436\u0435 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043a\u043e\u0441\u043d\u0443\u043b\u0438\u0441\u044c \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u044b \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0445\u0435\u043c\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u00ab!\u00bb \u0432 \u0441\u0445\u0435\u043c\u0443 graphQL. \u041d\u043e \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f?\u00a0<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/p>\n<ol>\n<li>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 jakarta.validation;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 graphQL directive.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\"><strong>Jakarta Validation<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>GraphQL-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>1. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/strong>: Jakarta Validation \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c API \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Java, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 GraphQL.<\/p>\n<\/td>\n<td>\n<p align=\"left\">1. <strong>\u041f\u0440\u044f\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 GraphQL<\/strong>: GraphQL-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e GraphQL-\u0441\u0445\u0435\u043c\u044b, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0432\u0430\u0448\u0438\u0445 GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>2. \u041b\u0435\u0433\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f<\/strong>: Jakarta Validation \u043b\u0435\u0433\u043a\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0432\u043a\u043b\u044e\u0447\u0430\u044f GraphQL.<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>2. \u041b\u0435\u0433\u043a\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/strong>: GraphQL-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430: \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043d\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f Integer.<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Jakarta Validation<\/h2>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u0441\u0442\u0430\u0440\u0442\u0435\u0440:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;    &lt;artifactId&gt;spring-boot-starter-validation&lt;\/artifactId&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"java\">@Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxIntValidator.class) public @interface MaxInt {    int value();    String message() default \"\u041f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\";    Class&lt;?&gt;[] groups() default {};    Class&lt;? extends Payload&gt;[] payload() default {}; }<\/code><\/pre>\n<pre><code class=\"java\">public class MaxIntValidator implements ConstraintValidator&lt;MaxInt, Integer&gt; {     private int max;     @Override    public void initialize(MaxInt maxInt) {        max = maxInt.value();    }     @Override    public boolean isValid(Integer value, ConstraintValidatorContext context) {        return value &lt;= max;    } }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0443:<\/p>\n<pre><code class=\"java\">@QueryMapping public List&lt;Author&gt; getAuthors(@Argument @MaxInt(1) Integer filter) {    return dataBaseService.getAuthors(filter); }<\/code><\/pre>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a:<\/p>\n<pre><code class=\"java\">public class MaxIntDirective implements SchemaDirectiveWiring {     @Override    public GraphQLArgument onArgument(SchemaDirectiveWiringEnvironment&lt;GraphQLArgument&gt; env) {        GraphQLArgument argument = env.getElement();        DataFetcher&lt;?&gt; originalDataFetcher = env.getFieldDataFetcher();         \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b        GraphQLAppliedDirective directive = env.getAppliedDirective();        Integer maxLength = directive.getArgument(\"value\").getValue();         \/\/ \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 DataFetcher        DataFetcher&lt;?&gt; wrappedDataFetcher = dataFetchingEnvironment -&gt; {            Integer argumentValue = dataFetchingEnvironment.getArgument(argument.getName());             \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f            if (argumentValue &gt; maxLength) {                throw new IllegalArgumentException(                        \"\u041f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \" + maxLength);            }             return originalDataFetcher.get(dataFetchingEnvironment);        };         \/\/ \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c DataFetcher        env.setFieldDataFetcher(wrappedDataFetcher);         return argument;    } }<\/code><\/pre>\n<p>\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0435\u0433\u043e \u0432 \u0441\u0445\u0435\u043c\u0435:<\/p>\n<pre><code class=\"java\">@Configuration public class GraphqlExtendedConfig {     @Bean    public RuntimeWiringConfigurer runtimeWiringConfigurer() {        return wiringBuilder -&gt; wiringBuilder                .directive(\"MaxInt\", new MaxIntDirective());    }  }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>directives.graphqls<\/code> \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<pre><code class=\"java\">directive @MaxInt(value: Int!) on ARGUMENT_DEFINITION<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443:<\/p>\n<pre><code class=\"java\">\"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432\" getAuthors(filter: Int @MaxInt(value: 4)): [Author!]!<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u043c\u0438 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 <code>AbstractDirectiveConstraint<\/code>:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;com.graphql-java&lt;\/groupId&gt;    &lt;artifactId&gt;graphql-java-extended-validation&lt;\/artifactId&gt;    &lt;version&gt;${graphql-java.version}&lt;\/version&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0432\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e, \u043d\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441, \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 MaxInt, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"java\">{  \"errors\": [    {      \"message\": \"INTERNAL_ERROR for 7e3b7163-20da-2136-545a-38e1eef5f90e\",      \"locations\": [        {          \"line\": 2,          \"column\": 3        }      ],      \"path\": [        \"getAuthors\"      ],      \"extensions\": {        \"classification\": \"INTERNAL_ERROR\"      }    }  ],  \"data\": null }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>DataFetcherExceptionResolverAdapter<\/code> \u0438 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c <code>GraphQLError<\/code> (\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 graphql-java):<\/p>\n<pre><code class=\"java\">@Component @Slf4j public class CustomExceptionResolver extends DataFetcherExceptionResolverAdapter {     @Override    @SuppressWarnings(value = \"checkstyle:CyclomaticComplexity\")    protected GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env) {       if (ex instanceof ConstraintViolationException                || ex instanceof MyError) {            return createError(ex, env, ValidationError);        } else {            return null;        }    }     private GraphQLError createError(            Throwable ex,            DataFetchingEnvironment env,            ErrorClassification classification) {        log.warn(ex.getMessage());        return GraphqlErrorBuilder.newError()                .errorType(classification)                .extensions(Map.of(\"myField\", \"my text\"))                .message(ex.getMessage())                .path(env.getExecutionStepInfo().getPath())                .location(env.getField().getSourceLocation())                .build();    }  }<\/code><\/pre>\n<p>\u0412 errorType \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.javadoc.io\/static\/com.graphql-java\/graphql-java\/17.6\/graphql\/ErrorType.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.javadoc.io\/static\/com.graphql-java\/graphql-java\/17.6\/graphql\/ErrorType.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/spring-projects\/spring-graphql\/blob\/main\/spring-graphql\/src\/main\/java\/org\/springframework\/graphql\/execution\/ErrorType.java\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/spring-projects\/spring-graphql\/blob\/main\/spring-graphql\/src\/main\/java\/org\/springframework\/graphql\/execution\/ErrorType.java<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <code>enum<\/code>:<\/p>\n<pre><code class=\"java\">public enum CustomErrorType implements ErrorClassification {    MY_ERROR(\"MY_ERROR\"),    MY_ERROR2(\"MY_ERROR2\")     private final String errorClassification;     CustomErrorType(String errorClassification) {        this.errorClassification = errorClassification;    }     @Override    public String toString() {        return errorClassification;    } }<\/code><\/pre>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0438\u0445 \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432<\/h2>\n<blockquote>\n<p>\u0421\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0435 \u0442\u0438\u043f\u044b (Scalar) \u0432 GraphQL \u2014 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430\u00a0\u043d\u0435\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u043b\u0438\u00a0\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u041e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u00ab\u043b\u0438\u0441\u0442\u044c\u044f\u043c\u0438\u00bb \u0432\u00a0GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0442.\u0435. \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<\/blockquote>\n<p>\u041f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0439\u0442\u0435 <code>id<\/code> \u0430\u0432\u0442\u043e\u0440\u0430 \u043d\u0430 <code>uuid<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0445\u0435\u043c\u0430 graphQL \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u0438 \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;com.graphql-java&lt;\/groupId&gt;    &lt;artifactId&gt;graphql-java-extended-scalars&lt;\/artifactId&gt;    &lt;version&gt;22.0&lt;\/version&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0435\u0433\u043e:<\/p>\n<pre><code class=\"java\">@Bean public RuntimeWiringConfigurer runtimeWiringConfigurer() {    return wiringBuilder -&gt; wiringBuilder            .directive(\"MaxInt\", new MaxIntDirective())            .scalar(ExtendedScalars.UUID); }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"java\">scalar UUID<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432 \u0442\u0438\u043f\u0435:<\/p>\n<pre><code class=\"java\">\"\u0410\u0432\u0442\u043e\u0440\" type Author {    \"id \u0430\u0432\u0442\u043e\u0440\u0430\"    id: UUID!    \"\u0418\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    name: String!    \"\u0424\u0430\u043c\u0438\u043b\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    surname: String!    \"\u0414\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    birthday: String!    \"\u041a\u043d\u0438\u0433\u0438 \u0430\u0432\u0442\u043e\u0440\u0430\"    books(id: Int): [Book!]! }<\/code><\/pre>\n<pre><code class=\"java\">type Query {    helloWorld(text: String!): String!    \"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432\"    getAuthors(filter: UUID): [Author!]! }<\/code><\/pre>\n<p>\u041f\u043e\u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<pre><code class=\"java\">@QueryMapping public List&lt;Author&gt; getAuthors(@Argument UUID filter) {    return dataBaseService.getAuthors(filter); }<\/code><\/pre>\n<p>\u0421\u043a\u0430\u043b\u044f\u0440 UUID \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435 \u043d\u0435 uuid:<\/p>\n<pre><code class=\"java\">{  \"errors\": [    {      \"message\": \"Validation error (WrongType@[getAuthors]) : argument 'filter' with value 'StringValue{value='215697a7-e4f7-4030-b158'}' is not a valid 'UUID' - Expected something that we can convert to a UUID but was invalid\",      \"locations\": [        {          \"line\": 2,          \"column\": 14        }      ],      \"extensions\": {        \"classification\": \"ValidationError\"      }    }  ] }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0432\u043e\u0439 \u0441\u043a\u0430\u043b\u044f\u0440.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043a\u0430\u043b\u044f\u0440\u0430 \u0434\u0430\u0442\u044b:<\/p>\n<pre><code class=\"java\">@Slf4j public class InstantCoercing implements Coercing&lt;Instant, String&gt; {     private static final String EXCEPTION_MESSAGE = \"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 ISO-8601 UTC\";     @Override    public String serialize(Object dataFetcherResult, GraphQLContext graphQLContext, Locale locale)            throws CoercingSerializeException {        return dataFetcherResult.toString();    }     @Override    public Instant parseLiteral(Value&lt;?&gt; input, CoercedVariables variables, GraphQLContext context, Locale locale)            throws CoercingParseLiteralException {        try {            if (input instanceof StringValue stringValue) {                return Instant.parse(stringValue.getValue());            } else {                throw createException();            }        } catch (CoercingParseLiteralException e) {            throw e;        } catch (Exception e) {            log.warn(\"Problem with parse Instant from %s\".formatted(input), e);            throw createException();        }    }     @Override    public Value&lt;?&gt; valueToLiteral(Object input, GraphQLContext graphQLContext, Locale locale) {        return GraphQLString.getCoercing().valueToLiteral(input, graphQLContext, locale);    }     private CoercingParseLiteralException createException() {        return new CoercingParseLiteralException(EXCEPTION_MESSAGE);    } }<\/code><\/pre>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"java\">@Bean public RuntimeWiringConfigurer runtimeWiringConfigurer() {    return wiringBuilder -&gt; wiringBuilder            .directive(\"MaxInt\", new MaxIntDirective())            .scalar(ExtendedScalars.UUID)            .scalar(                    GraphQLScalarType.newScalar()                            .name(\"DateTime\")                            .description(\"Represents date and time at UTC\")                            .coercing(new InstantCoercing())                            .build()); }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"java\">scalar DateTime<\/code><\/pre>\n<h2>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 header \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/h2>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0435 header \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0445 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>WebGraphQlInterceptor<\/code>:<\/p>\n<pre><code class=\"java\">@Component @RequiredArgsConstructor @Slf4j public class RequestGraphQLHeaderInterceptor implements WebGraphQlInterceptor {     @Override    public Mono&lt;WebGraphQlResponse&gt; intercept(WebGraphQlRequest request, Chain chain) {        Map&lt;String, Object&gt; context = new HashMap&lt;&gt;();        request.getHeaders().forEach((key, value) -&gt; {            switch (key.toLowerCase()) {                case \"test\":                    context.put(key.toLowerCase(), value.getFirst());                    break;                default:                    break;            }         });         if (!context.isEmpty()) {            request.configureExecutionInput((executionInput, builder) -&gt;                    builder.graphQLContext(context).build());        }        return chain.next(request);    } }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e header \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"java\">@QueryMapping public List&lt;Author&gt; getAuthors(        @Argument UUID filter,        @ContextValue(required = true, name = \"test\")        String myHeader) {    return dataBaseService.getAuthors(filter); }<\/code><\/pre>\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 header<\/h2>\n<p>\u0412\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 graphQlTester \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u043d\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0442\u0435\u0441\u0442\u0435\u0440 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"java\">@Autowired private WebApplicationContext context;  WebTestClient client;  HttpGraphQlTester testerGraphQlWithHeader;  @PostConstruct void init() {    client = MockMvcWebTestClient.bindToApplicationContext(context)            .configureClient()            .baseUrl(\"\/graphql\")            .build();     testerGraphQlWithHeader = HttpGraphQlTester.create(client)            .mutate().header(\"test\", \"myValue\")            .build(); }  @Autowired protected GraphQlTester graphQlTester; @Test void queryWithHeader() {    String query = \"\"\"                query MyQuery {                  getAuthors{                    id                  }                }            \"\"\";     List&lt;Author&gt; authors = testerGraphQlWithHeader.document(query).execute()            .path(\"getAuthors\").entityList(Author.class).get();    assertThat(authors).isNotEmpty(); }  @Test void queryWithoutHeader() {    String query = \"\"\"                query MyQuery {                  getAuthors{                    id                  }                }            \"\"\";     graphQlTester.document(query).execute()            .errors().expect(e -&gt; e.getErrorType().equals(INTERNAL_ERROR)); }<\/code><\/pre>\n<h2>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438 union-\u0442\u0438\u043f\u044b<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0434\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u043d\u043e \u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u0441\u0445\u0435\u043c\u0443 graphQL \u0442\u0438\u043f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u0435 \u0435\u0433\u043e \u0441 \u0442\u0438\u043f\u043e\u043c \u0430\u0432\u0442\u043e\u0440\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c:<\/p>\n<pre><code class=\"java\">type Query {    helloWorld(text: String!): String!    \"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432\"    getAuthors(filter: UUID): [Author!]!    getPeople: [Person!]! }  interface Person {    id: UUID!    name: String!    surname: String! }  type Reader implements Person{    id: UUID!,    name: String!,    surname: String! }  \"\u0410\u0432\u0442\u043e\u0440\" type Author implements Person{    \"id \u0430\u0432\u0442\u043e\u0440\u0430\"    id: UUID!    \"\u0418\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    name: String!    \"\u0424\u0430\u043c\u0438\u043b\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    surname: String!    \"\u0414\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    birthday: String!    \"\u041a\u043d\u0438\u0433\u0438 \u0430\u0432\u0442\u043e\u0440\u0430\"    books(id: Int): [Book!]! }<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"java\">public interface Person { }<\/code><\/pre>\n<pre><code class=\"java\">public record Reader (        UUID id,        String name,        String surname ) implements Person { }<\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0437\u0430\u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0432 Author.<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435:<\/p>\n<pre><code class=\"java\">@QueryMapping public List&lt;Person&gt; getPeople(){    return dataBaseService.getPersons(); }<\/code><\/pre>\n<p>Union \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435. \u041e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 \u0441\u0445\u0435\u043c\u0435<\/p>\n<pre><code class=\"java\">union Person = Reader | Author<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435\u0442. \u041d\u043e \u043e\u0431\u044b\u0447\u043d\u043e union \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0442\u0438\u043f\u044b, \u0430 interface \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435.<\/p>\n<h2>\u041a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c client graphql<\/h2>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;    &lt;artifactId&gt;spring-boot-starter-webflux&lt;\/artifactId&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0421\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<pre><code class=\"java\">import java.util.List; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.graphql.client.HttpGraphQlClient; import org.springframework.graphql.support.CachingDocumentSource; import org.springframework.graphql.support.DocumentSource; import org.springframework.graphql.support.ResourceDocumentSource; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.web.reactive.function.client.WebClient; import reactor.netty.http.client.HttpClient;   @Configuration public class GraphQLClientConfiguration {     private final String graphQlURI = \"http:\/\/localhost:8080\/graphql\";     @Bean    public HttpGraphQlClient testHttpGraphQlClient(WebClient testWebClient,                                                              DocumentSource testDocumentSource) {        return HttpGraphQlClient.builder(testWebClient)                .documentSource(testDocumentSource)                .build();    }     @Bean    public WebClient testWebClient(HttpClient httpClient) {        return WebClient.builder()                .baseUrl(graphQlURI)                .defaultHeader(\"test\", \"test\")                .clientConnector(new ReactorClientHttpConnector(httpClient))                .build();    }     @Bean    public DocumentSource testDocumentSource() {        return new CachingDocumentSource(                new ResourceDocumentSource(                        List.of(new ClassPathResource(\"graphql-templates\/test\/\")),                        ResourceDocumentSource.FILE_EXTENSIONS));    }     @Bean    public HttpClient httpClient() {        return HttpClient.create();    } }<\/code><\/pre>\n<p>\u0412 ClassPathResource \u0443\u043a\u0430\u0436\u0438\u0442\u0435 \u043f\u0443\u0442\u044c \u043a \u043f\u0430\u043f\u043a\u0435 \u0441 template \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432,\u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 header, \u0442. \u043a. \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043d \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 template: testFile.graphql (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0442\u0438\u043f \u0431\u0435\u0437 \u00abs\u00bb):<\/p>\n<pre><code class=\"java\">query MyQuery($inp: UUID) {    getAuthors(filter: $inp) {        id    } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<pre><code class=\"java\">@Component @RequiredArgsConstructor public class GraphQLClient {     private final HttpGraphQlClient testHttpGraphQlClient;     public List&lt;Author&gt; test(UUID uuid) {        return testHttpGraphQlClient.documentName(\"testFile\")                .variable(\"inp\", uuid)                .retrieve(\"getAuthors\")                .toEntityList(Author.class)                .block();    } }<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u043a\u043e\u043d\u0446\u0443 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e Spring GraphQL\u00a0\u2014 \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0438 \u0433\u0438\u0431\u043a\u043e\u0433\u043e API, \u0430 \u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441\u043e Spring-\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0439.<\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u0435 \u043c\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u0443\u0442\u044c \u043e\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0434\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e API: \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u0438 DataLoader, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043a\u0430\u043b\u044f\u0440\u044b \u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0438 union-\u0442\u0438\u043f\u0430\u043c\u0438. \u0410 \u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f GraphQL. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0435\u0440\u0438\u044f \u0433\u0430\u0439\u0434\u043e\u0432 \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u0442\u044c \u0441 GraphQL \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p><strong>P.S. <\/strong>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442.\u00a0\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u0438 \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0442\u0435\u043c\u044b \u043f\u043e Java, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445\u00a0\u2014 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0432\u044b\u0431\u0435\u0440\u0435\u043c, \u0447\u0442\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/938600\/\"> https:\/\/habr.com\/ru\/articles\/938600\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439, \u044f \u0431\u044d\u043a\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 <a href=\"https:\/\/t.me\/it_sense\" rel=\"noopener noreferrer nofollow\">SENSE<\/a> \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 10 \u043b\u0435\u0442 \u043f\u0438\u0448\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430 Java. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f\u00a0\u2014 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0438\u0438 \u0433\u0430\u0439\u0434\u043e\u0432 \u043f\u043e Spring GraphQL, \u0433\u0434\u0435 <a href=\"https:\/\/habr.com\/ru\/companies\/it_sense\/articles\/932054\/\" rel=\"noopener noreferrer nofollow\">\u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u0441 \u043d\u0443\u043b\u044f \u043f\u043e\u0434\u043d\u044f\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 GraphQL \u043a Spring Boot, \u0430 <a href=\"https:\/\/habr.com\/ru\/companies\/it_sense\/articles\/937128\/\" rel=\"noopener noreferrer nofollow\">\u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439<\/a> \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0441 SchemaMapping, DataLoader \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0434\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435: \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 (headers), \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432 \u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432. \u0410 \u0435\u0449\u0451 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u0438 union-\u0442\u0438\u043f\u0430\u043c\u0438 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f GraphQL-\u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h2>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0412\u044b \u0443\u0436\u0435 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043a\u043e\u0441\u043d\u0443\u043b\u0438\u0441\u044c \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u044b \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0445\u0435\u043c\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u00ab!\u00bb \u0432 \u0441\u0445\u0435\u043c\u0443 graphQL. \u041d\u043e \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f?\u00a0<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/p>\n<ol>\n<li>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 jakarta.validation;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 graphQL directive.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\"><strong>Jakarta Validation<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>GraphQL-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>1. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/strong>: Jakarta Validation \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c API \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Java, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 GraphQL.<\/p>\n<\/td>\n<td>\n<p align=\"left\">1. <strong>\u041f\u0440\u044f\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 GraphQL<\/strong>: GraphQL-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e GraphQL-\u0441\u0445\u0435\u043c\u044b, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0432\u0430\u0448\u0438\u0445 GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>2. \u041b\u0435\u0433\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f<\/strong>: Jakarta Validation \u043b\u0435\u0433\u043a\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0432\u043a\u043b\u044e\u0447\u0430\u044f GraphQL.<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>2. \u041b\u0435\u0433\u043a\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/strong>: GraphQL-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430: \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043d\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f Integer.<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Jakarta Validation<\/h2>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435 \u0441\u0442\u0430\u0440\u0442\u0435\u0440:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;    &lt;artifactId&gt;spring-boot-starter-validation&lt;\/artifactId&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"java\">@Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = MaxIntValidator.class) public @interface MaxInt {    int value();    String message() default \"\u041f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\";    Class&lt;?&gt;[] groups() default {};    Class&lt;? extends Payload&gt;[] payload() default {}; }<\/code><\/pre>\n<pre><code class=\"java\">public class MaxIntValidator implements ConstraintValidator&lt;MaxInt, Integer&gt; {     private int max;     @Override    public void initialize(MaxInt maxInt) {        max = maxInt.value();    }     @Override    public boolean isValid(Integer value, ConstraintValidatorContext context) {        return value &lt;= max;    } }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0443:<\/p>\n<pre><code class=\"java\">@QueryMapping public List&lt;Author&gt; getAuthors(@Argument @MaxInt(1) Integer filter) {    return dataBaseService.getAuthors(filter); }<\/code><\/pre>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a:<\/p>\n<pre><code class=\"java\">public class MaxIntDirective implements SchemaDirectiveWiring {     @Override    public GraphQLArgument onArgument(SchemaDirectiveWiringEnvironment&lt;GraphQLArgument&gt; env) {        GraphQLArgument argument = env.getElement();        DataFetcher&lt;?&gt; originalDataFetcher = env.getFieldDataFetcher();         \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b        GraphQLAppliedDirective directive = env.getAppliedDirective();        Integer maxLength = directive.getArgument(\"value\").getValue();         \/\/ \u041e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 DataFetcher        DataFetcher&lt;?&gt; wrappedDataFetcher = dataFetchingEnvironment -&gt; {            Integer argumentValue = dataFetchingEnvironment.getArgument(argument.getName());             \/\/ \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f            if (argumentValue &gt; maxLength) {                throw new IllegalArgumentException(                        \"\u041f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \" + maxLength);            }             return originalDataFetcher.get(dataFetchingEnvironment);        };         \/\/ \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c DataFetcher        env.setFieldDataFetcher(wrappedDataFetcher);         return argument;    } }<\/code><\/pre>\n<p>\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0435\u0433\u043e \u0432 \u0441\u0445\u0435\u043c\u0435:<\/p>\n<pre><code class=\"java\">@Configuration public class GraphqlExtendedConfig {     @Bean    public RuntimeWiringConfigurer runtimeWiringConfigurer() {        return wiringBuilder -&gt; wiringBuilder                .directive(\"MaxInt\", new MaxIntDirective());    }  }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>directives.graphqls<\/code> \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<pre><code class=\"java\">directive @MaxInt(value: Int!) on ARGUMENT_DEFINITION<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443:<\/p>\n<pre><code class=\"java\">\"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432\" getAuthors(filter: Int @MaxInt(value: 4)): [Author!]!<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u043c\u0438 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 <code>AbstractDirectiveConstraint<\/code>:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;com.graphql-java&lt;\/groupId&gt;    &lt;artifactId&gt;graphql-java-extended-validation&lt;\/artifactId&gt;    &lt;version&gt;${graphql-java.version}&lt;\/version&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0432\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e, \u043d\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441, \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 MaxInt, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"java\">{  \"errors\": [    {      \"message\": \"INTERNAL_ERROR for 7e3b7163-20da-2136-545a-38e1eef5f90e\",      \"locations\": [        {          \"line\": 2,          \"column\": 3        }      ],      \"path\": [        \"getAuthors\"      ],      \"extensions\": {        \"classification\": \"INTERNAL_ERROR\"      }    }  ],  \"data\": null }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>DataFetcherExceptionResolverAdapter<\/code> \u0438 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c <code>GraphQLError<\/code> (\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 graphql-java):<\/p>\n<pre><code class=\"java\">@Component @Slf4j public class CustomExceptionResolver extends DataFetcherExceptionResolverAdapter {     @Override    @SuppressWarnings(value = \"checkstyle:CyclomaticComplexity\")    protected GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env) {       if (ex instanceof ConstraintViolationException                || ex instanceof MyError) {            return createError(ex, env, ValidationError);        } else {            return null;        }    }     private GraphQLError createError(            Throwable ex,            DataFetchingEnvironment env,            ErrorClassification classification) {        log.warn(ex.getMessage());        return GraphqlErrorBuilder.newError()                .errorType(classification)                .extensions(Map.of(\"myField\", \"my text\"))                .message(ex.getMessage())                .path(env.getExecutionStepInfo().getPath())                .location(env.getField().getSourceLocation())                .build();    }  }<\/code><\/pre>\n<p>\u0412 errorType \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/www.javadoc.io\/static\/com.graphql-java\/graphql-java\/17.6\/graphql\/ErrorType.html\" rel=\"noopener noreferrer nofollow\">https:\/\/www.javadoc.io\/static\/com.graphql-java\/graphql-java\/17.6\/graphql\/ErrorType.html<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/spring-projects\/spring-graphql\/blob\/main\/spring-graphql\/src\/main\/java\/org\/springframework\/graphql\/execution\/ErrorType.java\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/spring-projects\/spring-graphql\/blob\/main\/spring-graphql\/src\/main\/java\/org\/springframework\/graphql\/execution\/ErrorType.java<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <code>enum<\/code>:<\/p>\n<pre><code class=\"java\">public enum CustomErrorType implements ErrorClassification {    MY_ERROR(\"MY_ERROR\"),    MY_ERROR2(\"MY_ERROR2\")     private final String errorClassification;     CustomErrorType(String errorClassification) {        this.errorClassification = errorClassification;    }     @Override    public String toString() {        return errorClassification;    } }<\/code><\/pre>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0438\u0445 \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432<\/h2>\n<blockquote>\n<p>\u0421\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0435 \u0442\u0438\u043f\u044b (Scalar) \u0432 GraphQL \u2014 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430\u00a0\u043d\u0435\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u043b\u0438\u00a0\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u041e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u00ab\u043b\u0438\u0441\u0442\u044c\u044f\u043c\u0438\u00bb \u0432\u00a0GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u0442.\u0435. \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<\/blockquote>\n<p>\u041f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0439\u0442\u0435 <code>id<\/code> \u0430\u0432\u0442\u043e\u0440\u0430 \u043d\u0430 <code>uuid<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0445\u0435\u043c\u0430 graphQL \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u0438 \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt;    &lt;groupId&gt;com.graphql-java&lt;\/groupId&gt;    &lt;artifactId&gt;graphql-java-extended-scalars&lt;\/artifactId&gt;    &lt;version&gt;22.0&lt;\/version&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<p>\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435 \u0435\u0433\u043e:<\/p>\n<pre><code class=\"java\">@Bean public RuntimeWiringConfigurer runtimeWiringConfigurer() {    return wiringBuilder -&gt; wiringBuilder            .directive(\"MaxInt\", new MaxIntDirective())            .scalar(ExtendedScalars.UUID); }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"java\">scalar UUID<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432 \u0442\u0438\u043f\u0435:<\/p>\n<pre><code class=\"java\">\"\u0410\u0432\u0442\u043e\u0440\" type Author {    \"id \u0430\u0432\u0442\u043e\u0440\u0430\"    id: UUID!    \"\u0418\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    name: String!    \"\u0424\u0430\u043c\u0438\u043b\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    surname: String!    \"\u0414\u0435\u043d\u044c \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430\"    birthday: String!    \"\u041a\u043d\u0438\u0433\u0438 \u0430\u0432\u0442\u043e\u0440\u0430\"    books(id: Int): [Book!]! }<\/code><\/pre>\n<pre><code class=\"java\">type Query {    helloWorld(text: String!): String!    \"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u0430\u0432\u0442\u043e\u0440\u043e\u0432\"    getAuthors(filter: UUID): [Author!]! }<\/code><\/pre>\n<p>\u041f\u043e\u043f\u0440\u0430\u0432\u044c\u0442\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<pre><code class=\"java\">@QueryMapping public List&lt;Author&gt; getAuthors(@Argument UUID filter) {    return dataBaseService.getAuthors(filter); }<\/code><\/pre>\n<p>\u0421\u043a\u0430\u043b\u044f\u0440 UUID \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u0435 \u043d\u0435 uuid:<\/p>\n<pre><code class=\"java\">{  \"errors\": [    {      \"message\": \"Validation error (WrongType@[getAuthors]) : argument 'filter' with value 'StringValue{value='215697a7-e4f7-4030-b158'}' is not a valid 'UUID' - Expected something that we can convert to a UUID but was invalid\",      \"locations\": [        {          \"line\": 2,          \"column\": 14        }      ],      \"extensions\": {        \"classification\": \"ValidationError\"      }    }  ] }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0432\u043e\u0439 \u0441\u043a\u0430\u043b\u044f\u0440.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043a\u0430\u043b\u044f\u0440\u0430 \u0434\u0430\u0442\u044b:<\/p>\n<pre><code class=\"java\">@Slf4j public class InstantCoercing implements Coercing&lt;Instant, String&gt; {     private static final String EXCEPTION_MESSAGE = \"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 ISO-8601 UTC\";     @Override    public String serialize(Object dataFetcherResult, GraphQLContext graphQLContext, Locale locale)            throws CoercingSerializeException {        return dataFetcherResult.toString();    }     @Override    public Instant parseLiteral(Value&lt;?&gt; input, CoercedVariables variables, GraphQLContext context, Locale locale)            throws CoercingParseLiteralException {        try {            if (input instanceof StringValue stringValue) {                return Instant.parse(stringValue.getValue());            } else {                throw createException();            }        } catch (CoercingParseLiteralException e) {            throw e;        } catch (Exception e) {            log.warn(\"Problem with parse Instant from %s\".formatted(input), e);            throw createException();        }    }     @Override    public Value&lt;?&gt; valueToLiteral(Object input, GraphQLContext graphQLContext, Locale locale) {        return GraphQLString.getCoercing().valueToLiteral(input, graphQLContext, locale);    }     private CoercingParseLiteralException createException() {        return new<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-471246","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/471246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471246"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/471246\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=471246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=471246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}