{"id":378583,"date":"2024-06-11T09:00:12","date_gmt":"2024-06-11T09:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=378583"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-11T09:00:12","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=378583","title":{"rendered":"<span>\u0410\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f api \u0434\u043b\u044f RTK Query, graphql, postgraphile \u0438 postgresql<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440: \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0443\u0435\u043c\u044b\u0439 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/gitverse.ru\/eustatos\/learn-graphile\" rel=\"noopener noreferrer nofollow\"> \u0437\u0434\u0435\u0441\u044c <\/a><\/p>\n<p>\u041f\u0440\u0435\u0434\u0443\u0441\u043b\u043e\u0432\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u0438\u043c\u0435\u0435\u0442\u0441\u044f GraphQL API \u0441\u0435\u0440\u0432\u0435\u0440. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0435\u0433\u043e \u0430\u0434\u0440\u0435\u0441: <code>http:\/\/localhost:5001\/graphql<\/code>. \u041e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>postgraphile<\/code>. \u0415\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0438\u0436\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>vitejs<\/code> \u0438 <code>react<\/code><\/p>\n<pre><code>npm create vite@latest client -- --template react-ts <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 api RTK Query \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/the-guild.dev\/graphql\/codegen\/plugins\/typescript\/typescript-rtk-query\" rel=\"noopener noreferrer nofollow\">@graphql-codegen\/typescript-rtk-query<\/a><\/p>\n<p>\u0414\u043b\u044f \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c:<\/p>\n<pre><code>npm i -D @graphql-codegen\/cli \\ @graphql-codegen\/introspection \\ @graphql-codegen\/near-operation-file-preset \\ @graphql-codegen\/typescript-rtk-query \\ @rtk-query\/graphql-request-base-query <\/code><\/pre>\n<p>\u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <code>scripts<\/code> \u0432 <code>package.json<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c:<\/p>\n<pre><code>    \"graphql-codegen\": \"graphql-codegen --config codegen.yml\" <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043e\u0440\u043d\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0430\u0439\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <code>codegen.yaml<\/code>:<\/p>\n<pre><code class=\"yaml\">overwrite: true schema: \"http:\/\/localhost:5001\/graphql\" documents: \"src\/**\/*.graphql\" watchConfig:   usePolling: true   interval: 1000 generates:   src\/app\/services\/types.generated.ts:     plugins:       - typescript     config:       maybeValue: T # normally, this would be T | null, but our msw mock returns everything as nullable, so we want to force these as non-nullalbe   src\/:     preset: near-operation-file     presetConfig:       baseTypesPath: app\/services\/types.generated.ts     plugins:       - add:           content: >             \/* eslint-disable *\/             \/**              *              * THIS FILE IS AUTOGENERATED, DO NOT EDIT IT!              *              * instead, edit one of the `.graphql` files in this project and run              *              * npm run graphql-codegen              *              * for this file to be re-created              *\/       - typescript-operations       - typescript-rtk-query:           importBaseApiFrom: \"..\/..\/app\/services\/baseApi\"           exportHooks: true     config:       maybeValue: T # normally, this would be T | null, but our msw mock returns everything as nullable, so we want to force these as non-nullalbe   .introspection.json:     plugins:       - introspection <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src<\/code> \u0444\u0430\u0439\u043b\u043e\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u044b qraphql: query, mutation.<br \/> \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u044d\u0442\u043e \u0444\u0430\u0439\u043b\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src\/features\/todos<\/code>:<\/p>\n<pre><code>src\/features\/todos \u251c\u2500\u2500 createTodo.graphql \u251c\u2500\u2500 deleteTodo.graphql \u251c\u2500\u2500 getTodos.graphql \u2514\u2500\u2500 updateTodoById.graphql <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<br \/> \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>src\/app\/services\/baseApi.ts<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">import { createApi } from \"@reduxjs\/toolkit\/query\/react\"; import { graphqlRequestBaseQuery } from \"@rtk-query\/graphql-request-base-query\"; import { GraphQLClient } from \"graphql-request\";  export const client = new GraphQLClient(\"\/api\/graphql\");  export const api = createApi({   baseQuery: graphqlRequestBaseQuery({ client }),   endpoints: () => ({}), }); <\/code><\/pre>\n<p>\u0412 \u043f\u0430\u043f\u043a\u0435 <code>src\/features\/todos<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0430\u0439\u043b\u044b graphql \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<br \/> <code>createTodo.graphql<\/code><\/p>\n<pre><code>mutation createTodo($description: String = \"\") {   createTodo(input: { todo: { description: $description } }) {     todo {       description       id     }   } } <\/code><\/pre>\n<p><code>getTodos.graphql<\/code><\/p>\n<pre><code>query getTodos {   allTodos {     nodes {       id       description       completed     }   } } <\/code><\/pre>\n<p><code>deleteTodo.graphql<\/code><\/p>\n<pre><code>mutation deleteTodoById($id: Int = 10) {   deleteTodoById(input: { id: $id }) {     todo {       description       id     }   } } <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c:<\/p>\n<pre><code>npm run graphql-codegen <\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438:<\/p>\n<pre><code>> client@0.0.0 graphql-codegen > graphql-codegen --config codegen.yml  \u2714 Parse Configuration \u2714 Generate outputs <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<pre><code>src \u251c\u2500\u2500 app \u2502   \u2514\u2500\u2500 services \u2502       \u2514\u2500\u2500 types.generated.ts \u2514\u2500\u2500 features     \u2514\u2500\u2500 todos         \u251c\u2500\u2500 createTodo.generated.ts         \u251c\u2500\u2500 deleteTodo.generated.ts         \u251c\u2500\u2500 getTodos.generated.ts         \u2514\u2500\u2500updateTodoById.generated.ts <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/gitverse.ru\/eustatos\/learn-graphile\" rel=\"noopener noreferrer nofollow\"> \u0437\u0434\u0435\u0441\u044c <\/a><\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435:<\/p>\n<pre><code>docker-compose up -d <\/code><\/pre>\n<p>\u0410 \u0437\u0430\u0442\u0435\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>\/client<\/code>:<\/p>\n<pre><code>npm run dev <\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/820899\/\"> https:\/\/habr.com\/ru\/articles\/820899\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440: \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0443\u0435\u043c\u044b\u0439 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/gitverse.ru\/eustatos\/learn-graphile\" rel=\"noopener noreferrer nofollow\"> \u0437\u0434\u0435\u0441\u044c <\/a><\/p>\n<p>\u041f\u0440\u0435\u0434\u0443\u0441\u043b\u043e\u0432\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u0438\u043c\u0435\u0435\u0442\u0441\u044f GraphQL API \u0441\u0435\u0440\u0432\u0435\u0440. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0435\u0433\u043e \u0430\u0434\u0440\u0435\u0441: <code>http:\/\/localhost:5001\/graphql<\/code>. \u041e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>postgraphile<\/code>. \u0415\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0438\u0436\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>vitejs<\/code> \u0438 <code>react<\/code><\/p>\n<pre><code>npm create vite@latest client -- --template react-ts <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 api RTK Query \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/the-guild.dev\/graphql\/codegen\/plugins\/typescript\/typescript-rtk-query\" rel=\"noopener noreferrer nofollow\">@graphql-codegen\/typescript-rtk-query<\/a><\/p>\n<p>\u0414\u043b\u044f \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c:<\/p>\n<pre><code>npm i -D @graphql-codegen\/cli \\ @graphql-codegen\/introspection \\ @graphql-codegen\/near-operation-file-preset \\ @graphql-codegen\/typescript-rtk-query \\ @rtk-query\/graphql-request-base-query <\/code><\/pre>\n<p>\u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <code>scripts<\/code> \u0432 <code>package.json<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c:<\/p>\n<pre><code>    \"graphql-codegen\": \"graphql-codegen --config codegen.yml\" <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043e\u0440\u043d\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0430\u0439\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <code>codegen.yaml<\/code>:<\/p>\n<pre><code class=\"yaml\">overwrite: true schema: \"http:\/\/localhost:5001\/graphql\" documents: \"src\/**\/*.graphql\" watchConfig:   usePolling: true   interval: 1000 generates:   src\/app\/services\/types.generated.ts:     plugins:       - typescript     config:       maybeValue: T # normally, this would be T | null, but our msw mock returns everything as nullable, so we want to force these as non-nullalbe   src\/:     preset: near-operation-file     presetConfig:       baseTypesPath: app\/services\/types.generated.ts     plugins:       - add:           content: >             \/* eslint-disable *\/             \/**              *              * THIS FILE IS AUTOGENERATED, DO NOT EDIT IT!              *              * instead, edit one of the `.graphql` files in this project and run              *              * npm run graphql-codegen              *              * for this file to be re-created              *\/       - typescript-operations       - typescript-rtk-query:           importBaseApiFrom: \"..\/..\/app\/services\/baseApi\"           exportHooks: true     config:       maybeValue: T # normally, this would be T | null, but our msw mock returns everything as nullable, so we want to force these as non-nullalbe   .introspection.json:     plugins:       - introspection <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src<\/code> \u0444\u0430\u0439\u043b\u043e\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u044b qraphql: query, mutation.<br \/> \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u044d\u0442\u043e \u0444\u0430\u0439\u043b\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src\/features\/todos<\/code>:<\/p>\n<pre><code>src\/features\/todos \u251c\u2500\u2500 createTodo.graphql \u251c\u2500\u2500 deleteTodo.graphql \u251c\u2500\u2500 getTodos.graphql \u2514\u2500\u2500 updateTodoById.graphql <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<br \/> \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>src\/app\/services\/baseApi.ts<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">import { createApi } from \"@reduxjs\/toolkit\/query\/react\"; import { graphqlRequestBaseQuery } from \"@rtk-query\/graphql-request-base-query\"; import { GraphQLClient } from \"graphql-request\";  export const client = new GraphQLClient(\"\/api\/graphql\");  export const api = createApi({   baseQuery: graphqlRequestBaseQuery({ client }),   endpoints: () => ({}), }); <\/code><\/pre>\n<p>\u0412 \u043f\u0430\u043f\u043a\u0435 <code>src\/features\/todos<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0430\u0439\u043b\u044b graphql \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<br \/> <code>createTodo.graphql<\/code><\/p>\n<pre><code>mutation createTodo($description: String = \"\") {   createTodo(input: { todo: { description: $description } }) {     todo {       description       id     }   } } <\/code><\/pre>\n<p><code>getTodos.graphql<\/code><\/p>\n<pre><code>query getTodos {   allTodos {     nodes {       id       description       completed     }   } } <\/code><\/pre>\n<p><code>deleteTodo.graphql<\/code><\/p>\n<pre><code>mutation deleteTodoById($id: Int = 10) {   deleteTodoById(input: { id: $id }) {     todo {       description       id     }   } } <\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c:<\/p>\n<pre><code>npm run graphql-codegen <\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438:<\/p>\n<pre><code>> client@0.0.0 graphql-codegen > graphql-codegen --config codegen.yml  \u2714 Parse Configuration \u2714 Generate outputs <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<pre><code>src \u251c\u2500\u2500 app \u2502   \u2514\u2500\u2500 services \u2502       \u2514\u2500\u2500 types.generated.ts \u2514\u2500\u2500 features     \u2514\u2500\u2500 todos         \u251c\u2500\u2500 createTodo.generated.ts         \u251c\u2500\u2500 deleteTodo.generated.ts         \u251c\u2500\u2500 getTodos.generated.ts         \u2514\u2500\u2500updateTodoById.generated.ts <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/gitverse.ru\/eustatos\/learn-graphile\" rel=\"noopener noreferrer nofollow\"> \u0437\u0434\u0435\u0441\u044c <\/a><\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435:<\/p>\n<pre><code>docker-compose up -d <\/code><\/pre>\n<p>\u0410 \u0437\u0430\u0442\u0435\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>\/client<\/code>:<\/p>\n<pre><code>npm run dev <\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/820899\/\"> https:\/\/habr.com\/ru\/articles\/820899\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-378583","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378583","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=378583"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/378583\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}