[英]Can't connect database with postgraphile
我在pgadmin中有一个数据库,名称为“ mydatabase”,表名为“ mytable”。 它在http://127.0.0.1:33859/browser/
运行。 我正在尝试使用后石墨与之联系。 这是代码
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
选项。
以下是一些入门的好选择:
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文件是入门的好地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.