{"id":386080,"date":"2024-06-29T06:29:59","date_gmt":"2024-06-29T06:29:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=386080"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=386080","title":{"rendered":"<span>\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 GraphQL \u0441\u043e Spring Boot<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0c0\/75b\/496\/0c075b496d42381181ec9ed7d5b7a4bb.png\" width=\"733\" height=\"412\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0c0\/75b\/496\/0c075b496d42381181ec9ed7d5b7a4bb.png\"\/><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Spring for GraphQL \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Spring Boot.\u00a0<\/p>\n<p>Spring for GraphQL \u2014 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442.\u00a0\u0412\u0435\u0440\u0441\u0438\u044f\u00a0<code>1.0<\/code> \u0431\u044b\u043b\u0430 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u043d\u0430\u0437\u0430\u0434. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u043b\u0438\u0437\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e GraphQL \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Spring Boot.\u00a0\u042f \u0443\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043b \u0434\u0432\u0430 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445.\u00a0\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439\u00a0<a href=\"https:\/\/piotrminkowski.com\/2020\/07\/31\/an-advanced-guide-to-graphql-with-spring-boot\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>\u00a0\u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0435 GraphQL Java Kickstart.\u00a0\u0412 \u0434\u0440\u0443\u0433\u043e\u0439\u00a0<a href=\"https:\/\/piotrminkowski.com\/2021\/04\/08\/an-advanced-graphql-with-spring-boot-and-netflix-dgs\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>\u00a0\u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b GraphQL \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Netflix DGS.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u0430\u043a \u0438 \u0432 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043e Spring Boot \u0438 GraphQL.<\/p>\n<h3>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.\u00a0\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0439\u00a0\u00a0<a href=\"https:\/\/github.com\/piomin\/sample-spring-boot-graphql.git\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>\u00a0GitHub.\u00a0\u0417\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0439\u0442\u0435 \u043c\u043e\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u00a0<code>sample-app-spring-graphql<\/code>.\u00a0\u041d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 Spring Boot \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 API \u043d\u0430 \u0431\u0430\u0437\u0435 GraphQL \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 H2 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.\u00a0\u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Spring Data JPA \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043b\u043e\u044f \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0\u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438\u00a0<code>Employee<\/code>,\u00a0<code>Department<\/code> \u0438\u00a0<code>Organization<\/code>.\u00a0\u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.\u00a0\u0412\u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5f9\/810\/d10\/5f9810d103cfed39f6bebceaa4024042.png\" alt=\"\" title=\"\" width=\"2480\" height=\"872\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5f9\/810\/d10\/5f9810d103cfed39f6bebceaa4024042.png\"\/><\/figure>\n<h3>\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e Spring for\u00a0GraphQL<\/h3>\n<p>\u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c Spring Boot \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"xml\">&lt;dependency>   &lt;groupId>org.springframework.boot&lt;\/groupId>   &lt;artifactId>spring-boot-starter-graphql&lt;\/artifactId> &lt;\/dependency> &lt;dependency>   &lt;groupId>org.springframework.graphql&lt;\/groupId>   &lt;artifactId>spring-graphql-test&lt;\/artifactId>   &lt;scope>test&lt;\/scope> &lt;\/dependency><\/code><\/pre>\n<p><code>spring-graph-test<\/code>\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432.\u00a0\u0421\u0442\u0430\u0440\u0442\u0435\u0440 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0438 \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439.\u00a0\u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 GraphiQL.\u00a0\u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0432 \u0444\u0430\u0439\u043b\u0435\u00a0<code>application.yml<\/code>:<\/p>\n<pre><code class=\"yaml\">spring:   graphql:     graphiql:       enabled: true<\/code><\/pre>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Spring for GraphQL \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u0445\u0435\u043c\u044b \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 <code>src\/main\/resources\/graphql<\/code>.\u00a0\u041e\u043d \u0438\u0449\u0435\u0442 \u0442\u0430\u043c \u0444\u0430\u0439\u043b\u044b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438 <code>.graphqls<\/code>\u00a0\u0438\u043b\u0438 <code>.gqls<\/code>. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u0441\u0445\u0435\u043c\u0443 GraphQL \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438\u00a0<code>Department<\/code>.\u00a0\u0422\u0438\u043f\u00a0<code>Department<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u0430:\u00a0<code>Organization<\/code>\u00a0\u0438 <code>Employee<\/code>\u00a0(\u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432). \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u043e\u0442\u0434\u0435\u043b\u043e\u0432 \u0438 \u043e\u0442\u0434\u0435\u043b\u0430 \u043f\u043e id \u0438 \u043e\u0434\u043d\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u0430.<\/p>\n<pre><code class=\"json\">type Query {    departments: [Department]    department(id: ID!): Department! }  type Mutation {    newDepartment(department: DepartmentInput!): Department }  input DepartmentInput {    name: String!    organizationId: Int }  type Department {    id: ID!    name: String!    organization: Organization    employees: [Employee] }<\/code><\/pre>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0442\u0438\u043f\u0430\u00a0<code>Organization<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0430.\u00a0\u0418\u0437 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0442\u0438\u043f\u0430\u043c\u0438\u00a0<code>Employee<\/code>\u00a0\u0438 <code>Department<\/code>.<\/p>\n<pre><code class=\"json\">extend type Query {    organizations: [Organization]    organization(id: ID!): Organization! }  extend type Mutation {    newOrganization(organization: OrganizationInput!): Organization }  input OrganizationInput {    name: String! }  type Organization {    id: ID!    name: String!    employees: [Employee]    departments: [Department] }<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0445\u0435\u043c\u0430 \u2014 \u0434\u043b\u044f \u0442\u0438\u043f\u0430\u00a0<code>Employee<\/code>.\u00a0\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0445\u0435\u043c, \u043e\u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u0438\u043f, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438.\u00a0EmployeeFilter \u043c\u043e\u0436\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0437\u0430\u0440\u043f\u043b\u0430\u0442\u0435, \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443.\u00a0\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u2014\u00a0<code>employeesWithFilter<\/code>.<\/p>\n<pre><code class=\"json\">extend type Query {   employees: [Employee]   employeesWithFilter(filter: EmployeeFilter): [Employee]   employee(id: ID!): Employee! }  extend type Mutation {   newEmployee(employee: EmployeeInput!): Employee }  input EmployeeInput {   firstName: String!   lastName: String!   position: String!   salary: Int   age: Int   organizationId: Int!   departmentId: Int! }  type Employee {   id: ID!   firstName: String!   lastName: String!   position: String!   salary: Int   age: Int   department: Department   organization: Organization }  input EmployeeFilter {   salary: FilterField   age: FilterField   position: FilterField }  input FilterField {   operator: String!   value: String! }<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/h3>\n<p>\u041d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u043d\u0430 \u043c\u0435\u043d\u044f \u0437\u043b\u0430, \u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Lombok \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u0412\u043e\u0442\u00a0\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>Employee<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0442\u0438\u043f\u0443 <code>Employee<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0432 \u0441\u0445\u0435\u043c\u0435 GraphQL.<\/p>\n<pre><code class=\"java\">@Entity @Data @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class Employee {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   @EqualsAndHashCode.Include   private Integer id;   private String firstName;   private String lastName;   private String position;   private int salary;   private int age;   @ManyToOne(fetch = FetchType.LAZY)   private Department department;   @ManyToOne(fetch = FetchType.LAZY)   private Organization organization; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u00a0<code>Department<\/code>.<\/p>\n<pre><code class=\"java\">@Entity @Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class Department {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   @EqualsAndHashCode.Include   private Integer id;   private String name;   @OneToMany(mappedBy = \"department\")   private Set&lt;Employee> employees;   @ManyToOne(fetch = FetchType.LAZY)   private Organization organization; }<\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u00a0<code>Organization<\/code>.<\/p>\n<pre><code class=\"java\">@Entity @Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class Organization {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   @EqualsAndHashCode.Include   private Integer id;   private String name;   @OneToMany(mappedBy = \"organization\")   private Set&lt;Department> departments;   @OneToMany(mappedBy = \"organization\")   private Set&lt;Employee> employees; }<\/code><\/pre>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 GraphQL for\u00a0Spring \u0441\u043e Spring Boot<\/h3>\n<p>Spring for\u00a0GraphQL \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u00a0<code>@Controller<\/code>.\u00a0\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Querydsl \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e Spring Data JPA.\u00a0\u0417\u0430\u0442\u0435\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u0445 Spring Data, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<code>@GraphQLRepository<\/code>.\u00a0\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 JPA Criteria API \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\u0438 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.\u00a0\u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0431\u0435\u0438\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438 \u043e Netflix DGS \u0438 GraphQL Java Kickstart, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435.\u00a0\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<code>@QueryMapping<\/code>, \u0430 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<code>@MutationMapping<\/code>.\u00a0\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <code>employeesWithFilter<\/code>\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u0443\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u0435\u0439, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u0442\u0438\u043f\u0435  <code>EmployeeFilter<\/code>.\u00a0\u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@Argument<\/code>.<\/p>\n<pre><code class=\"java\">@Controller public class EmployeeController {     DepartmentRepository departmentRepository;    EmployeeRepository employeeRepository;    OrganizationRepository organizationRepository;     EmployeeController(DepartmentRepository departmentRepository,                       EmployeeRepository employeeRepository,                        OrganizationRepository organizationRepository) {       this.departmentRepository = departmentRepository;       this.employeeRepository = employeeRepository;       this.organizationRepository = organizationRepository;    }     @QueryMapping    public Iterable&lt;Employee> employees() {        return employeeRepository.findAll();    }     @QueryMapping    public Employee employee(@Argument Integer id) {        return employeeRepository.findById(id).orElseThrow();    }     @MutationMapping    public Employee newEmployee(@Argument EmployeeInput employee) {       Department department = departmentRepository          .findById(employee.getDepartmentId()).get();       Organization organization = organizationRepository          .findById(employee.getOrganizationId()).get();       return employeeRepository.save(new Employee(null, employee.getFirstName(), employee.getLastName(),                 employee.getPosition(), employee.getAge(), employee.getSalary(),                 department, organization));    }     @QueryMapping    public Iterable&lt;Employee> employeesWithFilter(          @Argument EmployeeFilter filter) {       Specification&lt;Employee> spec = null;       if (filter.getSalary() != null)          spec = bySalary(filter.getSalary());       if (filter.getAge() != null)          spec = (spec == null ? byAge(filter.getAge()) : spec.and(byAge(filter.getAge())));       if (filter.getPosition() != null)          spec = (spec == null ? byPosition(filter.getPosition()) :                     spec.and(byPosition(filter.getPosition())));       if (spec != null)          return employeeRepository.findAll(spec);       else          return employeeRepository.findAll();    }     private Specification&lt;Employee> bySalary(FilterField filterField) {       return (root, query, builder) -> filterField          .generateCriteria(builder, root.get(\"salary\"));    }     private Specification&lt;Employee> byAge(FilterField filterField) {       return (root, query, builder) -> filterField          .generateCriteria(builder, root.get(\"age\"));    }     private Specification&lt;Employee> byPosition(FilterField filterField) {       return (root, query, builder) -> filterField          .generateCriteria(builder, root.get(\"position\"));    } }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f JPA.\u00a0\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c JPA Criteria API, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>JpaSpecificationExecutor<\/code>.\u00a0\u042d\u0442\u043e \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u043c: <code>DepartmentRepository<\/code> \u0438 <code>OrganizationRepository<\/code>.<\/p>\n<pre><code class=\"java\">public interface EmployeeRepository extends     CrudRepository&lt;Employee, Integer>, JpaSpecificationExecutor&lt;Employee> { }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.\u00a0\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <code>DepartmentController<\/code>.\u00a0\u0417\u0434\u0435\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439.\u00a0\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>DataFetchingEnvironment<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c <code>employees<\/code> \u0438\u043b\u0438 <code>organization<\/code>.\u00a0\u0415\u0441\u043b\u0438 \u043b\u044e\u0431\u043e\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043f\u043e\u043b\u0435\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 JOIN.\u00a0\u0422\u043e\u0442 \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u00a0<code>department<\/code> \u0438 <code>deparments.<\/code>\u00a0<\/p>\n<pre><code class=\"java\">@Controller public class DepartmentController {     DepartmentRepository departmentRepository;    OrganizationRepository organizationRepository;     DepartmentController(DepartmentRepository departmentRepository, OrganizationRepository organizationRepository) {       this.departmentRepository = departmentRepository;       this.organizationRepository = organizationRepository;    }     @MutationMapping    public Department newDepartment(@Argument DepartmentInput department) {       Organization organization = organizationRepository          .findById(department.getOrganizationId()).get();       return departmentRepository.save(new Department(null, department.getName(), null, organization));    }     @QueryMapping    public Iterable&lt;Department> departments(DataFetchingEnvironment environment) {       DataFetchingFieldSelectionSet s = environment.getSelectionSet();       List&lt;Specification&lt;Department>> specifications = new ArrayList&lt;>();       if (s.contains(\"employees\") &amp;&amp; !s.contains(\"organization\"))          return departmentRepository.findAll(fetchEmployees());       else if (!s.contains(\"employees\") &amp;&amp; s.contains(\"organization\"))          return departmentRepository.findAll(fetchOrganization());       else if (s.contains(\"employees\") &amp;&amp; s.contains(\"organization\"))          return departmentRepository.findAll(fetchEmployees().and(fetchOrganization()));       else          return departmentRepository.findAll();    }     @QueryMapping    public Department department(@Argument Integer id, DataFetchingEnvironment environment) {       Specification&lt;Department> spec = byId(id);       DataFetchingFieldSelectionSet selectionSet = environment          .getSelectionSet();       if (selectionSet.contains(\"employees\"))          spec = spec.and(fetchEmployees());       if (selectionSet.contains(\"organization\"))          spec = spec.and(fetchOrganization());       return departmentRepository.findOne(spec).orElseThrow(NoSuchElementException::new);    }      private Specification&lt;Department> fetchOrganization() {         return (root, query, builder) -> {             Fetch&lt;Department, Organization> f = root                .fetch(\"organization\", JoinType.LEFT);             Join&lt;Department, Organization> join = (Join&lt;Department, Organization>) f;             return join.getOn();         };     }     private Specification&lt;Department> fetchEmployees() {       return (root, query, builder) -> {          Fetch&lt;Department, Employee> f = root             .fetch(\"employees\", JoinType.LEFT);          Join&lt;Department, Employee> join = (Join&lt;Department, Employee>) f;          return join.getOn();       };    }     private Specification&lt;Department> byId(Integer id) {       return (root, query, builder) -> builder.equal(root.get(\"id\"), id);    } }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <code>OrganizationController<\/code>.<\/p>\n<pre><code class=\"java\">@Controller public class OrganizationController {     OrganizationRepository repository;     OrganizationController(OrganizationRepository repository) {       this.repository = repository;    }     @MutationMapping    public Organization newOrganization(@Argument OrganizationInput organization) {       return repository.save(new Organization(null, organization.getName(), null, null));    }     @QueryMapping    public Iterable&lt;Organization> organizations() {       return repository.findAll();    }     @QueryMapping    public Organization organization(@Argument Integer id, DataFetchingEnvironment environment) {       Specification&lt;Organization> spec = byId(id);       DataFetchingFieldSelectionSet selectionSet = environment          .getSelectionSet();       if (selectionSet.contains(\"employees\"))          spec = spec.and(fetchEmployees());       if (selectionSet.contains(\"departments\"))          spec = spec.and(fetchDepartments());       return repository.findOne(spec).orElseThrow();    }     private Specification&lt;Organization> fetchDepartments() {       return (root, query, builder) -> {          Fetch&lt;Organization, Department> f = root             .fetch(\"departments\", JoinType.LEFT);          Join&lt;Organization, Department> join = (Join&lt;Organization, Department>) f;          return join.getOn();       };    }     private Specification&lt;Organization> fetchEmployees() {       return (root, query, builder) -> {          Fetch&lt;Organization, Employee> f = root             .fetch(\"employees\", JoinType.LEFT);          Join&lt;Organization, Employee> join = (Join&lt;Organization, Employee>) f;          return join.getOn();       };    }     private Specification&lt;Organization> byId(Integer id) {       return (root, query, builder) -> builder.equal(root.get(\"id\"), id);    } }<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443, \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.\u00a0\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e GraphiQL IDE.\u00a0<\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430\u0445.\u00a0\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0447\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c Spring for GraphQL \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0bean-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>GraphQLTester<\/code>.\u00a0\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043c\u043e\u043a \u0432\u0435\u0431-\u0441\u0440\u0435\u0434\u0435.\u00a0\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u0443\u0440\u043e\u0432\u043d\u044f HTTP \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u2014\u00a0<code>HttpGraphQlTester<\/code>.\u00a0\u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>WebTestClient<\/code>.<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0435\u0441\u0442 \u0434\u043b\u044f\u00a0<code>Employee<\/code>\u00a0<code>@Controller<\/code>.\u00a0\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u044e GraphQL.\u00a0\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@AutoConfigureGraphQlTester<\/code>.\u00a0\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DSL API, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 <code>GraphQLTester<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0431\u044d\u043a\u0435\u043d\u0434\u0430.\u00a0\u041f\u043e\u043c\u0438\u043c\u043e \u0434\u0432\u0443\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u00a0<code>EmployeeFilter<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<code>findWithFilter<\/code>.<\/p>\n<pre><code class=\"java\">@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @AutoConfigureGraphQlTester public class EmployeeControllerTests {     @Autowired    private GraphQlTester tester;     @Test    void addEmployee() {       String query = \"mutation { newEmployee(employee: { firstName: \\\"John\\\" lastName: \\\"Wick\\\" position: \\\"developer\\\" salary: 10000 age: 20 departmentId: 1 organizationId: 1}) { id } }\";       Employee employee = tester.document(query)               .execute()               .path(\"data.newEmployee\")               .entity(Employee.class)               .get();       Assertions.assertNotNull(employee);       Assertions.assertNotNull(employee.getId());    }     @Test    void findAll() {       String query = \"{ employees { id firstName lastName salary } }\";       List&lt;Employee> employees = tester.document(query)              .execute()              .path(\"data.employees[*]\")              .entityList(Employee.class)              .get();       Assertions.assertTrue(employees.size() > 0);       Assertions.assertNotNull(employees.get(0).getId());       Assertions.assertNotNull(employees.get(0).getFirstName());    }     @Test    void findById() {       String query = \"{ employee(id: 1) { id firstName lastName salary } }\";       Employee employee = tester.document(query)              .execute()              .path(\"data.employee\")              .entity(Employee.class)              .get();       Assertions.assertNotNull(employee);       Assertions.assertNotNull(employee.getId());       Assertions.assertNotNull(employee.getFirstName());    }     @Test    void findWithFilter() {       String query = \"{ employeesWithFilter(filter: { salary: { operator: \\\"gt\\\" value: \\\"12000\\\" } }) { id firstName lastName salary } }\";       List&lt;Employee> employees = tester.document(query)              .execute()              .path(\"data.employeesWithFilter[*]\")              .entityList(Employee.class)              .get();       Assertions.assertTrue(employees.size() > 0);       Assertions.assertNotNull(employees.get(0).getId());       Assertions.assertNotNull(employees.get(0).getFirstName());    } }<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u0442\u0438\u043f\u0430\u00a0<code>Deparment<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438.\u00a0\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<code>findById<\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044f \u043f\u043e\u043b\u0435\u00a0<code>organization<\/code> \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n<pre><code class=\"java\">@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @AutoConfigureGraphQlTester public class DepartmentControllerTests {     @Autowired    private GraphQlTester tester;     @Test    void addDepartment() {       String query = \"mutation { newDepartment(department: { name: \\\"Test10\\\" organizationId: 1}) { id } }\";       Department department = tester.document(query)              .execute()              .path(\"data.newDepartment\")              .entity(Department.class)              .get();       Assertions.assertNotNull(department);       Assertions.assertNotNull(department.getId());    }     @Test    void findAll() {       String query = \"{ departments { id name } }\";       List&lt;Department> departments = tester.document(query)              .execute()              .path(\"data.departments[*]\")              .entityList(Department.class)              .get();       Assertions.assertTrue(departments.size() > 0);       Assertions.assertNotNull(departments.get(0).getId());       Assertions.assertNotNull(departments.get(0).getName());    }     @Test    void findById() {       String query = \"{ department(id: 1) { id name organization { id } } }\";       Department department = tester.document(query)              .execute()              .path(\"data.department\")              .entity(Department.class)              .get();       Assertions.assertNotNull(department);       Assertions.assertNotNull(department.getId());       Assertions.assertNotNull(department.getOrganization());       Assertions.assertNotNull(department.getOrganization().getId());    }      }<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u044f \u043c\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u0430\u043c.\u00a0\u0412\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u0441\u0431\u043e\u0440\u043a\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0432 \u043c\u043e\u0435\u043c \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0435 CircleCI.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5f6\/85f\/7d3\/5f685f7d350e603ed8c926089f0c6555.png\" alt=\"\" title=\"\" width=\"1646\" height=\"328\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5f6\/85f\/7d3\/5f685f7d350e603ed8c926089f0c6555.png\"\/><\/figure>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GraphiQL<\/h3>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Maven:<\/p>\n<pre><code class=\"bash\">$ mvn clean spring-boot:run<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u0435, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0443 GraphiQL \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>http:\/\/localhost:8080\/graphiql<\/code>.\u00a0\u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 H2.\u00a0GraphiQL \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u0443\u044e \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438  \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 GraphQL.\u00a0\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0430\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/adf\/dec\/8a5\/adfdec8a5d19bc2813637ec79d5d8e21.png\" alt=\"\" title=\"\" width=\"2020\" height=\"1378\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/adf\/dec\/8a5\/adfdec8a5d19bc2813637ec79d5d8e21.png\"\/><\/figure>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u044b\u0441\u043b\u0438<\/h3>\n<p>Spring for GraphQL \u2014 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u0438 \u044f \u0431\u0443\u0434\u0443 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0435\u0433\u043e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435\u043c.\u00a0<\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438\u00a0<code>@Controller<\/code>, \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e querydsl \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u043c\u0438 Spring Data JPA.\u00a0\u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u043c\u0435\u043d\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u044d\u0442\u0438\u043c, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0432 \u0441\u0442\u0430\u0442\u044c\u044e.\u00a0<\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 Spring for GraphQL \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u0442\u044c\u0438\u043c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c Java-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 GraphQL \u0434\u043b\u044f Spring Boot.\u00a0\u041c\u043e\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f Netflix DGS, \u043d\u043e Spring for GraphQL \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0434\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.\u00a0\u0422\u0430\u043a \u0447\u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432 \u0441\u043a\u043e\u0440\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0445 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<\/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\/720360\/\"> https:\/\/habr.com\/ru\/articles\/720360\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Spring for GraphQL \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Spring Boot.\u00a0<\/p>\n<p>Spring for GraphQL \u2014 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442.\u00a0\u0412\u0435\u0440\u0441\u0438\u044f\u00a0<code>1.0<\/code> \u0431\u044b\u043b\u0430 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u043d\u0430\u0437\u0430\u0434. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u043b\u0438\u0437\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e GraphQL \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Spring Boot.\u00a0\u042f \u0443\u0436\u0435 \u043e\u043f\u0438\u0441\u0430\u043b \u0434\u0432\u0430 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445.\u00a0\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439\u00a0<a href=\"https:\/\/piotrminkowski.com\/2020\/07\/31\/an-advanced-guide-to-graphql-with-spring-boot\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>\u00a0\u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0435 GraphQL Java Kickstart.\u00a0\u0412 \u0434\u0440\u0443\u0433\u043e\u0439\u00a0<a href=\"https:\/\/piotrminkowski.com\/2021\/04\/08\/an-advanced-graphql-with-spring-boot-and-netflix-dgs\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>\u00a0\u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b GraphQL \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Netflix DGS.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u0430\u043a \u0438 \u0432 \u044d\u0442\u0438\u0445 \u0434\u0432\u0443\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043e Spring Boot \u0438 GraphQL.<\/p>\n<h3>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.\u00a0\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0439\u00a0\u00a0<a href=\"https:\/\/github.com\/piomin\/sample-spring-boot-graphql.git\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>\u00a0GitHub.\u00a0\u0417\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0439\u0442\u0435 \u043c\u043e\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u00a0<code>sample-app-spring-graphql<\/code>.\u00a0\u041d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 Spring Boot \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 API \u043d\u0430 \u0431\u0430\u0437\u0435 GraphQL \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 H2 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.\u00a0\u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Spring Data JPA \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043b\u043e\u044f \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0\u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438\u00a0<code>Employee<\/code>,\u00a0<code>Department<\/code> \u0438\u00a0<code>Organization<\/code>.\u00a0\u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.\u00a0\u0412\u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e Spring for\u00a0GraphQL<\/h3>\n<p>\u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c Spring Boot \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"xml\">&lt;dependency>   &lt;groupId>org.springframework.boot&lt;\/groupId>   &lt;artifactId>spring-boot-starter-graphql&lt;\/artifactId> &lt;\/dependency> &lt;dependency>   &lt;groupId>org.springframework.graphql&lt;\/groupId>   &lt;artifactId>spring-graphql-test&lt;\/artifactId>   &lt;scope>test&lt;\/scope> &lt;\/dependency><\/code><\/pre>\n<p><code>spring-graph-test<\/code>\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432.\u00a0\u0421\u0442\u0430\u0440\u0442\u0435\u0440 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0438 \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439.\u00a0\u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 GraphiQL.\u00a0\u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0433\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0432 \u0444\u0430\u0439\u043b\u0435\u00a0<code>application.yml<\/code>:<\/p>\n<pre><code class=\"yaml\">spring:   graphql:     graphiql:       enabled: true<\/code><\/pre>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Spring for GraphQL \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u0445\u0435\u043c\u044b \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 <code>src\/main\/resources\/graphql<\/code>.\u00a0\u041e\u043d \u0438\u0449\u0435\u0442 \u0442\u0430\u043c \u0444\u0430\u0439\u043b\u044b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f\u043c\u0438 <code>.graphqls<\/code>\u00a0\u0438\u043b\u0438 <code>.gqls<\/code>. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u0441\u0445\u0435\u043c\u0443 GraphQL \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438\u00a0<code>Department<\/code>.\u00a0\u0422\u0438\u043f\u00a0<code>Department<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u0430:\u00a0<code>Organization<\/code>\u00a0\u0438 <code>Employee<\/code>\u00a0(\u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432). \u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u043e\u0442\u0434\u0435\u043b\u043e\u0432 \u0438 \u043e\u0442\u0434\u0435\u043b\u0430 \u043f\u043e id \u0438 \u043e\u0434\u043d\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u0430.<\/p>\n<pre><code class=\"json\">type Query {    departments: [Department]    department(id: ID!): Department! }  type Mutation {    newDepartment(department: DepartmentInput!): Department }  input DepartmentInput {    name: String!    organizationId: Int }  type Department {    id: ID!    name: String!    organization: Organization    employees: [Employee] }<\/code><\/pre>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0442\u0438\u043f\u0430\u00a0<code>Organization<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0430.\u00a0\u0418\u0437 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0442\u0438\u043f\u0430\u043c\u0438\u00a0<code>Employee<\/code>\u00a0\u0438 <code>Department<\/code>.<\/p>\n<pre><code class=\"json\">extend type Query {    organizations: [Organization]    organization(id: ID!): Organization! }  extend type Mutation {    newOrganization(organization: OrganizationInput!): Organization }  input OrganizationInput {    name: String! }  type Organization {    id: ID!    name: String!    employees: [Employee]    departments: [Department] }<\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0445\u0435\u043c\u0430 \u2014 \u0434\u043b\u044f \u0442\u0438\u043f\u0430\u00a0<code>Employee<\/code>.\u00a0\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0445\u0435\u043c, \u043e\u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0442\u0438\u043f, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438.\u00a0EmployeeFilter \u043c\u043e\u0436\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0437\u0430\u0440\u043f\u043b\u0430\u0442\u0435, \u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443.\u00a0\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u2014\u00a0<code>employeesWithFilter<\/code>.<\/p>\n<pre><code class=\"json\">extend type Query {   employees: [Employee]   employeesWithFilter(filter: EmployeeFilter): [Employee]   employee(id: ID!): Employee! }  extend type Mutation {   newEmployee(employee: EmployeeInput!): Employee }  input EmployeeInput {   firstName: String!   lastName: String!   position: String!   salary: Int   age: Int   organizationId: Int!   departmentId: Int! }  type Employee {   id: ID!   firstName: String!   lastName: String!   position: String!   salary: Int   age: Int   department: Department   organization: Organization }  input EmployeeFilter {   salary: FilterField   age: FilterField   position: FilterField }  input FilterField {   operator: String!   value: String! }<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/h3>\n<p>\u041d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u043d\u0430 \u043c\u0435\u043d\u044f \u0437\u043b\u0430, \u043d\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Lombok \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. \u0412\u043e\u0442\u00a0\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>Employee<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0442\u0438\u043f\u0443 <code>Employee<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0432 \u0441\u0445\u0435\u043c\u0435 GraphQL.<\/p>\n<pre><code class=\"java\">@Entity @Data @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class Employee {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   @EqualsAndHashCode.Include   private Integer id;   private String firstName;   private String lastName;   private String position;   private int salary;   private int age;   @ManyToOne(fetch = FetchType.LAZY)   private Department department;   @ManyToOne(fetch = FetchType.LAZY)   private Organization organization; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u00a0<code>Department<\/code>.<\/p>\n<pre><code class=\"java\">@Entity @Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class Department {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   @EqualsAndHashCode.Include   private Integer id;   private String name;   @OneToMany(mappedBy = \"department\")   private Set&lt;Employee> employees;   @ManyToOne(fetch = FetchType.LAZY)   private Organization organization; }<\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u00a0<code>Organization<\/code>.<\/p>\n<pre><code class=\"java\">@Entity @Data @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class Organization {   @Id   @GeneratedValue(strategy = GenerationType.IDENTITY)   @EqualsAndHashCode.Include   private Integer id;   private String name;   @OneToMany(mappedBy = \"organization\")   private Set&lt;Department> departments;   @OneToMany(mappedBy = \"organization\")   private Set&lt;Employee> employees; }<\/code><\/pre>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 GraphQL for\u00a0Spring \u0441\u043e Spring Boot<\/h3>\n<p>Spring for\u00a0GraphQL \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u00a0<code>@Controller<\/code>.\u00a0\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Querydsl \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e Spring Data JPA.\u00a0\u0417\u0430\u0442\u0435\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u0445 Spring Data, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<code>@GraphQLRepository<\/code>.\u00a0\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 JPA Criteria API \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\u0438 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.\u00a0\u041f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0431\u0435\u0438\u043c\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438 \u043e Netflix DGS \u0438 GraphQL Java Kickstart, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435.\u00a0\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<code>@QueryMapping<\/code>, \u0430 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<code>@MutationMapping<\/code>.\u00a0\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <code>employeesWithFilter<\/code>\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u0443\u044e \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u0435\u0439, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u0442\u0438\u043f\u0435  <code>EmployeeFilter<\/code>.\u00a0\u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@Argument<\/code>.<\/p>\n<pre><code class=\"java\">@Controller public class EmployeeController {     DepartmentRepository departmentRepository;    EmployeeRepository employeeRepository;    OrganizationRepository organizationRepository;     EmployeeController(DepartmentRepository departmentRepository,                       EmployeeRepository employeeRepository,                        OrganizationRepository organizationRepository) {       this.departmentRepository = departmentRepository;       this.employeeRepository = employeeRepository;       this.organizationRepository = organizationRepository;    }     @QueryMapping    public Iterable&lt;Employee> employees() {        return employeeRepository.findAll();    }     @QueryMapping    public Employee employee(@Argument Integer id) {        return employeeRepository.findById(id).orElseThrow();    }     @MutationMapping    public Employee newEmployee(@Argument EmployeeInput employee) {       Department department = departmentRepository          .findById(employee.getDepartmentId()).get();       Organization organization = organizationRepository          .findById(employee.getOrganizationId()).get();       return employeeRepository.save(new Employee(null, employee.getFirstName(), employee.getLastName(),                 employee.getPosition(), employee.getAge(), employee.getSalary(),                 department, organization));    }     @QueryMapping    public Iterable&lt;Employee> employeesWithFilter(          @Argument EmployeeFilter filter) {       Specification&lt;Employee> spec = null;       if (filter.getSalary() != null)          spec = bySalary(filter.getSalary());       if (filter.getAge() != null)          spec = (spec == null ? byAge(filter.getAge()) : spec.and(byAge(filter.getAge())));       if (filter.getPosition() != null)          spec = (spec == null ? byPosition(filter.getPosition()) :                     spec.and(byPosition(filter.getPosition())));       if (spec != null)          return employeeRepository.findAll(spec);       else          return employeeRepository.findAll();    }     private Specification&lt;Employee> bySalary(FilterField filterField) {       return (root, query, builder) -> filterField          .generateCriteria(builder, root.get(\"salary\"));    }     private Specification&lt;Employee> byAge(FilterField filterField) {       return (root, query, builder) -> filterField          .generateCriteria(builder, root.get(\"age\"));    }     private Specification&lt;Employee> byPosition(FilterField filterField) {       return (root, query, builder) -> filterField          .generateCriteria(builder, root.get(\"position\"));    } }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f JPA.\u00a0\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c JPA Criteria API, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>JpaSpecificationExecutor<\/code>.\u00a0\u042d\u0442\u043e \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f\u043c: <code>DepartmentRepository<\/code> \u0438 <code>OrganizationRepository<\/code>.<\/p>\n<pre><code class=\"java\">public interface EmployeeRepository extends     CrudRepository&lt;Employee, Integer>, JpaSpecificationExecutor&lt;Employee> { }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.\u00a0\u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <code>DepartmentController<\/code>.\u00a0\u0417\u0434\u0435\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439.\u00a0\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>DataFetchingEnvironment<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c <code>employees<\/code> \u0438\u043b\u0438 <code>or<\/code><\/p>\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-386080","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/386080","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=386080"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/386080\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=386080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=386080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=386080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}