{"id":285825,"date":"2017-05-02T23:42:56","date_gmt":"2017-05-02T19:42:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285825"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285825","title":{"rendered":"GraphQL \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 Koa2 \u0438\u00a0MongoDB"},"content":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u041c\u0438\u0440! \u0421\u0435\u0440\u0432\u0435\u0440\u200a\u2014\u200a\u044d\u0442\u043e \u0441\u0435\u0440\u0434\u0446\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0431\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u043e\u0442 SPA, \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c Android + iOS \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f\u0441\u044c \u043b\u0438\u0448\u044c \u0432\u0430\u0448\u0435\u0439 \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u0435\u0439.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/327\/c90\/a69\/327c90a69bbe479cb5371d10eb944969.png\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0422\u043e\u0442 \u043a\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 GraphQL, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0443\u0437\u043d\u0430\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e. \u0422\u043e\u0442 \u043a\u0442\u043e \u0441\u043f\u0435\u0448\u0438\u0442, \u043c\u043e\u0436\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 <a href=\"https:\/\/github.com\/nikitamarcius\/koa2-graphql-mongodb\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 GitHub<\/a>. \u0422\u043e\u0442, \u043a\u0442\u043e \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d \u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0445\u043e\u0442\u044f \u0431\u044b \u0447\u0430\u0441\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0441\u043c\u043e\u0436\u0435\u0442 \u0441 \u043d\u0443\u043b\u0435\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0447\u0438\u0439 GraphQL \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u0435\u0435\u200a\u2014\u200a\u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0434\u0440\u0443\u0436\u0438\u0442\u0435 \u0441 node.js.<\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u00a0GraphQL<\/h2>\n<p>  GraphQL\u200a\u2014\u200a\u044d\u0442\u043e \u044f\u0437\u044b\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b Facebook \u0438 \u0430\u043d\u043e\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043b \u0432 2015 \u0433\u043e\u0434\u0443. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c, \u0443\u0434\u0430\u043b\u044f\u0442\u044c, \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u043a\u043e\u043b\u0435\u043d\u043a\u0430\u0445.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430<\/h2>\n<p>  <i>\u041a\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u043e\u0441\u043d\u043e\u0432\u0430\u043c\u0438 node.js, \u043c\u043e\u0436\u0435\u0442 \u0441\u043c\u0435\u043b\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b.<\/i><\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f Node.js 7.7.4+<br \/>  \u041f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438 \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"javascript\">node -v<\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0441\u043e\u043b\u044c \u0432\u044b\u0432\u0435\u043b\u0430 v7.7.4+\u00a0? \u041e\u0442\u043b\u0438\u0447\u043d\u043e.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u0445, \u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f:<\/p>\n<pre><code class=\"javascript\">npm  \/\/ \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u0441\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c i    \/\/ \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u043e \u043e\u0442 install -g   \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0443\u043b\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e init \/\/ \u0440\u0443\u0447\u043d\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 package.json init -y   \/\/ \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 package.json -D   \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b &quot;devDependencies&quot; -S   \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b &quot;dependencies&quot; package.json: &quot;devDependencies&quot; - \u0440\u0430\u0437\u0434\u0435\u043b \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 &quot;dependencies&quot;    - \u0440\u0430\u0437\u0434\u0435\u043b \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e mkdir test \/\/ \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 cd test \/\/ \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 package.json \u0432 \u043f\u0430\u043f\u043a\u0435 test npm init -y<\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u0443\u0434\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0430\u043b\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043f\u0430\u043a\u0435\u0442 nodemon:<\/p>\n<pre><code class=\"javascript\">npm i -g nodemon<\/code><\/pre>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u0441\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u041f\u0440\u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435, \u043f\u0430\u043a\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h2>\n<p>  <i>\u0423 \u0432\u0430\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043f\u0430\u043f\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0432 \u043d\u0435\u0439 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b package.json, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d nodemon\u00a0, \u043f\u0440\u043e\u0435\u043a\u0442 \u043e\u0442\u043a\u0440\u044b\u0442 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435 \u043a\u043e\u0434\u0430 \u0438\u043b\u0438 IDE? \u0427\u0443\u0434\u043d\u043e, \u043f\u043e\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/i><\/p>\n<p>  \u041e\u0442\u043a\u0440\u043e\u0435\u043c package.json \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u201dscripts\u201d, \u0443\u0434\u0430\u043b\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u201ctest\u201d \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u0443\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<pre><code class=\"javascript\">&quot;scripts&quot;: {   &quot;dev&quot;: &quot;nodemon .\/src\/main.js&quot; }, <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0430\u043f\u043a\u0443 sr\u0441\u00a0, \u0430 \u0432 \u043d\u0435\u0439 3 \u0444\u0430\u0439\u043b\u0430: main.js, server.js, db.js\u00a0.<\/p>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 server.js \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. main.js\u200a\u2014\u200a\u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. db.js\u200a\u2014\u200a\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 es2015 (es6), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f Babel \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 es6 \u0432 es5:<\/p>\n<pre><code class=\"javascript\">\/\/ babel-preset-es2015 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 es6 \u0432 es5 \/\/ babel-register \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0445\u043e\u0434\u0443 \/\/ babel-plugin-transform-runtime + babel-preset-stage-3  \/\/ \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e\u0437\u0436\u0435 npm i -D babel-register babel-preset-es2015 babel-preset-stage-3 babel-plugin-transform-runtime<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0444\u0430\u0439\u043b \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0.babelrc c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">{   &quot;presets&quot;: [     &quot;es2015&quot;,     &quot;stage-3&quot;   ],   &quot;plugins&quot;: [&quot;transform-runtime&quot;] }<\/code><\/pre>\n<p>  .babelrc\u200a\u2014\u200a\u044d\u0442\u043e \u0444\u0430\u0439\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 Babel, \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0412 main.js \u0434\u043e\u0431\u0430\u0432\u0438\u043c:<\/p>\n<pre><code class=\"javascript\">\/\/ babel-register \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 server.js require('babel-register'); require('.\/server');<\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043f\u0430\u043a\u0435\u0442 mongoose\u00a0, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 MongoDB.<\/p>\n<pre><code class=\"javascript\">npm i -S mongoose<\/code><\/pre>\n<p>  \u0412 \u0444\u0430\u0439\u043b db.js \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435:<\/p>\n<pre><code class=\"javascript\">import mongoose from 'mongoose'; mongoose.Promise = global.Promise; \/\/ \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414 \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0442\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435 \u0443\u0432\u0438\u0434\u0438\u043c:  \/\/ 'Connected to mongo server.' mongoose.connection.on('open', function (ref) {     console.log('Connected to mongo server.'); }); \/\/ \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u0411\u0414, \u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:  \/\/ 'Could not connect to mongo server!' + \u043e\u0448\u0438\u0431\u043a\u0438 mongoose.connection.on('error', function (err) {     console.log('Could not connect to mongo server!');     console.log(err); }); \/\/ \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a MongoDB \/\/ mongodb:\/\/username:password@host:port\/myDataBase mongoose.connect('mongodb:\/\/localhost:27017\/test');<\/code><\/pre>\n<p>  \u041d\u0430\u043f\u043e\u043c\u043d\u044e, mongoose \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043c\u043e\u0441\u0442, \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0438 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c MongoDB \u043c\u043e\u0436\u043d\u043e \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u0438\u043b\u0438 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u041f\u043e\u0438\u0441\u043a \u0432 Google:<i> free mongodb cloud<\/i> \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0435 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433. \u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u043a <a href=\"http:\/\/mongoosejs.com\/docs\/connections.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> mongoose.<\/p>\n<blockquote><p>\u0423 \u0441\u0435\u0431\u044f \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0411\u0414: mongodb:\/\/localhost:27017\/test\u00a0.<br \/>  \u0412 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0442 username \u0438 password, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 host: localhost\u00a0, \u043f\u043e\u0440\u0442: 27017, \u0438\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445: test\u00a0.  <\/p><\/blockquote>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u0444\u0430\u0439\u043b\u0443 server.js \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b:<\/p>\n<pre><code class=\"javascript\">\/\/ @next - \u044d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430 npm i -S koa koa-router@next koa-bodyparser@next graphql-server-koa<\/code><\/pre>\n<p>  \u0412 \u0441\u0430\u043c \u0444\u0430\u0439\u043b server.js \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0434:<\/p>\n<pre><code class=\"javascript\">\/\/ koa - node.js \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043d\u0430 \u0431\u0430\u0437\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440 \/\/ koa-router - \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \/\/ graphql-server-koa \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u0432\u044f\u0437\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c Koa \u0438 GraphQL import koa from 'koa'; \/\/ koa@2 import koaRouter from 'koa-router'; \/\/ koa-router@next import koaBody from 'koa-bodyparser'; \/\/ koa-bodyparser@next import {graphqlKoa, graphiqlKoa} from 'graphql-server-koa'; \/\/ \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 schema \u0436\u0434\u0435\u0442 \u043d\u0430\u0441 \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \/\/ db.js - \u0444\u0430\u0439\u043b \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a MongoDB import schema from '.\/data\/schema' import '.\/db' const app = new koa(); const router = new koaRouter(); const PORT = 3000; \/\/ koaBody is needed just for POST. app.use(koaBody()); \/\/ POST \u0438 GET \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0441\u0445\u0435\u043c\u0443 GraphQL router.post('\/graphql', graphqlKoa({schema: schema})); router.get('\/graphql', graphqlKoa({schema: schema})); \/\/ \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 localhost:3000\/graphiql router.get('\/graphiql', graphiqlKoa({endpointURL: '\/graphql'})); app.use(router.routes()); app.use(router.allowedMethods()); \/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0430 app.listen(PORT, () =&gt; {     console.log('Server is running on', 'localhost:' + PORT);     console.log('GraphiQL dashboard', 'localhost:' + PORT + '\/graphiql'); });<\/code><\/pre>\n<p>  \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u044d\u0442\u043e \u043e\u0441\u0438\u043b\u0438\u043b\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b. \u0412 \u0444\u0430\u0439\u043b\u0435 server.js \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"javascript\">\/\/import schema from '.\/data\/schema'; \/\/router.post('\/graphql', graphqlKoa({schema: schema})); \/\/router.get('\/graphql', graphqlKoa({schema: schema}));<\/code><\/pre>\n<p>  \u041c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u0441\u0445\u0435\u043c\u0443 GraphQL, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043a \u043c\u044b \u0438\u0437\u0431\u0435\u0436\u0438\u043c \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0441\u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0441\u043b\u0430\u0434\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0431\u043e\u0447\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"javascript\">npm run dev<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a MongoDB, \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435 \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"javascript\">&gt; nodemon .\/src\/main.js [nodemon] 1.11.0 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `node .\/src\/main.js` Sever is running on localhost:3000 GraphiQL dashboard localhost:3000\/graphiql Connected to mongo server.<\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438? \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e. \u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 <a href=\"https:\/\/github.com\/nikitamarcius\/koa2-graphql-mongodb\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442<\/a> \u043d\u0430 Github \u0438 \u0441\u0432\u0435\u0440\u044c\u0442\u0435 \u0444\u0430\u0439\u043b\u044b \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043f\u043e\u043a data \u0438\u00a0.idea\u00a0.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a, \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435:<\/p>\n<pre><code class=\"javascript\">http:\/\/localhost:3000\/graphiql<\/code><\/pre>\n<p>  \u0412\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 GraphiQL \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c? \u041e\u0442\u043b\u0438\u0447\u043d\u043e. <\/p>\n<blockquote><p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0435\u0440\u0435\u0440\u044b\u0432. \u041d\u0430\u043b\u0435\u0439\u0442\u0435 \u0441\u0435\u0431\u0435 \u043a\u043e\u0444\u0435 \u0438\u043b\u0438 \u0447\u0430\u0439, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f. \u041f\u043e\u0437\u0436\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0441\u0430\u043c\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c.<\/p><\/blockquote>\n<p>  <\/p>\n<h2>2 + 2 =\u00a0GraphQL<\/h2>\n<p>  <i>GraphQL\u200a\u2014\u200a\u043f\u0440\u043e\u0441\u0442 \u0438 \u044f \u043c\u043e\u0433\u0443 \u044d\u0442\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c.<\/i><\/p>\n<p>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e, \u0432\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u043b\u0443\u0448\u0430\u043b\u0438\u0441\u044c \u043c\u043e\u0435\u0433\u043e \u0441\u043e\u0432\u0435\u0442\u0430 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0441\u0435\u0431\u0435 \u0447\u0430\u0439 \u0438\u043b\u0438 \u043a\u043e\u0444\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0437\u0430 \u0432\u0430\u0441 \u044d\u0442\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u043a\u0430\u044f Jane Dohe.<\/p>\n<p>  \u0422\u0430\u043a, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u0435\u0439 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435: \u0447\u0430\u0439 \u0438\u043b\u0438 \u043a\u043e\u0444\u0435. Jane \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u0430\u043c\u0430 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0438 \u043f\u0440\u0438\u043d\u0435\u0441\u0442\u0438 \u0432\u0430\u043c. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0441\u0430\u0445\u0430\u0440 \u0438 \u043c\u043e\u043b\u043e\u043a\u043e \u0432 \u043d\u0430\u043f\u0438\u0442\u043e\u043a, Jane \u0432\u043e\u0437\u044c\u043c\u0435\u0442 \u0443 \u0441\u043e\u0441\u0435\u0434\u043a\u0438 \u0441\u0430\u0445\u0430\u0440, \u0430 \u0437\u0430 \u043c\u043e\u043b\u043e\u043a\u043e\u043c \u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043e \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430. \u0421\u0430\u043c\u0430 \u0432\u0441\u0435 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u0438\u0442 \u0438 \u0443\u0436\u0435 \u0432 \u0433\u043e\u0442\u043e\u0432\u043e\u043c \u0432\u0438\u0434\u0435 \u043f\u0440\u0438\u043d\u0435\u0441\u0435\u0442 \u0432\u0430\u043c, \u0432 \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0432\u044b \u043e\u0431 \u044d\u0442\u043e\u043c \u0435\u0435 \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b\u0438.<\/p>\n<p>  \u0423 Jane \u0435\u0441\u0442\u044c \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441, \u0441\u0430\u043c\u0430 \u043e\u043d\u0430 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0433\u0434\u0435 \u0431\u0440\u0430\u0442\u044c \u0441\u0430\u0445\u0430\u0440 \u0438 \u043c\u043e\u043b\u043e\u043a\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0439 \u043d\u0443\u0436\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0438 \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u043f\u0440\u043e\u0441\u044c\u0431\u0435 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 GraphQL \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Jane Dohe. \u0412\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u043e\u0442\u0432\u0435\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0437\u0430\u0445: MongoDB, MySQL, PostgreSQL. \u0421 \u043e\u0434\u043d\u0438\u043c \u043d\u044e\u0430\u043d\u0441\u043e\u043c, \u043a\u0430\u043a \u0438 Jane, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u0443\u0436\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c GraphQL \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u043a\u0430\u043a \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0442\u043a\u0443\u0434\u0430 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c.<\/p>\n<p>  \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 server.js, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442? \u041f\u043e\u0440\u0430 \u0440\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<pre><code class=\"javascript\">import schema from '.\/data\/schema'; router.post('\/graphql', graphqlKoa({schema: schema})); router.get('\/graphql', graphqlKoa({schema: schema}));<\/code><\/pre>\n<p>  \u0412 \u043f\u0430\u043f\u043a\u0435 src \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u0430\u043f\u043a\u0443 data\u00a0. \u0412 \u043f\u0430\u043f\u043a\u0435 data \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b schema.js \u0438 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043f\u0430\u043f\u043a\u0443 user \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f 3 \u0444\u0430\u0439\u043b\u0430: queries.js\u00a0, mutations.js \u0438 models.js\u00a0. <\/p>\n<p>  \u0412\u0441\u044f \u0441\u0445\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9eb\/cbd\/fb9\/9ebcbdfb946444da9477ae58cca3c4c4.png\"\/><\/p>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f. \u0423 Jane Dohe \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441: \u0435\u0439 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0441\u0430\u0445\u0430\u0440 \u0438 \u043c\u043e\u043b\u043e\u043a\u043e. \u0422\u0430\u043a \u0432\u043e\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 User, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 Users. \u041b\u044e\u0431\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 GraphQL \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f\u200a\u2014\u200aqueries \u0438 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 queries.js\u00a0.<\/p>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e queries, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f mutations \u0438 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 mutations.js\u00a0. \u041a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u0435: UserCreate, UserDelete, UserEdit.<\/p>\n<p>  Queries \u0438 mutations \u0438\u043c\u0435\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e, \u043f\u043e\u043c\u0438\u043c\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u200a\u2014\u200a\u0443 \u043d\u0438\u0445 \u043e\u0431\u0449\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p>  models.js\u200a\u2014\u200a\u044d\u0442\u043e \u0444\u0430\u0439\u043b \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u0445\u0435\u043c\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u043c\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0442\u0438\u043f\u044b, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f queries \u0438 mutations.<\/p>\n<p>  \u0422\u0438\u043f\u044b \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u0441\u0445\u0435\u043c\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u043c\u0435\u0435\u0442 \u0442\u0440\u0438 \u044f\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\u0422\u0438\u043f\u044b \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u044e\u0442 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0445 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043d\u0430 \u043f\u0443\u0442\u0438 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<li>\u0418\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u0434\u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u044d\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/li>\n<li>\u0412 \u0442\u0438\u043f\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0432\u0430\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0445 \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c.<\/li>\n<\/ul>\n<p>  \u0418\u043c\u0435\u043d\u043d\u043e \u0438\u0437-\u0437\u0430 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432, \u0434\u043b\u044f queries \u0438 mutations \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b.<\/p>\n<h2>GraphQL\u200a\u2014\u200aJust do\u00a0it!<\/h2>\n<p>  <i>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u044b \u0441 \u043a\u043e\u0434\u043e\u043c.<\/i><\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b GraphQL \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u044b, \u043c\u0443\u0442\u0430\u0446\u0438\u0439, \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">npm i -S graphql<\/code><\/pre>\n<p>  \u0421\u0445\u0435\u043c\u0430\u200a\u2014\u200a\u044d\u0442\u043e \u044f\u0434\u0440\u043e GraphQL \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e 1 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 queries \u0438 mutations.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u0434 \u0432 schema.js\u00a0:<\/p>\n<pre><code class=\"javascript\">import {     GraphQLObjectType,     GraphQLSchema } from 'graphql'; \/\/ \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c queries \u0438 mutations \u0438\u0437 \u043f\u0430\u043f\u043a\u0438 user import UserQueries from '.\/user\/queries' import UserMutations from '.\/user\/mutations' \/\/ \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c GraphQL \u0441\u0445\u0435\u043c\u0443 \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \/\/ \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d GraphQLObjectType export default new GraphQLSchema({     query: new GraphQLObjectType({         name: 'Query',      \/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u0438\u043c\u044f \u0434\u043b\u044f API \u0431\u0438\u0431\u043b\u0438\u0442\u0435\u043a\u0438         fields: UserQueries \/\/ \u043f\u043e\u043b\u044f \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 queries.js     }),     mutation: new GraphQLObjectType({         name: 'Mutation',         fields: UserMutations     }) });<\/code><\/pre>\n<p>  \u041e\u0442 \u0441\u0445\u0435\u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a models.js\u00a0:<\/p>\n<pre><code class=\"javascript\">import {     GraphQLObjectType,     GraphQLInputObjectType,     GraphQLNonNull,     GraphQLString,     GraphQLID } from 'graphql'; import mongoose from 'mongoose'; \/\/ \u0441\u0445\u0435\u043c\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 const schema = new mongoose.Schema({     firstName: {         type: String,     },     lastName: {         type: String,     } }); \/\/ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e User \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a \u043d\u0435\u0439 \u0441\u0445\u0435\u043c\u0443 export let UserModel = mongoose.model('User', schema); \/\/ \u0442\u0438\u043f \u0434\u043b\u044f queries export let UserType = new GraphQLObjectType({     name: 'User',     fields: {         _id: {             type: new GraphQLNonNull(GraphQLID)         },         firstName: {             type: GraphQLString         },         lastName: {             type: GraphQLString         }     } }); \/\/ \u0442\u0438\u043f \u0434\u043b\u044f mutations export let UserInput = new GraphQLInputObjectType({     name: &quot;UserInput&quot;,     fields: {         firstName: {             type: GraphQLString         },         lastName: {             type: GraphQLString         }     } });<\/code><\/pre>\n<p>  \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u043c\u044b \u0440\u0430\u043d\u0435\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043f\u043e\u043b\u044f\u0445 User \u0438 Users, \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.\u00a0\u041f\u043e\u0440\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b queries.js\u00a0:<\/p>\n<pre><code class=\"javascript\">import {     GraphQLID,     GraphQLList,     GraphQLNonNull } from 'graphql'; \/\/ \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 models.js import {UserModel, UserType, UserInput} from '.\/models'; \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f const User = {     type: UserType,  \/\/ \u0442\u0438\u043f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     args: {         \/\/ \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c         id: {                   name: 'id',             type: new GraphQLNonNull(GraphQLID)         }     },     \/\/ \u043c\u0435\u0442\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435     resolve (root, params, options) {         return UserModel             .findById(params.id)             .exec();  \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c JSON     } }; const Users = {     type: new GraphQLList(UserType),     args: {},      resolve (root, params, options) {         return UserModel             .find()             .exec();     } }; export default {     User: User,     Users: Users, }<\/code><\/pre>\n<p>  Mutations \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b queries. Queries \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0430 mutations \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u0434\u0438\u043d \u0437\u0430 \u043e\u0434\u043d\u0438\u043c. \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043a\u043e\u0434 \u0432 mutations.js\u00a0.<\/p>\n<pre><code class=\"javascript\">import {     GraphQLNonNull,     GraphQLBoolean, } from 'graphql'; import {UserModel, UserType, UserInput} from '.\/models'; const UserCreate = {     description: &quot;Create new user&quot;,     type: GraphQLBoolean,     args: {         data: {             name: &quot;data&quot;,             type: new GraphQLNonNull(UserInput)         }     },     async resolve (root, params, options) {         const userModel = new UserModel(params.data);         const newUser = await userModel.save(); if (!newUser) {             throw new Error('Error adding new user');         }         return true;     } }; export default {     UserCreate: UserCreate, }<\/code><\/pre>\n<p>  \u042f \u0432\u0430\u0441 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e! \u0412\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u0439 GraphQL \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0443\u043b\u044f. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0435\u0433\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"javascript\">npm run dev<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0442\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u043a \u0440\u0430\u0431\u043e\u0447\u0435\u043c\u0443 <a href=\"https:\/\/github.com\/nikitamarcius\/koa2-graphql-mongodb\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044e<\/a> Github. \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e\u043c, \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435:<\/p>\n<pre><code class=\"javascript\">http:\/\/localhost:3000\/graphiql<\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u043e\u043a\u043d\u0435, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0441\u0432\u043e\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">mutation firstMutation{   UserCreate(data: {firstName: &quot;John&quot;, lastName: &quot;Dohe&quot;}) } mutation secondMutation{   UserCreate(data: {firstName: &quot;Jane&quot;, lastName: &quot;Dohe&quot;}) }<\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435:<\/p>\n<pre><code class=\"javascript\">{   &quot;data&quot;: {     &quot;UserCreate&quot;: true   } }<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0430\u0433\u043e\u043c, \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 MongoDB:<\/p>\n<pre><code class=\"javascript\">{   Users{     firstName     lastName   } }<\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u0432\u0435\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"javascript\">{   &quot;data&quot;: {     &quot;Users&quot;: [       {         &quot;firstName&quot;: &quot;John&quot;,         &quot;lastName&quot;: &quot;Dohe&quot;       },       {         &quot;firstName&quot;: &quot;Jane&quot;,         &quot;lastName&quot;: &quot;Dohe&quot;       }     ]   } }<\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u0438\u043b\u0438 \u043d\u0430\u0448\u043b\u0438 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435. \u0422\u0430\u043a, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0432\u0435\u0449\u0435\u0439 \u043e node.js, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 Koa \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043a MongoDB, \u043f\u043e\u043b\u0443\u043b\u043e\u0441\u044c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0447\u0438\u0439 GraphQL \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043f\u043e\u0436\u0435\u043b\u0430\u043d\u0438\u044f, \u044f \u0441 \u0443\u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u0438\u0435\u043c \u043e\u0442\u0432\u0435\u0447\u0443 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<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:\/\/habrahabr.ru\/post\/327816\/\"> https:\/\/habrahabr.ru\/post\/327816\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u041c\u0438\u0440! \u0421\u0435\u0440\u0432\u0435\u0440\u200a\u2014\u200a\u044d\u0442\u043e \u0441\u0435\u0440\u0434\u0446\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0431\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u043e\u0442 SPA, \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c Android + iOS \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044f\u0441\u044c \u043b\u0438\u0448\u044c \u0432\u0430\u0448\u0435\u0439 \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u0435\u0439.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/327\/c90\/a69\/327c90a69bbe479cb5371d10eb944969.png\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-285825","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285825","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=285825"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285825\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}