【问题标题】:How to set a base url in a springboot graphql app如何在 springboot graphql 应用程序中设置基本 url
【发布时间】:2019-07-05 08:56:09
【问题描述】:

我们如何在 springboot graphql-server app 中设置基本 url。 默认情况下,graphiql api-console 在http://localhost:8080/graphiql 上打开

尝试通过邮递员访问http://localhost:8080,并使用如下后查询:

{
    bookings {
        name
    }
}

给出一个错误说:

{
    "timestamp": 1549913598497,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/"
}
  1. Q1 我应该用来调用它的服务器的路径应该是什么。
  2. Q2 有没有一种方法可以提供自定义基本路径,例如 http://localhost:8080/service/api/query

【问题讨论】:

    标签: spring-boot graphql


    【解决方案1】:
    1. 通常,graphql 端点的服务器路径位于 http://localhost:8080/graphql。如果在 GraphiQL 界面上运行查询时不只是检查浏览器上的网络选项卡,它将在 api 端点上运行查询。

    2. 要更改基本路径,您需要将 application.properties 更改为:

        graphql.servlet.mapping: /service/api/query
    
        graphiql.mapping: /graphiql
        graphiql.endpoint: /service/api/query
    

    【讨论】:

    • @TarunPatel 你应该在你的问题上指定版本。第一个问题的答案应该是正确的。
    • :update .. 我的坏.. 跨 graphql 和 speingboot 的 jars/版本冲突有一些问题,这对我来说是个问题。已将您的答案标记为正确。感谢您的帮助
    • 对于我来说,application.properties 中的 graphql.url = /test 有效,所以 URL 将类似于:localhost:8080/testgraphql-java-spring-boot-starter-webmvc, version 2019-06-24T11-47-27-31ab4f9
    猜你喜欢
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 2020-03-24
    • 2013-03-09
    相关资源
    最近更新 更多