无法将数据库与 postgraphile 连接
Can't connect database with postgraphile
我在 pgadmin 中有一个名为 "mydatabase" 的数据库,表名为 "mytable"。它在 http://127.0.0.1:33859/browser/
中运行。我试图使用 postgraphile 来连接它。这是代码
const express = require("express");
const { postgraphile } = require("postgraphile");
const app = express();
app.use(postgraphile("postgres://postgres:postgres@localhost:33859/mydatabase -s public"));
app.listen(3000);
我的超级用户用户名是 "postgres",密码是 "postgres"。该数据库由名为 "test" 且密码为“1234”的用户所有。 运行带node的脚本后,终端没有报错。当我点击端口 3000 时,它显示 Cannot GET /
。有什么帮助吗?
因为 PostGraphile 中间件预计会与您的 Node.js 应用程序的其余部分一起安装,它不会接管根 URL 而是使 GraphQL 端点在 /graphql
默认。要更改此设置,有 graphqlRoute
和 graphiqlRoute
选项 documented in the Library Usage page.
这里有一些不错的入门选项:
const isDev = process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "staging";
const DB = "postgres://postgres:postgres@localhost:33859/mydatabase -s public";
const SCHEMA = "public";
app.use(postgraphile(DB, SCHEMA, {
// Enable the GraphiQL IDE in development
graphiql: isDev,
// Add some enhancements (headers, formatting, etc)
enhanceGraphiql: isDev,
// Makes GraphiQL available at http://localhost:3000/ rather than /graphiql
graphiqlRoute: '/',
// Watch DB for changes
watchPg: isDev,
// Use JSON objects rather than strings
dynamicJson: true,
// Debugging
showErrorStack: isDev,
extendedErrors:
isDev
? [
"errcode",
"severity",
"detail",
"hint",
"positon",
"internalPosition",
"internalQuery",
"where",
"schema",
"table",
"column",
"dataType",
"constraint",
"file",
"line",
"routine",
]
: ["errcode"],
// For use with e.g. apollo-link-batch-http
enableQueryBatching: true,
}));
您可能会发现 bootstrap-react-apollo installPostGraphile.js 文件是开始的好地方。
我在 pgadmin 中有一个名为 "mydatabase" 的数据库,表名为 "mytable"。它在 http://127.0.0.1:33859/browser/
中运行。我试图使用 postgraphile 来连接它。这是代码
const express = require("express");
const { postgraphile } = require("postgraphile");
const app = express();
app.use(postgraphile("postgres://postgres:postgres@localhost:33859/mydatabase -s public"));
app.listen(3000);
我的超级用户用户名是 "postgres",密码是 "postgres"。该数据库由名为 "test" 且密码为“1234”的用户所有。 运行带node的脚本后,终端没有报错。当我点击端口 3000 时,它显示 Cannot GET /
。有什么帮助吗?
因为 PostGraphile 中间件预计会与您的 Node.js 应用程序的其余部分一起安装,它不会接管根 URL 而是使 GraphQL 端点在 /graphql
默认。要更改此设置,有 graphqlRoute
和 graphiqlRoute
选项 documented in the Library Usage page.
这里有一些不错的入门选项:
const isDev = process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "staging";
const DB = "postgres://postgres:postgres@localhost:33859/mydatabase -s public";
const SCHEMA = "public";
app.use(postgraphile(DB, SCHEMA, {
// Enable the GraphiQL IDE in development
graphiql: isDev,
// Add some enhancements (headers, formatting, etc)
enhanceGraphiql: isDev,
// Makes GraphiQL available at http://localhost:3000/ rather than /graphiql
graphiqlRoute: '/',
// Watch DB for changes
watchPg: isDev,
// Use JSON objects rather than strings
dynamicJson: true,
// Debugging
showErrorStack: isDev,
extendedErrors:
isDev
? [
"errcode",
"severity",
"detail",
"hint",
"positon",
"internalPosition",
"internalQuery",
"where",
"schema",
"table",
"column",
"dataType",
"constraint",
"file",
"line",
"routine",
]
: ["errcode"],
// For use with e.g. apollo-link-batch-http
enableQueryBatching: true,
}));
您可能会发现 bootstrap-react-apollo installPostGraphile.js 文件是开始的好地方。