我在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 /。对此有什么帮助吗?
发布于 2019-01-11 19:18:49
由于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文件是一个很好的入门位置。
https://stackoverflow.com/questions/54144178
复制相似问题