【问题标题】:Apollo Graphql interface - create sharable URL from queryApollo Graphql 界面 - 从查询中创建可共享的 URL
【发布时间】:2023-03-10 03:31:01
【问题描述】:

我有一个在 Node.JS 上使用 Apollo 引擎构建的 GraphQL API,该 API 包括一个指向 graphql 操场的 /graphiql 端点,我可以在其中生成如下示例的查询:

query {
  canonical(ref: "") {
    id
  }
}

我的问题是:如何生成包含上述查询的可共享 URL。 (例如:htttp://gql-endpoint.com/graphiql?query=...

这样做的动机是生成 URL,根据请求打开 graphiql 界面并将查询与响应并排显示。

感谢您的帮助。

【问题讨论】:

    标签: graphql apollo


    【解决方案1】:

    事实证明,实际上有一个非常简单的解决方案: 您可以在图形界面中按原样复制查询,并将其添加到?query=查询字符串参数中

    例如,给定端点http://gql-endpoint.com/graphiql,查询将如下所示:

    http://gql-endpoint.com/graphiql?query=COPY_PASTE_YOUR_QUERY_HERE.

    使用上面的例子,这看起来像:

    http://gql-endpoint.com/graphiql?query=query {
      canonical(ref: "") {
        id
      }
    }
    

    当在浏览器上使用时,会产生一个转义的 URL,类似于:

    http://gql-endpoint.com/graphiql?query=query%20{%20canonical(ref:%20%22%22)%20{%20id%20}%20}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-20
      • 2018-10-19
      • 1970-01-01
      • 2022-10-23
      • 2018-06-29
      • 2020-10-01
      • 2018-03-02
      • 2021-07-04
      相关资源
      最近更新 更多