5分でNodeJSとPostgresで高速オートGraphicalサーバーを作る!


こんにちは世界!
あまりにも多くの私の最後のポストで大好き
今日、私はあなたに5分でNODEJSとPostgresデータベースで速い自動スキーマGraphicalサーバを取り付ける方法を示します.
最初のものはDockerでマウントPostgresデータベースです!
docker run --name mydb-postgres -e POSTGRES_PASSWORD=12345 -p 5432:5432 -d postgres  
(デフォルトのユーザは以下の通りです: Postgres、デフォルトDBはPostgresです).
dbeaverに接続してみると良いPostgres UIツールです
https://dbeaver.io/
さあ!
NodeJSプロジェクトのフォルダを作成する
mkdir awesome-graphql-server
cd awesome-graphql-server
NPMパッケージ
npm init
エクスプレスエクスプレス
PostGraileはPostgresの構造に基づいて、GraphSQLを自動スキーマ化するのに非常に良いツールです.
npm install express
npm install postgraphile
それで、あなたのインデックスに挿入しなければならない単純なコードです.js
touch index.js
nano index.js
インサート中
var express = require('express');

const {
    postgraphile
} = require("postgraphile");

var app = express();
app.use(
    postgraphile(
        process.env.DATABASE_URL || "postgres://postgres:[email protected]:5432/postgres",
        "public", {
            watchPg: true,
            graphiql: true,
            enhanceGraphiql: true,
        }
    )
);
app.listen(4000, () => console.log('go to for playground graphiql http://localhost:4000/graphiql'))
起動後
node index.js
そして、http://localhost:4000/graphiqlに行く
あなたのGraphSQL自動スキーマ遊び場へようこそ!
GraphSQLリクエストの終点は
http://localhost:4000/graphql
あなたのフィードバックのおかげで!