{"id":404776,"date":"2024-06-29T17:55:03","date_gmt":"2024-06-29T17:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=404776"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=404776","title":{"rendered":"<span>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c Kotlin \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e GraphQL \u0441\u0445\u0435\u043c\u0435<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4e9\/1a8\/f26\/4e91a8f26ed5f397ad25cd197fb91f1d.png\" alt=\"\u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u0435 REST, \u043e\u0447\u0435\u043d\u044c \u0441\u043a\u043e\u0440\u043e \u0440\u0430\u0437\u043e\u0440\u0438\u0442\u0435\u0441\u044c... \u0421\u043b\u043e\u0432\u043e \u00abKotlin\u00bb \u0438 \u0441\u043b\u043e\u0432\u043e \u00abGraphQL\u00bb \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435!\" title=\"\u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u0435 REST, \u043e\u0447\u0435\u043d\u044c \u0441\u043a\u043e\u0440\u043e \u0440\u0430\u0437\u043e\u0440\u0438\u0442\u0435\u0441\u044c... \u0421\u043b\u043e\u0432\u043e \u00abKotlin\u00bb \u0438 \u0441\u043b\u043e\u0432\u043e \u00abGraphQL\u00bb \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435!\" width=\"921\" height=\"657\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4e9\/1a8\/f26\/4e91a8f26ed5f397ad25cd197fb91f1d.png\"\/><figcaption>\u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u0435 REST, \u043e\u0447\u0435\u043d\u044c \u0441\u043a\u043e\u0440\u043e \u0440\u0430\u0437\u043e\u0440\u0438\u0442\u0435\u0441\u044c&#8230; \u0421\u043b\u043e\u0432\u043e \u00abKotlin\u00bb \u0438 \u0441\u043b\u043e\u0432\u043e \u00abGraphQL\u00bb \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435!<\/figcaption><\/figure>\n<p>\u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, GraphQL \u0441\u0445\u0435\u043c\u0430 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0435\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439, Kotlin \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u0440\u044f\u0441\u0430\u044e\u0449\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 (DSL). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u044f\u0437\u044b\u043a \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 GraphQL \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u043e\u0439. \u041d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u044d\u0442\u043e \u0441\u0438\u0437\u0438\u0444\u043e\u0432 \u0442\u0440\u0443\u0434. \u041b\u0443\u0447\u0448\u0435 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0418 \u0432 \u044d\u0442\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 <a href=\"https:\/\/github.com\/ermadmi78\/kobby\" rel=\"noopener noreferrer nofollow\"><strong>\u043f\u043b\u0430\u0433\u0438\u043d Kobby<\/strong><\/a>. \u041e\u043d \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 GraphQL \u0441\u0445\u0435\u043c\u0443 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 DSL. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u0434\u0435\u043b\u0435!<\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435?<\/summary>\n<div class=\"spoiler__content\">\n<p><code>GraphQL<\/code>:<\/p>\n<pre><code class=\"json\">query {   film(id: 0) {     id     title     actors {       id       firstName       lastName     }   } }<\/code><\/pre>\n<p><code>Kotlin<\/code>:<\/p>\n<pre><code class=\"kotlin\">val result = context.query {     film(id = 0L) {         id()         title()         actors {             id()             firstName()             lastName()         }     } }<\/code><\/pre>\n<p><code>GraphQL<\/code>:<\/p>\n<pre><code class=\"json\">mutation {   createFilm(title: \"My Film\") {     id     title   } }<\/code><\/pre>\n<p><code>Kotlin<\/code>:<\/p>\n<pre><code class=\"kotlin\">val result = context.mutation {     createFilm(title = \"My Film\") {         id()         title()     } }<\/code><\/pre>\n<p><code>GraphQL<\/code>:<\/p>\n<pre><code class=\"json\">subscription {   filmCreated {     id     title   } }<\/code><\/pre>\n<p><code>Kotlin<\/code>:<\/p>\n<pre><code class=\"kotlin\">launch(Dispatchers.Default) {     context.subscription {         filmCreated {             id()             title()         }     }.subscribe {         while (true) {             val result = receive()         }     } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 <a href=\"https:\/\/github.com\/ermadmi78\/kobby-gradle-tutorial\" rel=\"noopener noreferrer nofollow\"><strong>Kobby Gradle Tutorial<\/strong><\/a> \u0438 <a href=\"https:\/\/github.com\/ermadmi78\/kobby-maven-tutorial\" rel=\"noopener noreferrer nofollow\"><strong>Kobby Maven Tutorial<\/strong><\/a>.<\/p>\n<hr\/>\n<h2>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u043e \u0441\u0445\u0435\u043c\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Gradle-GraphQL-Schema-Location\" rel=\"noopener noreferrer nofollow\">Kobby \u0438\u0449\u0435\u0442 GraphQL \u0441\u0445\u0435\u043c\u0443<\/a> \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <code>graphqls<\/code> \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u0445\u0435\u043c\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 <code>cinema.graphqls<\/code>:<\/p>\n<pre><code class=\"json\">type Query {     film(id: ID!): Film     films: [Film!]! }  type Mutation {     createFilm(title: String!): Film! }  type Subscription {     filmCreated: Film! }  type Film {     id: ID!     title: String!     actors: [Actor!]! }  type Actor {     id: ID!     firstName: String!     lastName: String }<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 GraphQL &#8212; \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0430\u043c \u043f\u043b\u0430\u0433\u0438\u043d. \u0414\u043b\u044f <strong>Gradle<\/strong> \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"kotlin\">plugins {     kotlin(\"jvm\")     id(\"io.github.ermadmi78.kobby\") version \"1.3.0\" }  dependencies {     \/\/ Add this dependency to enable      \/\/ Jackson annotation generation in DTO classes     compileOnly(\"com.fasterxml.jackson.core:jackson-annotations:2.12.2\")      \/\/ Add this dependency to enable      \/\/ default Ktor adapters generation     compileOnly(\"io.ktor:ktor-client-cio:1.5.4\") }<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0434\u043b\u044f <strong>Maven<\/strong> \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u0430:<\/p>\n<pre><code class=\"xml\">&lt;project>     &lt;build>         &lt;plugins>             &lt;plugin>                 &lt;groupId>io.github.ermadmi78&lt;\/groupId>                 &lt;artifactId>kobby-maven-plugin&lt;\/artifactId>                 &lt;version>${kobby.version}&lt;\/version>                 &lt;executions>                     &lt;execution>                         &lt;phase>generate-sources&lt;\/phase>                         &lt;goals>                             &lt;goal>generate-kotlin&lt;\/goal>                         &lt;\/goals>                     &lt;\/execution>                 &lt;\/executions>             &lt;\/plugin>         &lt;\/plugins>     &lt;\/build>      &lt;dependencies>         &lt;!--Add this dependency to enable-->         &lt;!--Jackson annotation generation in DTO classes-->         &lt;dependency>             &lt;groupId>com.fasterxml.jackson.core&lt;\/groupId>             &lt;artifactId>jackson-annotations&lt;\/artifactId>             &lt;version>${jackson.version}&lt;\/version>             &lt;scope>compile&lt;\/scope>         &lt;\/dependency>          &lt;!--Add this dependency to enable-->         &lt;!--default Ktor adapters generation-->         &lt;dependency>             &lt;groupId>io.ktor&lt;\/groupId>             &lt;artifactId>ktor-client-cio-jvm&lt;\/artifactId>             &lt;version>${ktor.version}&lt;\/version>             &lt;scope>compile&lt;\/scope>         &lt;\/dependency>     &lt;\/dependencies> &lt;\/project><\/code><\/pre>\n<p>Kobby \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u2014 <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Available-Gradle-Plugin-Settings\" rel=\"noopener noreferrer nofollow\">\u044f\u0432\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0432 \u043a\u043e\u0434\u0435<\/a> \u0438 \u043d\u0435\u044f\u0432\u043d\u0443\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0439. \u041c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0439, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a <a href=\"https:\/\/github.com\/FasterXML\/jackson\" rel=\"noopener noreferrer nofollow\">Jackson<\/a> \u0438 <a href=\"https:\/\/ktor.io\/\" rel=\"noopener noreferrer nofollow\">Ktor<\/a>. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, Kobby \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u0418, \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 Jackson, \u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 Jackson \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f DTO \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0438\u0445 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 JSON. \u0410 \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u0433\u0438\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 Ktor, \u0442\u043e \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 DSL \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430\u0445 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<hr\/>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 DSL<\/h2>\n<p>\u041c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0430\u0448 \u043f\u043b\u0430\u0433\u0438\u043d. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>gradle build<\/code> \u0434\u043b\u044f Gradle \u0438\u043b\u0438 <code>mvn compile<\/code> \u0434\u043b\u044f Maven, \u0438 \u043f\u043b\u0430\u0433\u0438\u043d \u043d\u0430\u0439\u0434\u0435\u0442 \u0444\u0430\u0439\u043b <code>cinema.graphqls<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 DSL \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1ba\/6db\/7cd\/1ba6db7cd37e95379f9fe277f0fc0d13.png\" width=\"547\" height=\"682\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1ba\/6db\/7cd\/1ba6db7cd37e95379f9fe277f0fc0d13.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043b\u0430\u0433\u0438\u043d \u0441\u043e\u0437\u0434\u0430\u043b \u0444\u0430\u0439\u043b <code>cinema.kt<\/code> \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>cinemaContextOf<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>CinemaContext<\/code>. \u042d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e DSL:<\/p>\n<pre><code class=\"kotlin\">fun cinemaContextOf(adapter: CinemaAdapter): CinemaContext =     CinemaContextImpl(adapter)<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>cinemaContextOf<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 &#8212; <code>CinemaAdapter<\/code>. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440? \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0438 \u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f GraphQL. \u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0443. \u0410 \u0430\u0434\u0430\u043f\u0442\u0435\u0440, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u044e \u0433\u0440\u044f\u0437\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442. \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c.<\/p>\n<p>\u041c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/ktor.io\/\" rel=\"noopener noreferrer nofollow\">Ktor<\/a> \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. GraphQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445 HTTP, \u0430 \u0441\u0435\u0430\u043d\u0441\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445 WebSocket:<\/p>\n<pre><code class=\"kotlin\">fun createKtorAdapter(): CinemaAdapter {     \/\/ Create Ktor http client     val client = HttpClient {         install(WebSockets)     }      \/\/ Create Jackson object mapper     val mapper = jacksonObjectMapper().registerModule(         ParameterNamesModule(JsonCreator.Mode.PROPERTIES)     )      \/\/ Create default implementation of CinemaAdapter     return CinemaCompositeKtorAdapter(         client = client,         httpUrl = \"http:\/\/localhost:8080\/graphql\",         webSocketUrl = \"ws:\/\/localhost:8080\/subscriptions\",         mapper = object : CinemaMapper {             override fun serialize(value: Any): String =                 mapper.writeValueAsString(value)              override fun &lt;T : Any> deserialize(                 content: String,                 contentType: KClass&lt;T>             ): T = mapper.readValue(content, contentType.java)         }     ) }<\/code><\/pre>\n<hr\/>\n<h2>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p>\u041c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0444\u0438\u043b\u044c\u043c \u0441 \u0430\u043a\u0442\u0435\u0440\u0430\u043c\u0438 \u043f\u043e \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443. \u0412 GraphQL \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">query {     film(id: 0) {         id         title         actors {             id             firstName             lastName         }     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f Kotlin \u043d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  val result = context.query {     film(id = 0L) {         id()         title()         actors {             id()             firstName()             lastName()         }     } }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>context.query<\/code> \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <code>suspend<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0430 \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a. \u0410 \u0447\u0442\u043e \u0436\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430? \u0412 GraphQL \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f JSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"film\": {       \"id\": \"0\",       \"title\": \"Amelie\",       \"actors\": [         {           \"id\": \"0\",           \"firstName\": \"Audrey\",           \"lastName\": \"Tautou\"         },         {           \"id\": \"1\",           \"firstName\": \"Mathieu\",           \"lastName\": \"Kassovitz\"         }       ]     }   } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u00ab\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439\u00bb \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 GraphQL \u0442\u0438\u043f\u043e\u0432 \u0438\u0437 \u0441\u0445\u0435\u043c\u044b:<\/p>\n<pre><code class=\"kotlin\">interface Query {     val film: Film?     val films: List&lt;Film> }  interface Mutation {     val createFilm: Film }  interface Subscription {     val filmCreated: Film }  interface Film {     val id: Long     val title: String     val actors: List&lt;Actor> }  interface Actor {     val id: Long     val firstName: String     val lastName: String? }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>context.query<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Query<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  val result = context.query {     film(id = 0L) {         id()         title()         actors {             id()             firstName()             lastName()         }     } }  result.film?.also { film ->     println(film.title)     film.actors.forEach { actor ->         println(\"  ${actor.firstName} ${actor.lastName}\")     } }<\/code><\/pre>\n<hr\/>\n<h2>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0439<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0438\u043b\u044c\u043c. GraphQL \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u043c\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">mutation {     createFilm(title: \"My Film\") {         id         title     } }<\/code><\/pre>\n<p>\u0418, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 JSON:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"createFilm\": {       \"id\": \"4\",       \"title\": \"My Film\"     }   } }<\/code><\/pre>\n<p>\u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u043a\u0430\u043a \u043d\u0430\u0448\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432 Kotlin:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  val result = context.mutation {     createFilm(title = \"My Film\") {         id()         title()     } }  result.createFilm.also { film ->     println(film.title) }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>context.mutation<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Mutation<\/code>, \u0438, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>context.query<\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <code>suspend<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u043d\u0430\u0448\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442.<\/p>\n<hr\/>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u043e\u043a<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c\u0441\u044f \u043d\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e \u043d\u043e\u0432\u044b\u0445 \u0444\u0438\u043b\u044c\u043c\u0430\u0445 \u0432 GraphQL:<\/p>\n<pre><code class=\"json\">subscription {     filmCreated {         id         title     } }<\/code><\/pre>\n<p>\u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 JSON \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"filmCreated\": {       \"id\": \"4\",       \"title\": \"My Film\"     }   } }<\/code><\/pre>\n<p>\u0421\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0432 Kotlin \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>context.query<\/code> \u0438 <code>context.mutation<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u043e\u0442\u0432\u0435\u0442, \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043e\u043b\u0433\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0430\u043d\u0441 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  launch(Dispatchers.Default) {     context.subscription {         filmCreated {             id()             title()         }     }.subscribe {         while (true) {             val result = receive()             result.filmCreated.also { film ->                 println(film.title)             }         }     } }<\/code><\/pre>\n<p>\u041d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0439\u0442\u0435\u0441\u044c, \u043c\u044b \u043d\u0435 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>subscribe<\/code> \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>receive<\/code> \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <code>suspend<\/code>.<\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0435\u0430\u043d\u0441\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0442\u0430\u043a\u043e\u0435 \u0436\u0435, \u043a\u0430\u043a \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>subscribe<\/code>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0430\u043d\u0441, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u043d\u0435\u0435, \u0441\u0435\u0430\u043d\u0441 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>receive<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Subscription<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<hr\/>\n<h2>\u041e \u0447\u0435\u043c \u044f \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435?<\/h2>\n<ul>\n<li>\n<p>\u042f \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b, <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Gradle-GraphQL-Scalar-Mapping\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 Kotlin \u0434\u043b\u044f GraphQL \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432<\/a>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0441\u0445\u0435\u043c\u0435.<\/p>\n<\/li>\n<li>\n<p>\u042f \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Support-for-GraphQL-Abstract-Data-Types\" rel=\"noopener noreferrer nofollow\">Kobby \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u042f \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b, \u043a\u0430\u043a <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Client-DSL-Customization\" rel=\"noopener noreferrer nofollow\">\u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 DSL \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432<\/a> GraphQL.<\/p>\n<\/li>\n<li>\n<p>\u042f \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/GraphQL-Java-Kickstart-support\" rel=\"noopener noreferrer nofollow\">\u043f\u043b\u0430\u0433\u0438\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/a>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418, \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u044f \u043d\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a\u0430 \u0438 <a href=\"https:\/\/kotlinlang.ru\/docs\/reference\/extensions.html\" rel=\"noopener noreferrer nofollow\">\u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f Kotlin<\/a> \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 DSL \u0432 rich domain model \u043d\u0430 \u0441\u0442\u0435\u0440\u043e\u0438\u0434\u0430\u0445. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/587388\/\"> https:\/\/habr.com\/ru\/articles\/587388\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption>\u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u0435 REST, \u043e\u0447\u0435\u043d\u044c \u0441\u043a\u043e\u0440\u043e \u0440\u0430\u0437\u043e\u0440\u0438\u0442\u0435\u0441\u044c&#8230; \u0421\u043b\u043e\u0432\u043e \u00abKotlin\u00bb \u0438 \u0441\u043b\u043e\u0432\u043e \u00abGraphQL\u00bb \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435!<\/figcaption><\/figure>\n<p>\u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, GraphQL \u0441\u0445\u0435\u043c\u0430 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0435\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439, Kotlin \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u0440\u044f\u0441\u0430\u044e\u0449\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 (DSL). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u044f\u0437\u044b\u043a \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 GraphQL \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u043e\u0439. \u041d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u044d\u0442\u043e \u0441\u0438\u0437\u0438\u0444\u043e\u0432 \u0442\u0440\u0443\u0434. \u041b\u0443\u0447\u0448\u0435 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0418 \u0432 \u044d\u0442\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 <a href=\"https:\/\/github.com\/ermadmi78\/kobby\" rel=\"noopener noreferrer nofollow\"><strong>\u043f\u043b\u0430\u0433\u0438\u043d Kobby<\/strong><\/a>. \u041e\u043d \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 GraphQL \u0441\u0445\u0435\u043c\u0443 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 DSL. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u0434\u0435\u043b\u0435!<\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435?<\/summary>\n<div class=\"spoiler__content\">\n<p><code>GraphQL<\/code>:<\/p>\n<pre><code class=\"json\">query {   film(id: 0) {     id     title     actors {       id       firstName       lastName     }   } }<\/code><\/pre>\n<p><code>Kotlin<\/code>:<\/p>\n<pre><code class=\"kotlin\">val result = context.query {     film(id = 0L) {         id()         title()         actors {             id()             firstName()             lastName()         }     } }<\/code><\/pre>\n<p><code>GraphQL<\/code>:<\/p>\n<pre><code class=\"json\">mutation {   createFilm(title: \"My Film\") {     id     title   } }<\/code><\/pre>\n<p><code>Kotlin<\/code>:<\/p>\n<pre><code class=\"kotlin\">val result = context.mutation {     createFilm(title = \"My Film\") {         id()         title()     } }<\/code><\/pre>\n<p><code>GraphQL<\/code>:<\/p>\n<pre><code class=\"json\">subscription {   filmCreated {     id     title   } }<\/code><\/pre>\n<p><code>Kotlin<\/code>:<\/p>\n<pre><code class=\"kotlin\">launch(Dispatchers.Default) {     context.subscription {         filmCreated {             id()             title()         }     }.subscribe {         while (true) {             val result = receive()         }     } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 <a href=\"https:\/\/github.com\/ermadmi78\/kobby-gradle-tutorial\" rel=\"noopener noreferrer nofollow\"><strong>Kobby Gradle Tutorial<\/strong><\/a> \u0438 <a href=\"https:\/\/github.com\/ermadmi78\/kobby-maven-tutorial\" rel=\"noopener noreferrer nofollow\"><strong>Kobby Maven Tutorial<\/strong><\/a>.<\/p>\n<hr\/>\n<h2>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441\u043e \u0441\u0445\u0435\u043c\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Gradle-GraphQL-Schema-Location\" rel=\"noopener noreferrer nofollow\">Kobby \u0438\u0449\u0435\u0442 GraphQL \u0441\u0445\u0435\u043c\u0443<\/a> \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <code>graphqls<\/code> \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u0445\u0435\u043c\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 <code>cinema.graphqls<\/code>:<\/p>\n<pre><code class=\"json\">type Query {     film(id: ID!): Film     films: [Film!]! }  type Mutation {     createFilm(title: String!): Film! }  type Subscription {     filmCreated: Film! }  type Film {     id: ID!     title: String!     actors: [Actor!]! }  type Actor {     id: ID!     firstName: String!     lastName: String }<\/code><\/pre>\n<p>\u042d\u0442\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0438\u0434\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 GraphQL &#8212; \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0430\u043c \u043f\u043b\u0430\u0433\u0438\u043d. \u0414\u043b\u044f <strong>Gradle<\/strong> \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"kotlin\">plugins {     kotlin(\"jvm\")     id(\"io.github.ermadmi78.kobby\") version \"1.3.0\" }  dependencies {     \/\/ Add this dependency to enable      \/\/ Jackson annotation generation in DTO classes     compileOnly(\"com.fasterxml.jackson.core:jackson-annotations:2.12.2\")      \/\/ Add this dependency to enable      \/\/ default Ktor adapters generation     compileOnly(\"io.ktor:ktor-client-cio:1.5.4\") }<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0434\u043b\u044f <strong>Maven<\/strong> \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u0430:<\/p>\n<pre><code class=\"xml\">&lt;project>     &lt;build>         &lt;plugins>             &lt;plugin>                 &lt;groupId>io.github.ermadmi78&lt;\/groupId>                 &lt;artifactId>kobby-maven-plugin&lt;\/artifactId>                 &lt;version>${kobby.version}&lt;\/version>                 &lt;executions>                     &lt;execution>                         &lt;phase>generate-sources&lt;\/phase>                         &lt;goals>                             &lt;goal>generate-kotlin&lt;\/goal>                         &lt;\/goals>                     &lt;\/execution>                 &lt;\/executions>             &lt;\/plugin>         &lt;\/plugins>     &lt;\/build>      &lt;dependencies>         &lt;!--Add this dependency to enable-->         &lt;!--Jackson annotation generation in DTO classes-->         &lt;dependency>             &lt;groupId>com.fasterxml.jackson.core&lt;\/groupId>             &lt;artifactId>jackson-annotations&lt;\/artifactId>             &lt;version>${jackson.version}&lt;\/version>             &lt;scope>compile&lt;\/scope>         &lt;\/dependency>          &lt;!--Add this dependency to enable-->         &lt;!--default Ktor adapters generation-->         &lt;dependency>             &lt;groupId>io.ktor&lt;\/groupId>             &lt;artifactId>ktor-client-cio-jvm&lt;\/artifactId>             &lt;version>${ktor.version}&lt;\/version>             &lt;scope>compile&lt;\/scope>         &lt;\/dependency>     &lt;\/dependencies> &lt;\/project><\/code><\/pre>\n<p>Kobby \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u2014 <a href=\"https:\/\/github.com\/ermadmi78\/kobby\/wiki\/Available-Gradle-Plugin-Settings\" rel=\"noopener noreferrer nofollow\">\u044f\u0432\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0432 \u043a\u043e\u0434\u0435<\/a> \u0438 \u043d\u0435\u044f\u0432\u043d\u0443\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0439. \u041c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0439, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a <a href=\"https:\/\/github.com\/FasterXML\/jackson\" rel=\"noopener noreferrer nofollow\">Jackson<\/a> \u0438 <a href=\"https:\/\/ktor.io\/\" rel=\"noopener noreferrer nofollow\">Ktor<\/a>. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, Kobby \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u0418, \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 Jackson, \u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 Jackson \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f DTO \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0438\u0445 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u0437 JSON. \u0410 \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u0433\u0438\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 Ktor, \u0442\u043e \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 DSL \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430\u0445 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<hr\/>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 DSL<\/h2>\n<p>\u041c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0430\u0448 \u043f\u043b\u0430\u0433\u0438\u043d. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>gradle build<\/code> \u0434\u043b\u044f Gradle \u0438\u043b\u0438 <code>mvn compile<\/code> \u0434\u043b\u044f Maven, \u0438 \u043f\u043b\u0430\u0433\u0438\u043d \u043d\u0430\u0439\u0434\u0435\u0442 \u0444\u0430\u0439\u043b <code>cinema.graphqls<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 DSL \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435:<\/p>\n<figure class=\"bordered full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043b\u0430\u0433\u0438\u043d \u0441\u043e\u0437\u0434\u0430\u043b \u0444\u0430\u0439\u043b <code>cinema.kt<\/code> \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>cinemaContextOf<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>CinemaContext<\/code>. \u042d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u043e\u0439 \u0432\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e DSL:<\/p>\n<pre><code class=\"kotlin\">fun cinemaContextOf(adapter: CinemaAdapter): CinemaContext =     CinemaContextImpl(adapter)<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>cinemaContextOf<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440 &#8212; <code>CinemaAdapter<\/code>. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440? \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0438 \u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f GraphQL. \u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0443. \u0410 \u0430\u0434\u0430\u043f\u0442\u0435\u0440, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u044e \u0433\u0440\u044f\u0437\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442. \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0438\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u043e\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c.<\/p>\n<p>\u041c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/ktor.io\/\" rel=\"noopener noreferrer nofollow\">Ktor<\/a> \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. GraphQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445 HTTP, \u0430 \u0441\u0435\u0430\u043d\u0441\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445 WebSocket:<\/p>\n<pre><code class=\"kotlin\">fun createKtorAdapter(): CinemaAdapter {     \/\/ Create Ktor http client     val client = HttpClient {         install(WebSockets)     }      \/\/ Create Jackson object mapper     val mapper = jacksonObjectMapper().registerModule(         ParameterNamesModule(JsonCreator.Mode.PROPERTIES)     )      \/\/ Create default implementation of CinemaAdapter     return CinemaCompositeKtorAdapter(         client = client,         httpUrl = \"http:\/\/localhost:8080\/graphql\",         webSocketUrl = \"ws:\/\/localhost:8080\/subscriptions\",         mapper = object : CinemaMapper {             override fun serialize(value: Any): String =                 mapper.writeValueAsString(value)              override fun &lt;T : Any> deserialize(                 content: String,                 contentType: KClass&lt;T>             ): T = mapper.readValue(content, contentType.java)         }     ) }<\/code><\/pre>\n<hr\/>\n<h2>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p>\u041c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0444\u0438\u043b\u044c\u043c \u0441 \u0430\u043a\u0442\u0435\u0440\u0430\u043c\u0438 \u043f\u043e \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443. \u0412 GraphQL \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">query {     film(id: 0) {         id         title         actors {             id             firstName             lastName         }     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f Kotlin \u043d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  val result = context.query {     film(id = 0L) {         id()         title()         actors {             id()             firstName()             lastName()         }     } }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>context.query<\/code> \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <code>suspend<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0430 \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a. \u0410 \u0447\u0442\u043e \u0436\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430? \u0412 GraphQL \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f JSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"film\": {       \"id\": \"0\",       \"title\": \"Amelie\",       \"actors\": [         {           \"id\": \"0\",           \"firstName\": \"Audrey\",           \"lastName\": \"Tautou\"         },         {           \"id\": \"1\",           \"firstName\": \"Mathieu\",           \"lastName\": \"Kassovitz\"         }       ]     }   } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u00ab\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439\u00bb \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 GraphQL \u0442\u0438\u043f\u043e\u0432 \u0438\u0437 \u0441\u0445\u0435\u043c\u044b:<\/p>\n<pre><code class=\"kotlin\">interface Query {     val film: Film?     val films: List&lt;Film> }  interface Mutation {     val createFilm: Film }  interface Subscription {     val filmCreated: Film }  interface Film {     val id: Long     val title: String     val actors: List&lt;Actor> }  interface Actor {     val id: Long     val firstName: String     val lastName: String? }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>context.query<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Query<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  val result = context.query {     film(id = 0L) {         id()         title()         actors {             id()             firstName()             lastName()         }     } }  result.film?.also { film ->     println(film.title)     film.actors.forEach { actor ->         println(\"  ${actor.firstName} ${actor.lastName}\")     } }<\/code><\/pre>\n<hr\/>\n<h2>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0439<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0438\u043b\u044c\u043c. GraphQL \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u043c\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">mutation {     createFilm(title: \"My Film\") {         id         title     } }<\/code><\/pre>\n<p>\u0418, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 JSON:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"createFilm\": {       \"id\": \"4\",       \"title\": \"My Film\"     }   } }<\/code><\/pre>\n<p>\u042f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u043a\u0430\u043a \u043d\u0430\u0448\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432 Kotlin:<\/p>\n<pre><code class=\"kotlin\">\/\/ Instantiate DSL context val context = cinemaContextOf(createKtorAdapter())  val result = context.mutation {     createFilm(title = \"My Film\") {         id()         title()     } }  result.createFilm.also { film ->     println(film.title) }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>context.mutation<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>Mutation<\/code>, \u0438, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>context.query<\/code>, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <code>suspend<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u043d\u0430\u0448\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442.<\/p>\n<hr\/>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u043e\u043a<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c\u0441\u044f \u043d\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e \u043d\u043e\u0432\u044b\u0445 \u0444\u0438\u043b\u044c\u043c\u0430\u0445 \u0432 GraphQL:<\/p>\n<pre><code class=\"json\">subscription {     filmCreated {         id         title     } }<\/code><\/pre>\n<p>\u041f\u043e \u044d\u0442\u043e\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 JSON \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"json\">{   \"data\": {     \"filmCreated\": {       \"id\": \"4\",       \"title\": \"My Film\"     }   } }<\/code><\/pre>\n<p>\u0421\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 \u0432 Kotlin \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>context.query<\/code> \u0438 <code>context.mutati<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-404776","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/404776","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=404776"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/404776\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=404776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=404776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=404776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}