我在 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
选项。
这里有一些不错的选择可以帮助您入门:
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文件是开始的好地方。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句