【问题标题】:How to access postgraphile route inside the server如何访问服务器内部的 postgraphile 路由
【发布时间】:2020-07-21 00:03:52
【问题描述】:

我在我的服务器中创建了 postgraphile 路由,在我的 app.ts 中有这一行: app.use(postgraphileRoute) 现在,我想在我的存储库中访问此路由。 我正在使用 graphql-request 包,但我不知道我在发送 new GraphQLClient() 时发送哪个 url 我尝试发送 serverURL/graphql(我从客户端访问它的方式)但它不起作用。 我需要发送哪个网址?

【问题讨论】:

    标签: postgresql graphql graphql-js postgraphile


    【解决方案1】:

    路由默认为/graphql,但您可以使用graphqlRoute 属性对其进行配置。另请参阅docs

    const express = require("express");
    const { postgraphile } = require("postgraphile");
    
    const app = express();
    
    const postgraphileRoute = postgraphile(
        process.env.DATABASE_URL || "postgres://user:pass@host:5432/dbname",
        "public",
        {
          watchPg: true,
          graphiql: true,
          enhanceGraphiql: true,
          graphqlRoute: '/graphql' // Set to any route you like
        }
    );
    
    app.use(postgraphileRoute);
    
    app.listen(process.env.PORT || 3000);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 2018-04-12
      • 2019-07-19
      相关资源
      最近更新 更多