【发布时间】:2019-03-31 10:40:16
【问题描述】:
我无法理解 Apollo 客户端库,因为它无法按预期工作。它没有发送 GET HTTP 方法,而是发送 OPTIONS HTTP 方法,即使我已经使用 GET从 GraphQL 服务器检索数据。
const client = new ApolloClient({
link: ApolloLink.from([
new MeteorAccountsLink(),
new HttpLink({
uri: 'https://selo-comments.herokuapp.com/graphql',
useGETForQueries: true
})
]),
cache: new InMemoryCache()
});
来自浏览器的控制台日志:
OPTIONS https://selo-comments.herokuapp.com/graphql?query=%7B%0A%20%20comments(id%3A%20%22TFpQmhrDxQqHk2ryy%22)%20%7B%0A%20%20%20%20articleID%0A%20%20%20%20content%0A%20%20%20%20userId%0A%20%20%20%20createdAt%0A%20%20%20%20commentID%0A%20%20%20%20votes%0A%20%20%20%20blockedUsers%0A%20%20%20%20__typename%0A%20%20%7D%0A%7D%0A&variables=%7B%7D 405 (Method Not Allowed)
这显然意味着HTTP方法是不正确的,即使它的url中有查询参数。如果您使用 Postman 查询该 url,或者只是使用浏览器的地址栏导航到该 url,您将获得 GraphQL 数据。我必须使用https://cors-anywhere.herokuapp.com/ 才能成功执行查询。
我做错了什么?
【问题讨论】:
标签: javascript meteor graphql apollo-client