postgresql - 无法使用 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 端点可用。要更改这一点,请在 Library Usage 页面中记录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文件是开始的好地方。
推荐阅读
- python - 使用 pip 安装软件包有效,但使用 setuptools 不适用于本地 pypi
- python - 使用 pyomo.environ 创建多元分段函数
- python - 未来从未检索到任务异常:
我有一个以内联模式发送星座的机器人代码:
import re from aiogram.types import InputTextMessageContent, InlineQuery, InlineQueryResultArt
- java - 在 Thymeleaf 模板中使用 @ManyToOne 值 - 属性 '' 不可读或具有无效的 getter 方法是否 getter 的返回类型
- rust - 意外的 tokio::task::spawn_blocking 行为
- angular - 为什么 Angular 会覆盖 idex.html 中的 base-href
- sql - 查找成功和失败记录的总数
- python - 如何使用此脚本抓取多个页面?
- npm - npm publish :更新版本而不更改最新版本
- elasticsearch - Elasticsearch:查找值在两个字段值之间的记录