批处理apollo-graphql查询

时间:2019-01-24 16:52:56

标签: reactjs apollo react-apollo apollo-link

我无法使用BatchHttpLink通过非常简单的apollo-graphql配置来批量查询。网络出现错误。

当我使用BatchHttpLink时,任何查询在javascript中都会失败。它在网络中不会失败。

查询示例:

query QueryCurrencies { currencies { name id } }

它返回,在“网络”标签中:

{
  "graphql": [
    {
      "data": {
        "currencies": [
          {
            "name": "peseta",
            "id": 3
          }
        ]
      }
    }
  ]
}

但是在javascript中,Query hoc不返回任何数据,而是返回错误消息"Network error: Server response was missing for query 'QueryCurrencies'."

const cache = new InMemoryCache()
const httpLink = new HttpLink({
    uri: '/store/api/graphql'
})
const batchHttpLink = new BatchHttpLink({
    uri: '/store/api/graphql'
})
const stateLink = withClientState({
    cache,
    defaults,
    resolvers
});
const apolloClient = new ApolloClient({
    link: stateLink.concat(batchHttpLink),
    cache
});

ReactDOM.render(
    <ApolloProvider client={ apolloClient }>
        <Query query={ gql`query QueryCurrencies { currencies { name id } }` }>
            {
                ({ data }) => {
                    debugger
                    return <h1>Hi</h1>
                }
            }
        </Query>
    </ApolloProvider>,
    document.getElementById('app')
)

预期结果是获取数据且没有错误。实际结果是错误,没有数据。

我在做什么错了?

0 个答案:

没有答案