{"id":476826,"date":"2026-04-21T13:19:02","date_gmt":"2026-04-21T13:19:02","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=476826"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=476826","title":{"rendered":"REST \u0443\u043c\u0435\u0440? \u041f\u043e\u0447\u0435\u043c\u0443 Java-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0443\u0445\u043e\u0434\u044f\u0442 \u0432 GraphQL"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>\u041e\u0434\u0438\u043d \u044d\u043a\u0440\u0430\u043d<\/strong> \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0430 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\u0435 <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e REST-\u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/strong>, \u043a\u0443\u0447\u0430 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u044b, \u0433\u0434\u0435 90% \u043f\u043e\u043b\u0435\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f. \u0422\u0435\u0440\u044f\u0435\u043c \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>GraphQL<\/strong> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 <strong>\u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/strong>: \u043e\u0434\u0438\u043d API-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u0430\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b. \u042d\u0442\u043e <strong>\u0441\u043d\u0438\u0436\u0430\u0435\u0442 overfetching<\/strong>, <strong>\u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442 \u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 <\/strong>\u043c\u0435\u0436\u0434\u0443 \u0444\u0440\u043e\u043d\u0442\u043e\u043c \u0438 \u0431\u044d\u043a\u043e\u043c \u0437\u0430 \u0441\u0447\u0435\u0442 \u0441\u0445\u0435\u043c\u044b \u043a\u0430\u043a \u044f\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0438 \u0436\u0438\u0432\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u043d\u043e\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <a href=\"https:\/\/t.me\/+acrI2N6q080wZjM6\">Spring \u0410\u0439\u041e<\/a> \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0433\u0434\u0435 <strong>GraphQL \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442<\/strong>: \u043a\u0430\u043a \u0443\u0439\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432, \u043a\u0430\u043a \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0438 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432.<\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 GraphQL?<\/h2>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0441\u043b\u043e\u043d\u0430 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435: \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0434\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0440\u0435\u0437\u044e\u043c\u0435. \u0418\u0437\u0431\u0435\u0433\u0430\u0439\u0442\u0435 Resume Driven Development! \u041e\u0434\u043d\u0430\u043a\u043e GraphQL \u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0431\u043e\u043b\u0435\u0432\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 REST API:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438<\/strong>. REST-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u044b \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043e\u0431\u044a\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u0440\u0430 \u043f\u043e\u043b\u0435\u0439. GraphQL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0440\u043e\u0432\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u043d\u044c\u0448\u0435 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u043e\u0445\u043e\u0434\u043e\u0432.<\/strong> \u0412\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0447\u0435\u0442\u044b\u0440\u0451\u043c \u0440\u0430\u0437\u043d\u044b\u043c \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u044d\u043a\u0440\u0430\u043d \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u043e\u0434\u0438\u043d GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0440\u0430\u0437\u0443 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0423\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432.<\/strong> \u041f\u043e\u043f\u0440\u043e\u0449\u0430\u0439\u0442\u0435\u0441\u044c \u0441 <code>\/users\/{id}<\/code>, <code>\/users\/{id}\/posts<\/code> \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (<code>\/v1<\/code>, <code>\/v2<\/code>). GraphQL \u0434\u0430\u0451\u0442 \u043e\u0434\u0438\u043d-\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.<\/strong> \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 GraphQL \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0445\u0435\u043c\u0443, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u00ab\u0436\u0438\u0432\u0443\u044e\u00bb \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 \u043e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u0435\u043b\u044f GraphiQL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u043d\u0442\u0440\u043e\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c API \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/651\/50c\/7ed\/65150c7edb1205fa1986b372ffa2bccf.png\" width=\"2048\" height=\"1104\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/651\/50c\/7ed\/65150c7edb1205fa1986b372ffa2bccf.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/651\/50c\/7ed\/65150c7edb1205fa1986b372ffa2bccf.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u041f\u0440\u043e\u0435\u043a\u0442: GraphQL Books<\/h2>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u043a\u043d\u0438\u0433, \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u0438 \u043e\u0442\u0437\u044b\u0432\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0435\u0437 \u0440\u0443\u0447\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Docker Compose \u2014 \u043e\u043d \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 \u0431\u0430\u0437\u0443 PostgreSQL \u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Zipkin \u0434\u043b\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<p>\u0412\u043e\u0442 <strong>compose.yaml<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<\/p>\n<pre><code class=\"yaml\">services:  postgres:    image: 'postgres:latest'    environment:      - 'POSTGRES_DB=books'      - 'POSTGRES_PASSWORD=password'      - 'POSTGRES_USER=admin'    ports:      - '5432:5432'  zipkin:    image: 'openzipkin\/zipkin:latest'    ports:      - '9411:9411'<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c Docker Compose \u0432 Spring Boot \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u044d\u0442\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0443\u0447\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<h2>1. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u043e \u0441\u0445\u0435\u043c\u0435 (Schema-First)<\/h2>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 REST API, \u0433\u0434\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0447\u0430\u0441\u0442\u043e \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u00ab\u043d\u0430 \u043f\u043e\u0442\u043e\u043c\u00bb, GraphQL \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 schema-first. \u041c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Schema Definition Language (SDL). \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434- \u0438 \u0431\u044d\u043a\u0435\u043d\u0434-\u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u044b \u0435\u0449\u0451 \u0434\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u0447\u0430\u0441\u0442\u044c \u0441\u0445\u0435\u043c\u044b \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"json\">type Query {  books: [Book!]!  book(id: Int!): Book!  authors: [Author!]!  search(text: String) : [SearchItem!]!}type Mutation {  addBook(bookInput: BookInput): Book!}type Book {  id: ID!  title: String!  author: Author!}type Author {  id: ID!  name: String!  books: [Book!]!}input BookInput {  title: String!  authorId: Int!}union SearchItem = Author | Book<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b: \u0442\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 <code>Query<\/code> \u0438 <code>Mutation<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u044b; input-\u0442\u0438\u043f\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432; \u0430 union-\u0442\u0438\u043f \u2014 \u0434\u043b\u044f union \u0442\u0438\u043f\u043e\u0432 \ud83d\ude42<\/p>\n<p>Spring for GraphQL \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043e\u0442\u0447\u0451\u0442 Schema Mapping Inspection Report. \u041e\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e Java-\u043a\u043e\u0434\u0430 \u0441\u0445\u0435\u043c\u0435, \u0443\u0431\u0435\u0436\u0434\u0430\u044f\u0441\u044c, \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0438\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 fetcher\u2019\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0440\u0430\u0441\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u044d\u0442\u043e \u043f\u0440\u044f\u043c\u043e \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0435\u0449\u0451 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043f\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<h2>2. Data Fetchers (\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b)<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c GraphQL-\u0441\u0445\u0435\u043c\u0443 \u0441 Java-\u043a\u043e\u0434\u043e\u043c, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0432\u0440\u043e\u0434\u0435 <code>@QueryMapping<\/code> \u0438 <code>@MutationMapping<\/code> \u043c\u044b \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0431\u044d\u043a\u0435\u043d\u0434-\u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u0432 \u0441\u0445\u0435\u043c\u0435. \u0412\u043e\u0442 <code>BookController<\/code>:<\/p>\n<pre><code class=\"java\">@Controllerpublic class BookController {    private final BookRepository bookRepository;    private final AuthorRepository authorRepository;    public BookController(BookRepository bookRepository, AuthorRepository authorRepository) {        this.bookRepository = bookRepository;        this.authorRepository = authorRepository;    }    @QueryMapping    public List&lt;Book&gt; books() {        return bookRepository.findAll();    }    @QueryMapping    public Optional&lt;Book&gt; book(@Argument Long id) {        return bookRepository.findById(id);    }    @MutationMapping    public Book addBook(@Argument BookInput bookInput) {        var author = authorRepository.findById(bookInput.authorId());        var book = new Book();        book.setTitle(bookInput.title());        book.setAuthor(author.orElseThrow());        return bookRepository.save(book);    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@QueryMapping<\/code> \u2014 \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f <code>@SchemaMapping(typeName = \"Query\")<\/code>. Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043f\u043e\u043b\u0435\u043c \u0432 \u0441\u0445\u0435\u043c\u0435. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Argument<\/code> \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b GraphQL \u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u0414\u043b\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c input-\u0442\u0438\u043f, \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043d\u0438\u0433\u0438. \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Java \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 record:<\/p>\n<pre><code class=\"java\">public record BookInput(String title, Long authorId) {}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>Records \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f GraphQL input-\u0442\u0438\u043f\u043e\u0432: \u043e\u043d\u0438 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0435, \u0430 Spring for GraphQL \u043c\u043e\u0436\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c record\u2019\u0430.<\/p>\n<p>\u0421 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c GraphiQL \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"yaml\"># \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u043a\u043d\u0438\u0433\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0445 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438query {  books {    id    title    author {      name    }  }}# \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043a\u043d\u0438\u0433\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435query findBookById($id: Int!) {  book(id: $id) {    id    title    author {      id      name    }  }}# \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u043a\u043d\u0438\u0433\u0443mutation {  addBook(bookInput: {title: \"new book\", authorId: 1}) {    id    title  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h2>3. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b N+1 \u0441 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439<\/h2>\n<p>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u0430. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043d\u0438\u0433\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430, \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 N+1 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<pre><code class=\"java\">@SchemaMappingpublic List&lt;Book&gt; books(Author author) throws InterruptedException {  log.info(\"Retrieving books for author \" + author.getName());  return bookRepository.findByAuthor(author);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 6 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 6 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u043a\u0430\u043a SQL-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u0441 <code>spring.jpa.show-sql=true<\/code>. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u2014 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@BatchMapping<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0432 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"java\">@BatchMappingpublic List&lt;List&lt;Book&gt;&gt; books(List&lt;Author&gt; authors) {    log.info(\"Batch loading books for {} authors\", authors.size());    List&lt;Long&gt; authorIds = authors.stream()        .map(Author::getId)        .toList();    List&lt;Book&gt; allBooks = bookRepository.findByAuthorIdIn(authorIds);    Map&lt;Long, List&lt;Book&gt;&gt; booksByAuthorId = allBooks.stream()        .collect(Collectors.groupingBy(book -&gt; book.getAuthor().getId()));    return authors.stream()        .map(author -&gt; booksByAuthorId.getOrDefault(author.getId(), Collections.emptyList()))        .toList();}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0430\u043c\u0430 \u0437\u0430 \u0441\u0435\u0431\u044f. Spring \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Author, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u0435 <code>books<\/code>, \u0430 \u0432\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0435 <code>List&lt;List&gt;<\/code>, \u0433\u0434\u0435 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443. \u041e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0438 \u0433\u043e\u0442\u043e\u0432\u043e.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u043c, \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 (Virtual Threads), \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0430\u0441\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0430 \u043d\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 Tomcat. \u042d\u0442\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"yaml\">spring:  threads:    virtual:      enabled: true<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h2>4. \u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0441 Unions<\/h2>\n<p>\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u0449\u0435\u0442 \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443, \u0430 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043b\u0438\u0431\u043e <code>Book<\/code>, \u043b\u0438\u0431\u043e <code>Author<\/code>? \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f GraphQL (Unions) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0412 \u0441\u0445\u0435\u043c\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"json\">union SearchItem = Author | Book<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0410 \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c <code>SearchController<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"java\">@Controllerpublic class SearchController {    private static final Logger log = LoggerFactory.getLogger(SearchController.class);    private final BookRepository bookRepository;    private final AuthorRepository authorRepository;    public SearchController(BookRepository bookRepository, AuthorRepository authorRepository) {        this.bookRepository = bookRepository;        this.authorRepository = authorRepository;    }    @QueryMapping    public List&lt;Object&gt; search(@Argument String text) {        log.debug(\"Searching for '{}'\", text);        List&lt;Object&gt; results = new ArrayList&lt;&gt;();        results.addAll(authorRepository.findAllByNameContainsIgnoreCase(text));        results.addAll(bookRepository.findAllByTitleContainsIgnoreCase(text));        return results;    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 <code>List<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 <code>Author<\/code> \u0438\u043b\u0438 <code>Book<\/code>. Spring for GraphQL \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u0430\u043a\u0435\u0442\u0435, \u0447\u0442\u043e \u0438 \u0442\u0438\u043f\u044b \u0441\u0445\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442. \u041a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c inline fragments, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"json\">query {  search(text: \"Spring\") {    ... on Book {      title    }    ... on Author {      name    }  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h2>5. Query By Example \u0438 @GraphQlRepository<\/h2>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u0438\u0431\u043a\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043e\u0442\u0437\u044b\u0432\u043e\u0432, \u0433\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0446\u0435\u043d\u043a\u0435, \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0440\u0435\u0446\u0435\u043d\u0437\u0435\u043d\u0442\u0430, \u043f\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u0443 \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u2014 \u0438\u043b\u0438 \u043f\u043e \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u0432\u044b \u0431\u044b \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438.<\/p>\n<p>Spring for GraphQL \u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>@GraphQlRepository<\/code> \u0438 Query by Example:<\/p>\n<pre><code class=\"java\">@GraphQlRepositorypublic interface ReviewRepository extends JpaRepository&lt;Review, Long&gt;, QueryByExampleExecutor&lt;Review&gt; {}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0432\u0435\u0441\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@GraphQlRepository<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 data fetcher\u2019\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0441\u0445\u0435\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u044d\u0442\u043e\u043c\u0443 \u0442\u0438\u043f\u0443. \u0412 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 <code>QueryByExampleExecutor<\/code> \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0435\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432.<\/p>\n<p>\u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0445\u0435\u043c\u044b \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c input-\u0442\u0438\u043f ReviewFilter:<\/p>\n<pre><code class=\"json\">input ReviewFilter {  rating: Int  verified: Boolean  reviewerName: String}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 Java record:<\/p>\n<pre><code class=\"java\">public record ReviewFilter(  Integer rating,  Boolean verified,  String reviewerName) {}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u2014 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb:<\/p>\n<pre><code class=\"json\"># \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0437\u044b\u0432\u044b{  reviews(filter: { verified: true }) {    reviewerName    rating    comment  }}# \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u0437\u044b\u0432\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0440\u0435\u0446\u0435\u043d\u0437\u0435\u043d\u0442\u0430{  reviews(filter: { reviewerName: \"Sarah Chen\" }) {    book {      title    }    rating    comment  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u043e\u043b\u044f \u0432 \u0444\u0438\u043b\u044c\u0442\u0440\u0435 \u0432\u0441\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 <code>null<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u043b\u0438 \u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c \u043d\u0443\u0436\u043d\u0430.<\/p>\n<h2>6. \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 Spring Data AOT<\/h2>\n<p>Spring Boot 4 \u0432\u0432\u043e\u0434\u0438\u0442 Spring Data AOT (Ahead-of-Time) \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e. \u0414\u043e\u0431\u0430\u0432\u0438\u0432 \u0446\u0435\u043b\u044c process-aot \u0432 Maven-\u043f\u043b\u0430\u0433\u0438\u043d, \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u0438\u0437 runtime \u0432 build time. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, AOT-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 SQL-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0431\u043e\u0440\u043a\u0438.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0432 <strong>pom.xml<\/strong>:<\/p>\n<pre><code class=\"xml\">&lt;plugin&gt;    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;    &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;    &lt;executions&gt;        &lt;execution&gt;            &lt;id&gt;process-aot&lt;\/id&gt;            &lt;goals&gt;                &lt;goal&gt;process-aot&lt;\/goal&gt;            &lt;\/goals&gt;        &lt;\/execution&gt;    &lt;\/executions&gt;&lt;\/plugin&gt;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u0442\u0430\u0440\u0442 (\u043a\u043e\u043c\u0430\u043d\u0434\u0430 Spring \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 50\u201370%), \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0435\u0447\u0430\u0442\u043e\u043a \u0432 \u0438\u043c\u0435\u043d\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 <code>findByNamme<\/code>, \u2014 \u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0440\u0430\u0441\u0445\u043e\u0434 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 SQL-\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 <code>target\/<\/code>. \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>BookRepository<\/code> \u0438 <code>AuthorRepository<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u044e\u0442 \u043e\u0442 AOT-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<\/p>\n<pre><code class=\"java\">public interface BookRepository extends JpaRepository&lt;Book, Long&gt; {    @Override    @EntityGraph(attributePaths = \"author\")    List&lt;Book&gt; findAll();    List&lt;Book&gt; findAllByTitleContainsIgnoreCase(String title);    List&lt;Book&gt; findByAuthorIdIn(List&lt;Long&gt; authorIds);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h2>7. \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041c\u044b \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c, \u043a\u0430\u043a \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c GraphQL API \u0438\u0437 Java-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <code>ClientApp<\/code> \u2014 \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 Spring Boot (\u0441 <code>WebApplicationType.NONE<\/code>), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 <code>HttpSyncGraphQlClient<\/code> \u043e\u0442 Spring:<\/p>\n<pre><code class=\"java\">@Import(RestClientAutoConfiguration.class)public class ClientApp implements ApplicationRunner {    private static final Logger log = LoggerFactory.getLogger(ClientApp.class);    private final HttpSyncGraphQlClient client;    public ClientApp(RestClient.Builder builder) {        RestClient restClient = builder.baseUrl(\"http:\/\/localhost:8080\/graphql\").build();        this.client = HttpSyncGraphQlClient.builder(restClient).build();    }    public static void main(String[] args) {        new SpringApplicationBuilder(ClientApp.class).web(WebApplicationType.NONE).run(args);    }    @Override    public void run(ApplicationArguments args) throws Exception {        var document = \"\"\"                query findBookById($id: Int!) {                    book(id: $id) {                        id                        title                        author {                            id                            name                        }                    }                }                \"\"\";        var book = client.document(document)                .variable(\"id\", 1L)                .retrieveSync(\"book\")                .toEntity(Book.class);        log.info(\"Book: {}\", book);    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u043e\u0432\u0435\u0440\u0445 <code>RestClient<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f. \u0412\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0435 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0432\u0430\u0448 entity-\u043a\u043b\u0430\u0441\u0441. \u0412\u044b\u0437\u043e\u0432 <code>.toEntity(Book.class)<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 <code>author<\/code>.<\/p>\n<h2>8. \u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0441\u0442\u044c<\/h2>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 GraphQL API \u043c\u043e\u0436\u0435\u0442 \u00ab\u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0442\u044c\u00bb \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0431\u0430\u0437\u0430\u043c\u0438, \u043a\u044d\u0448\u0430\u043c\u0438 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u043e\u0439. \u0412 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Micrometer tracing bridge \u0438 Zipkin reporter, \u0430 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0441\u044d\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 100%:<\/p>\n<pre><code class=\"yaml\">management:  tracing:    sampling:      probability: 1.0<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>Spring for GraphQL \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043d\u0430 \u0431\u0430\u0437\u0435 Micrometer Observation API. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 data fetcher \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u044c Grafana \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443<a href=\"http:\/\/localhost:3000\/\"> <\/a><strong>http:\/\/localhost:3000<\/strong> \u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0432\u0430\u0448\u0438\u043c data fetcher\u2019\u0430\u043c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0443\u0437\u043a\u0438\u0435 \u043c\u0435\u0441\u0442\u0430.<\/p>\n<h2>9. \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u0442\u0430\u043a\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>GraphQlTester<\/code> \u0438\u0437 Spring for GraphQL. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u0442 \u043c\u0443\u0442\u0430\u0446\u0438\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u043a\u043d\u0438\u0433\u0438:<\/p>\n<pre><code class=\"java\">@SpringBootTest@Transactionalclass BookControllerTests {    private final GraphQlTester graphQlTester;    @Autowired    BookControllerTests(ExecutionGraphQlService graphQlService) {        this.graphQlTester = ExecutionGraphQlServiceTester.builder(graphQlService).build();    }    @Test    void shouldAddNewBook() {        var document = \"\"\"        mutation($input: BookInput!) {            addBook(bookInput: $input) {                id                title                author {                    id                    name                }            }        }        \"\"\";        Map&lt;String, Object&gt; input = Map.of(                \"title\", \"New Book\",                \"authorId\", 1        );        graphQlTester.document(document)                .variable(\"input\", input)                .execute()                .path(\"addBook\")                .entity(Book.class)                .satisfies(book -&gt; {                    assertThat(book.getTitle()).isEqualTo(\"New Book\");                    assertThat(book.getAuthor()).isNotNull();                });    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><code>ExecutionGraphQlServiceTester<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u043c\u0443 GraphQL-\u0434\u0432\u0438\u0436\u043a\u0443 \u0431\u0435\u0437 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 HTTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0435\u0441\u0442\u044b \u0431\u044b\u0441\u0442\u0440\u044b\u043c\u0438 \u0438 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u043d\u044b\u043c\u0438. \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f Testcontainers \u0434\u043b\u044f PostgreSQL, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c\u044b.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/258\/484\/92d\/25848492d4cd2dcd1df595e475569a9a.png\" width=\"1560\" height=\"334\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/258\/484\/92d\/25848492d4cd2dcd1df595e475569a9a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/258\/484\/92d\/25848492d4cd2dcd1df595e475569a9a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><a href=\"https:\/\/t.me\/+acrI2N6q080wZjM6\">\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c<\/a>\u00a0\u043a\u00a0\u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430\u00a0Spring Boot \u0432\u00a0\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u00a0\u2014\u00a0<a href=\"https:\/\/t.me\/+acrI2N6q080wZjM6\">Spring \u0410\u0439\u041e<\/a>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0432 \u043a\u0443\u0440\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439 \u0438\u0437 \u043c\u0438\u0440\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Spring Boot \u0438 \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u0441 \u043d\u0438\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043e.<\/p>\n<\/div>\n<p>\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\/1026130\/\">https:\/\/habr.com\/ru\/articles\/1026130\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u0434\u0438\u043d \u044d\u043a\u0440\u0430\u043d \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0430 \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e REST-\u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u043a\u0443\u0447\u0430 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u044b, \u0433\u0434\u0435 90% \u043f\u043e\u043b\u0435\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f. \u0422\u0435\u0440\u044f\u0435\u043c \u0432 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445.GraphQL \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434: \u043e\u0434\u0438\u043d API-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0438 \u0437\u0430\u043f\u0440\u043e\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u0430\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 overfetching, \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442 \u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0444\u0440\u043e\u043d\u0442\u043e\u043c \u0438 \u0431\u044d\u043a\u043e\u043c \u0437\u0430 \u0441\u0447\u0435\u0442 \u0441\u0445\u0435\u043c\u044b \u043a\u0430\u043a \u044f\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430 \u0438 \u0436\u0438\u0432\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.\u0412 \u043d\u043e\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Spring \u0410\u0439\u041e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0433\u0434\u0435 GraphQL \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442: \u043a\u0430\u043a \u0443\u0439\u0442\u0438 \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432, \u043a\u0430\u043a \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0438 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432.\u041f\u043e\u0447\u0435\u043c\u0443 GraphQL?\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0441\u043b\u043e\u043d\u0430 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435: \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0434\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0440\u0435\u0437\u044e\u043c\u0435. \u0418\u0437\u0431\u0435\u0433\u0430\u0439\u0442\u0435 Resume Driven Development! \u041e\u0434\u043d\u0430\u043a\u043e GraphQL \u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0431\u043e\u043b\u0435\u0432\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 REST API:\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. REST-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u044b \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043e\u0431\u044a\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u0440\u0430 \u043f\u043e\u043b\u0435\u0439. GraphQL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0440\u043e\u0432\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e.\u041c\u0435\u043d\u044c\u0448\u0435 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u043e\u0445\u043e\u0434\u043e\u0432. \u0412\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0447\u0435\u0442\u044b\u0440\u0451\u043c \u0440\u0430\u0437\u043d\u044b\u043c \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u044d\u043a\u0440\u0430\u043d \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u043e\u0434\u0438\u043d GraphQL-\u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0440\u0430\u0437\u0443 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.\u0423\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432. \u041f\u043e\u043f\u0440\u043e\u0449\u0430\u0439\u0442\u0435\u0441\u044c \u0441 \/users\/{id}, \/users\/{id}\/posts \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\/v1, \/v2). GraphQL \u0434\u0430\u0451\u0442 \u043e\u0434\u0438\u043d-\u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0434\u0430\u043d\u043d\u044b\u043c.\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 GraphQL \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0445\u0435\u043c\u0443, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u00ab\u0436\u0438\u0432\u0443\u044e\u00bb \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 \u043e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u0435\u043b\u044f GraphiQL \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u043d\u0442\u0440\u043e\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c API \u043f\u0440\u044f\u043c\u043e \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.\u041f\u0440\u043e\u0435\u043a\u0442: GraphQL Books\u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u043a\u043d\u0438\u0433, \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u0438 \u043e\u0442\u0437\u044b\u0432\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u0431\u044b\u0441\u0442\u0440\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0435\u0437 \u0440\u0443\u0447\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Docker Compose \u2014 \u043e\u043d \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 \u0431\u0430\u0437\u0443 PostgreSQL \u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Zipkin \u0434\u043b\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438.\u0412\u043e\u0442 compose.yaml, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438:services:  postgres:    image: &#8216;postgres:latest&#8217;    environment:      &#8212; &#8216;POSTGRES_DB=books&#8217;      &#8212; &#8216;POSTGRES_PASSWORD=password&#8217;      &#8212; &#8216;POSTGRES_USER=admin&#8217;    ports:      &#8212; &#8216;5432:5432&#8217;  zipkin:    image: &#8216;openzipkin\/zipkin:latest&#8217;    ports:      &#8212; &#8216;9411:9411&#8217;\u041c\u043e\u0434\u0443\u043b\u044c Docker Compose \u0432 Spring Boot \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u044d\u0442\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0443\u0447\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.1. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u043e \u0441\u0445\u0435\u043c\u0435 (Schema-First)\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 REST API, \u0433\u0434\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0447\u0430\u0441\u0442\u043e \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u00ab\u043d\u0430 \u043f\u043e\u0442\u043e\u043c\u00bb, GraphQL \u043f\u0440\u043e\u0434\u0432\u0438\u0433\u0430\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 schema-first. \u041c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Schema Definition Language (SDL). \u042d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434- \u0438 \u0431\u044d\u043a\u0435\u043d\u0434-\u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u044b \u0435\u0449\u0451 \u0434\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.\u0412\u043e\u0442 \u0447\u0430\u0441\u0442\u044c \u0441\u0445\u0435\u043c\u044b \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:type Query {  books: [Book!]!  book(id: Int!): Book!  authors: [Author!]!  search(text: String) : [SearchItem!]!}type Mutation {  addBook(bookInput: BookInput): Book!}type Book {  id: ID!  title: String!  author: Author!}type Author {  id: ID!  name: String!  books: [Book!]!}input BookInput {  title: String!  authorId: Int!}union SearchItem = Author | Book\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b: \u0442\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 Query \u0438 Mutation \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u044b; input-\u0442\u0438\u043f\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432; \u0430 union-\u0442\u0438\u043f \u2014 \u0434\u043b\u044f union \u0442\u0438\u043f\u043e\u0432 :)Spring for GraphQL \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043e\u0442\u0447\u0451\u0442 Schema Mapping Inspection Report. \u041e\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e Java-\u043a\u043e\u0434\u0430 \u0441\u0445\u0435\u043c\u0435, \u0443\u0431\u0435\u0436\u0434\u0430\u044f\u0441\u044c, \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0438\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 fetcher\u2019\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0415\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0440\u0430\u0441\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u044d\u0442\u043e \u043f\u0440\u044f\u043c\u043e \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0435\u0449\u0451 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043f\u0430\u0434\u0451\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440.2. Data Fetchers (\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b)\u0427\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c GraphQL-\u0441\u0445\u0435\u043c\u0443 \u0441 Java-\u043a\u043e\u0434\u043e\u043c, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 \u0432\u0440\u043e\u0434\u0435 @QueryMapping \u0438 @MutationMapping \u043c\u044b \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0431\u044d\u043a\u0435\u043d\u0434-\u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u0432 \u0441\u0445\u0435\u043c\u0435. \u0412\u043e\u0442 BookController:@Controllerpublic class BookController {    private final BookRepository bookRepository;    private final AuthorRepository authorRepository;    public BookController(BookRepository bookRepository, AuthorRepository authorRepository) {        this.bookRepository = bookRepository;        this.authorRepository = authorRepository;    }    @QueryMapping    public List&lt;Book&gt; books() {        return bookRepository.findAll();    }    @QueryMapping    public Optional&lt;Book&gt; book(@Argument Long id) {        return bookRepository.findById(id);    }    @MutationMapping    public Book addBook(@Argument BookInput bookInput) {        var author = authorRepository.findById(bookInput.authorId());        var book = new Book();        book.setTitle(bookInput.title());        book.setAuthor(author.orElseThrow());        return bookRepository.save(book);    }}\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @QueryMapping \u2014 \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f @SchemaMapping(typeName = &#171;Query&#187;). Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043f\u043e\u043b\u0435\u043c \u0432 \u0441\u0445\u0435\u043c\u0435. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @Argument \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b GraphQL \u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u0430.\u0414\u043b\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c input-\u0442\u0438\u043f, \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043d\u0438\u0433\u0438. \u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Java \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 record:public record BookInput(String title, Long authorId) {}Records \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f GraphQL input-\u0442\u0438\u043f\u043e\u0432: \u043e\u043d\u0438 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435, \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0435, \u0430 Spring for GraphQL \u043c\u043e\u0436\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u043c record\u2019\u0430.\u0421 \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c GraphiQL \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:# \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u043a\u043d\u0438\u0433\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0445 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438query {  books {    id    title    author {      name    }  }}# \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043a\u043d\u0438\u0433\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435query findBookById($id: Int!) {  book(id: $id) {    id    title    author {      id      name    }  }}# \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u043a\u043d\u0438\u0433\u0443mutation {  addBook(bookInput: {title: &#171;new book&#187;, authorId: 1}) {    id    title  }}3. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b N+1 \u0441 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u0430. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043d\u0438\u0433\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430, \u043c\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 N+1 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:@SchemaMappingpublic List&lt;Book&gt; books(Author author) throws InterruptedException {  log.info(&#171;Retrieving books for author &#187; + author.getName());  return bookRepository.findByAuthor(author);}\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 6 \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 6 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u043a\u0430\u043a SQL-\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u0441 spring.jpa.show-sql=true. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u2014 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @BatchMapping, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0432 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:@BatchMappingpublic List&lt;List&lt;Book&gt;&gt; books(List&lt;Author&gt; authors) {    log.info(&#171;Batch loading books for {} authors&#187;, authors.size());    List&lt;Long&gt; authorIds = authors.stream()        .map(Author::getId)        .toList();    List&lt;Book&gt; allBooks = bookRepository.findByAuthorIdIn(authorIds);    Map&lt;Long, List&lt;Book&gt;&gt; booksByAuthorId = allBooks.stream()        .collect(Collectors.groupingBy(book -&gt; book.getAuthor().getId()));    return authors.stream()        .map(author -&gt; booksByAuthorId.getOrDefault(author.getId(), Collections.emptyList()))        .toList();}\u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0430\u043c\u0430 \u0437\u0430 \u0441\u0435\u0431\u044f. Spring \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Author, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u0435 books, \u0430 \u0432\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0435 List&lt;List&gt;, \u0433\u0434\u0435 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443. \u041e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u2014 \u0438 \u0433\u043e\u0442\u043e\u0432\u043e.\u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u043c, \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 (Virtual Threads), \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0430\u0441\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0430 \u043d\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 Tomcat. \u042d\u0442\u043e \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:spring:  threads:    virtual:      enabled: true4. \u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u0441 Unions\u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u0449\u0435\u0442 \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443, \u0430 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043b\u0438\u0431\u043e Book, \u043b\u0438\u0431\u043e Author? \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f GraphQL (Unions) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0412 \u0441\u0445\u0435\u043c\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c:union SearchItem = Author | Book\u0410 \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c SearchController, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:@Controllerpublic class SearchController {    private static final Logger log = LoggerFactory.getLogger(SearchController.class);    private final BookRepository bookRepository;    private final AuthorRepository authorRepository;    public SearchController(BookRepository bookRepository, AuthorRepository authorRepository) {        this.bookRepository = bookRepository;        this.authorRepository = authorRepository;    }    @QueryMapping    public List&lt;Object&gt; search(@Argument String text) {        log.debug(&#171;Searching for &#8216;{}'&#187;, text);        List&lt;Object&gt; results = new ArrayList&lt;&gt;();        results.addAll(authorRepository.findAllByNameContainsIgnoreCase(text));        results.addAll(bookRepository.findAllByTitleContainsIgnoreCase(text));        return results;    }}\u0422\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 List, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 Author \u0438\u043b\u0438 Book. Spring for GraphQL \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u0430\u043a\u0435\u0442\u0435, \u0447\u0442\u043e \u0438 \u0442\u0438\u043f\u044b \u0441\u0445\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442. \u041a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u0430\u0442\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c inline fragments, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430:query {  search(text: &#171;Spring&#187;) {    &#8230; on Book {      title    }    &#8230; on Author {      name    }  }}5. Query By Example \u0438 @GraphQlRepository\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u0438\u0431\u043a\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043e\u0442\u0437\u044b\u0432\u043e\u0432, \u0433\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0445\u043e\u0442\u0435\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0446\u0435\u043d\u043a\u0435, \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0440\u0435\u0446\u0435\u043d\u0437\u0435\u043d\u0442\u0430, \u043f\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u0443 \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u2014 \u0438\u043b\u0438 \u043f\u043e \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u0432\u044b \u0431\u044b \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438.Spring for GraphQL \u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e @GraphQlRepository \u0438 Query by Example:@GraphQlRepositorypublic interface ReviewRepository extends JpaRepository&lt;Review, Long&gt;, QueryByExampleExecutor&lt;Review&gt; {}\u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0432\u0435\u0441\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f @GraphQlRepository \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 data&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-476826","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/476826","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=476826"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/476826\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=476826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=476826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=476826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}