首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用postgraphile连接数据库

无法使用postgraphile连接数据库
EN

Stack Overflow用户
提问于 2019-01-11 18:00:14
回答 1查看 573关注 0票数 0

我在pgadmin中有一个数据库,名为"mydatabase“,表名为"mytable”。它在http://127.0.0.1:33859/browser/中运行。我试着用postgraphile和它联系起来。以下是代码

代码语言:javascript
复制
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 /。对此有什么帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-11 19:18:49

由于PostGraphile中间件预计将与Node.js应用程序的其余部分一起挂载,因此它不会接管根URL,而是在缺省情况下使GraphQL端点在/graphql上可用。要更改这一点,可以使用graphqlRoutegraphiqlRoute选项documented in the Library Usage page

这里有一些很好的选项可以让你入门:

代码语言:javascript
复制
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文件是一个很好的入门位置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54144178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档