{"id":390432,"date":"2024-06-29T09:14:27","date_gmt":"2024-06-29T09:14:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=390432"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=390432","title":{"rendered":"<span>GraphQL + SPQR + Spring Boot Starter 2021<\/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><strong>GraphQL<\/strong> \u2014 \u044d\u0442\u043e \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c. \u041e\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u043c\u043e\u0433 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e. GraphQL <strong>SPQR<\/strong> \u043f\u0440\u0438\u0437\u0432\u0430\u043d \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 GraphQL API \u0432\u00a0<em>\u043b\u044e\u0431\u043e\u0439<\/em>\u00a0Java-\u043f\u0440\u043e\u0435\u043a\u0442.\u00a0SPQR \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u0441\u0445\u0435\u043c\u0443 GraphQL \u0438\u0437 \u043a\u043e\u0434\u0430 Java, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0442\u0438!  <\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \/ \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0432\u0430\u0448 maven \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code>&lt;dependency>     &lt;groupId>io.leangen.graphql&lt;\/groupId>     &lt;artifactId>graphql-spqr-spring-boot-starter&lt;\/artifactId>     &lt;version>0.0.6&lt;\/version> &lt;\/dependency> &lt;dependency>     &lt;groupId>com.graphql-java&lt;\/groupId>     &lt;artifactId>graphiql-spring-boot-starter&lt;\/artifactId>     &lt;version>5.0.2&lt;\/version> &lt;\/dependency><\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b\u00a0<code>SpqrAutoConfiguration<\/code>\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445\u00a0<code>ResolverBuilder<\/code>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><code>AnnotatedResolverBuilder<\/code>&#8212; \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435\u00a0<code>@GraphQLQuery<\/code>,\u00a0<code>@GraphQLMutation<\/code>\u0438\u043b\u0438<code>@GraphQLSubscription<\/code><\/p>\n<\/li>\n<li>\n<p><code>PublicResolverBuilder<\/code>&#8212; \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u00a0<code>public<\/code>\u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b\u00a0<code>void<\/code>\u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u044f\u043c\u0438)<\/p>\n<\/li>\n<li>\n<p><code>BeanResolverBuilder<\/code>&#8212; \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b \u043a\u0430\u043a \u043c\u0443\u0442\u0430\u0446\u0438\u0438 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u044b\u00a0<code>Publisher&lt;T><\/code>\u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430\u043c\u0438)<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0441\u0432\u043e\u0439\u00a0<strong>ResolverBuilder <\/strong>\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 SPQR<\/h2>\n<p><a class=\"mention\" href=\"\/users\/graphqlapi\">@GraphQLApi<\/a>&#8212; \u0430\u043d\u0430\u043b\u043e\u0433 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b Query \u0438 Mutation.<\/p>\n<p><a class=\"mention\" href=\"\/users\/graphqlquery\">@GraphQLQuery<\/a> &#8212; QUERY, \u0430\u043d\u0430\u043b\u043e\u0433 read \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<p><a class=\"mention\" href=\"\/users\/graphqlmutation\">@GraphQLMutation<\/a>&#8212; MUTATION, \u0430\u043d\u0430\u043b\u043e\u0433 create\/delete\/update \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0438\u0436\u0435.<\/p>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u043d\u043a\u043e\u0432\u0441\u043a\u0438\u0439 \u0441\u0447\u0435\u0442 \u0438\u043c\u0435\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u0441\u0447\u0435\u0442\u0430 (numberAccount), \u0432\u0430\u043b\u044e\u0442\u0443 (currency) \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0447\u0435\u0442 (balance).<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"bank_account\") @FieldDefaults(level = AccessLevel.PRIVATE) @NoArgsConstructor public class BankAccountEntity {     @Id     String numberAccount;          Currency currency;      BigDecimal balance; } <\/code><\/pre>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c dto \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e:<\/p>\n<pre><code class=\"java\">@Getter @Setter @FieldDefaults(level = AccessLevel.PRIVATE) public class BankAccountDto {     @GraphQLId     String numberAccount;      @NotNull     @GraphQLScalar     @GraphQLInputField     Currency currency;      @NotNull     @GraphQLInputField     BigDecimal balance; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <a class=\"mention\" href=\"\/users\/graphqlinputfield\">@GraphQLInputField<\/a> \u0433\u043e\u0432\u043e\u0440\u0438\u0442 GraphQL, \u0447\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043f\u043e\u043b\u0435 \u0431\u0443\u0434\u0435\u0442  \u043f\u043e\u043b\u0435\u043c \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0432\u0432\u043e\u0434\u0430. \u041f\u043e\u043f\u0440\u043e\u0448\u0443 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u043f\u043e\u043b\u044f currency \u0441\u0442\u043e\u0438\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <a class=\"mention\" href=\"\/users\/graphqlscalar\">@GraphQLScalar<\/a> &#8212;  \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0441\u043a\u0430\u043b\u044f\u0440. <\/p>\n<pre><code class=\"java\">package ru.bank.web.dataFetcher;  import io.leangen.graphql.annotations.GraphQLArgument; import io.leangen.graphql.annotations.GraphQLMutation; import io.leangen.graphql.annotations.GraphQLNonNull; import io.leangen.graphql.annotations.GraphQLQuery; import io.leangen.graphql.spqr.spring.annotations.GraphQLApi; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; import ru.bank.business.service.BankAccountService; import ru.bank.web.dto.BankAccountDto; import ru.bank.web.dto.DispatchMoneyDto;  import java.util.List;  @RequiredArgsConstructor @Component @GraphQLApi public class BankAccountDataFetcher {     private final BankAccountService service;      @GraphQLQuery(name = \"getAllBalance\")     public List&lt;BankAccountDto> getAll(@GraphQLArgument(name = \"page\")Pageable pageable) {         return service.getAll(pageable);     }      @GraphQLMutation(name = \"createBankAccount\", description = \"create a new bank account\")     public BankAccountDto createBankAccount(@GraphQLArgument(name = \"createBankAccountInput\") @GraphQLNonNull BankAccountDto bankAccount) {         return service.create(bankAccount);     }      @GraphQLMutation(name = \"dispatchMoney\", description = \"dispatch money\")     public void dispatchMoney(@GraphQLArgument(name = \"createDispatchMoneyInput\") @GraphQLNonNull DispatchMoneyDto dispatchMoneyDto) {         service.dispatchMoney(dispatchMoneyDto);     }      @GraphQLMutation(name = \"removeBankAccount\", description = \"remove bank account\")     public void removeBankAccount(@GraphQLNonNull String numberAccount) {         service.remove(numberAccount);     } } <\/code><\/pre>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <a class=\"mention\" href=\"\/users\/graphqlmutation\">@GraphQLMutation<\/a> name &#8212; \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f GraphQL, \u0430 description &#8212; \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f graphiql<\/p>\n<h2>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/241\/f94\/4c2\/241f944c2410f02e50e8e497e85971e9.png\" alt=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Query \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\u043c\" title=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Query \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\u043c\" width=\"1890\" height=\"682\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/241\/f94\/4c2\/241f944c2410f02e50e8e497e85971e9.png\"\/><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Query \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\u043c<\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4c8\/98a\/da7\/4c898ada7815adfca2c8bc9f8af2c256.png\" alt=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e \u043a\u043b\u044e\u0447\u0443\" title=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e \u043a\u043b\u044e\u0447\u0443\" width=\"1672\" height=\"374\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c8\/98a\/da7\/4c898ada7815adfca2c8bc9f8af2c256.png\"\/><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3bf\/12b\/407\/3bf12b407eab4777148fde00cd590608.png\" alt=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\" title=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\" width=\"1556\" height=\"408\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3bf\/12b\/407\/3bf12b407eab4777148fde00cd590608.png\"\/><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430<\/figcaption><\/figure>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435: <a href=\"https:\/\/github.com\/gibkin\/graphql-sqpr-spring-boot-starter\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/gibkin\/graphql-sqpr-spring-boot-starter<\/a><\/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\/594335\/\"> https:\/\/habr.com\/ru\/articles\/594335\/<\/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><strong>GraphQL<\/strong> \u2014 \u044d\u0442\u043e \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c. \u041e\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u043c\u043e\u0433 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e. GraphQL <strong>SPQR<\/strong> \u043f\u0440\u0438\u0437\u0432\u0430\u043d \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 GraphQL API \u0432\u00a0<em>\u043b\u044e\u0431\u043e\u0439<\/em>\u00a0Java-\u043f\u0440\u043e\u0435\u043a\u0442.\u00a0SPQR \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044f \u0441\u0445\u0435\u043c\u0443 GraphQL \u0438\u0437 \u043a\u043e\u0434\u0430 Java, \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439. \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0442\u0438!  <\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \/ \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0432\u0430\u0448 maven \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code>&lt;dependency>     &lt;groupId>io.leangen.graphql&lt;\/groupId>     &lt;artifactId>graphql-spqr-spring-boot-starter&lt;\/artifactId>     &lt;version>0.0.6&lt;\/version> &lt;\/dependency> &lt;dependency>     &lt;groupId>com.graphql-java&lt;\/groupId>     &lt;artifactId>graphiql-spring-boot-starter&lt;\/artifactId>     &lt;version>5.0.2&lt;\/version> &lt;\/dependency><\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b\u00a0<code>SpqrAutoConfiguration<\/code>\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0442\u0440\u0435\u0445 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445\u00a0<code>ResolverBuilder<\/code>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><code>AnnotatedResolverBuilder<\/code>&#8212; \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435\u00a0<code>@GraphQLQuery<\/code>,\u00a0<code>@GraphQLMutation<\/code>\u0438\u043b\u0438<code>@GraphQLSubscription<\/code><\/p>\n<\/li>\n<li>\n<p><code>PublicResolverBuilder<\/code>&#8212; \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u00a0<code>public<\/code>\u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b\u00a0<code>void<\/code>\u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u044f\u043c\u0438)<\/p>\n<\/li>\n<li>\n<p><code>BeanResolverBuilder<\/code>&#8212; \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b \u043a\u0430\u043a \u043c\u0443\u0442\u0430\u0446\u0438\u0438 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u044b\u00a0<code>Publisher&lt;T><\/code>\u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430\u043c\u0438)<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u0441\u0432\u043e\u0439\u00a0<strong>ResolverBuilder <\/strong>\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 SPQR<\/h2>\n<p><a class=\"mention\" href=\"\/users\/graphqlapi\">@GraphQLApi<\/a>&#8212; \u0430\u043d\u0430\u043b\u043e\u0433 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b Query \u0438 Mutation.<\/p>\n<p><a class=\"mention\" href=\"\/users\/graphqlquery\">@GraphQLQuery<\/a> &#8212; QUERY, \u0430\u043d\u0430\u043b\u043e\u0433 read \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<p><a class=\"mention\" href=\"\/users\/graphqlmutation\">@GraphQLMutation<\/a>&#8212; MUTATION, \u0430\u043d\u0430\u043b\u043e\u0433 create\/delete\/update \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0438\u0436\u0435.<\/p>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0421\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u043d\u043a\u043e\u0432\u0441\u043a\u0438\u0439 \u0441\u0447\u0435\u0442 \u0438\u043c\u0435\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u0441\u0447\u0435\u0442\u0430 (numberAccount), \u0432\u0430\u043b\u044e\u0442\u0443 (currency) \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0447\u0435\u0442 (balance).<\/p>\n<pre><code class=\"java\">@Getter @Setter @Entity @Table(name = \"bank_account\") @FieldDefaults(level = AccessLevel.PRIVATE) @NoArgsConstructor public class BankAccountEntity {     @Id     String numberAccount;          Currency currency;      BigDecimal balance; } <\/code><\/pre>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c dto \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e:<\/p>\n<pre><code class=\"java\">@Getter @Setter @FieldDefaults(level = AccessLevel.PRIVATE) public class BankAccountDto {     @GraphQLId     String numberAccount;      @NotNull     @GraphQLScalar     @GraphQLInputField     Currency currency;      @NotNull     @GraphQLInputField     BigDecimal balance; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <a class=\"mention\" href=\"\/users\/graphqlinputfield\">@GraphQLInputField<\/a> \u0433\u043e\u0432\u043e\u0440\u0438\u0442 GraphQL, \u0447\u0442\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043f\u043e\u043b\u0435 \u0431\u0443\u0434\u0435\u0442  \u043f\u043e\u043b\u0435\u043c \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0432\u0432\u043e\u0434\u0430. \u041f\u043e\u043f\u0440\u043e\u0448\u0443 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u043f\u043e\u043b\u044f currency \u0441\u0442\u043e\u0438\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <a class=\"mention\" href=\"\/users\/graphqlscalar\">@GraphQLScalar<\/a> &#8212;  \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0441\u043a\u0430\u043b\u044f\u0440. <\/p>\n<pre><code class=\"java\">package ru.bank.web.dataFetcher;  import io.leangen.graphql.annotations.GraphQLArgument; import io.leangen.graphql.annotations.GraphQLMutation; import io.leangen.graphql.annotations.GraphQLNonNull; import io.leangen.graphql.annotations.GraphQLQuery; import io.leangen.graphql.spqr.spring.annotations.GraphQLApi; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; import ru.bank.business.service.BankAccountService; import ru.bank.web.dto.BankAccountDto; import ru.bank.web.dto.DispatchMoneyDto;  import java.util.List;  @RequiredArgsConstructor @Component @GraphQLApi public class BankAccountDataFetcher {     private final BankAccountService service;      @GraphQLQuery(name = \"getAllBalance\")     public List&lt;BankAccountDto> getAll(@GraphQLArgument(name = \"page\")Pageable pageable) {         return service.getAll(pageable);     }      @GraphQLMutation(name = \"createBankAccount\", description = \"create a new bank account\")     public BankAccountDto createBankAccount(@GraphQLArgument(name = \"createBankAccountInput\") @GraphQLNonNull BankAccountDto bankAccount) {         return service.create(bankAccount);     }      @GraphQLMutation(name = \"dispatchMoney\", description = \"dispatch money\")     public void dispatchMoney(@GraphQLArgument(name = \"createDispatchMoneyInput\") @GraphQLNonNull DispatchMoneyDto dispatchMoneyDto) {         service.dispatchMoney(dispatchMoneyDto);     }      @GraphQLMutation(name = \"removeBankAccount\", description = \"remove bank account\")     public void removeBankAccount(@GraphQLNonNull String numberAccount) {         service.remove(numberAccount);     } } <\/code><\/pre>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <a class=\"mention\" href=\"\/users\/graphqlmutation\">@GraphQLMutation<\/a> name &#8212; \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f GraphQL, \u0430 description &#8212; \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f graphiql<\/p>\n<h2>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<figure class=\"full-width\"><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Query \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430\u043c<\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 Mutation \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430<\/figcaption><\/figure>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435: <a href=\"https:\/\/github.com\/gibkin\/graphql-sqpr-spring-boot-starter\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/gibkin\/graphql-sqpr-spring-boot-starter<\/a><\/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\/594335\/\"> https:\/\/habr.com\/ru\/articles\/594335\/<\/a><br \/><\/br><\/br><\/p>\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-390432","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/390432","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=390432"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/390432\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=390432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=390432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=390432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}