【问题标题】:How to change graphql endpoint url name如何更改 graphql 端点 url 名称
【发布时间】:2018-09-07 23:29:32
【问题描述】:

我刚刚开始使用带有 apollo 客户端的 graphql,我已经设置了 graphql 服务器并且正在运行 localhost:4000,这是我的客户端

index.js

const client = new ApolloClient({
    uri: "http://localhost:4000/graphql",
    cache: new InMemoryCache()
});

blog.js

const GET_BLOG = gql`
  {
    post(id:"5ab2b46d941953bf614e2617") {
        title
        body
        user {
            name
            email
        }
    }
  }
 <Query query={GET_BLOG}>...</Query>

我让一切正常,我的问题是我可以更改 graphql 端点 url 名称,所以我可以有 /graphql/post、/graphql/user 之类的东西,而不是 graphql,我在 graphql 服务器中有方案,但如果我打两个电话,它只会在网络选项卡中返回两个 /graphql

【问题讨论】:

    标签: javascript reactjs graphql react-apollo


    【解决方案1】:
    SERVER.applyMiddleware({
      app: APP, 
      path: '/newEndPoint'
    });
    

    在 applyMiddleWare 选项对象中设置路径属性。现在访问 localhost:&lt;port&gt;/newEndPoint 抓住机会

    【讨论】:

      【解决方案2】:

      据我所知,graphql 只使用一个端点 url 名称,在你的情况下是 http://localhost:4000/graphql ,如果你想要单独的端点,它就像 REST 路由

      【讨论】:

        猜你喜欢
        • 2020-09-17
        • 2019-02-11
        • 1970-01-01
        • 2017-02-28
        • 1970-01-01
        • 2014-09-21
        • 2020-03-06
        • 2011-05-09
        • 2018-02-10
        相关资源
        最近更新 更多