【发布时间】:2019-09-27 16:04:28
【问题描述】:
我正在尝试在我的 react 应用程序中连接到 apollo-client,但在运行查询时出现错误 400。如果我在邮递员中使用相同的 url 和相同的查询,它工作得很好。谢谢各位
我已经尝试过使用 apollo-link 但无法正常工作。
const client = new ApolloClient({
uri: 'http://localhost:3000/graphql',
onError: (e) => { console.log(e) },
})
client.query({
query: gql`
{
contracts{
id
}
} `
}).then(data => console.log(`Query Result ${data}`))
浏览器出错!!
{operation: {…}, networkError: ServerError: Response not successful: Received status code 400
at throwServerError (http://loca…, graphQLErrors: undefined, forward: ƒ}forward: ƒ (op)graphQLErrors: undefinednetworkError: ServerError: Response not successful: Received status code 400
at throwServerError (http://localhost:3000/static/js/bundle.js:37934:17)
at http://localhost:3000/static/js/bundle.js:37959:13operation: {variables: {…}, extensions: {…}, operationName: null, query: {…}, setContext: ƒ, …}__proto__: Object
bundle.esm.js:60 Uncaught (in promise) Error: Network error: Response not successful: Received status code 400
at new ApolloError (bundle.esm.js:60)
at QueryManager.<anonymous> (bundle.esm.js:1184)
at step (tslib.es6.js:97)
at Object.next (tslib.es6.js:78)
at tslib.es6.js:71
at new Promise (<anonymous>)
at __awaiter (tslib.es6.js:67)
at bundle.esm.js:1147
at bundle.esm.js:1627
at Array.forEach (<anonymous>)
at bundle.esm.js:1626
at Map.forEach (<anonymous>)
at QueryManager../node_modules/apollo-client/bundle.esm.js.QueryManager.broadcastQueries (bundle.esm.js:1621)
at bundle.esm.js:1127
我只是想通过控制台记录查询结果以进行测试
【问题讨论】:
-
正如@Jhm 在下面对答案的评论中所说。在网络选项卡中检查您对请求的响应。它应该有更多信息。
标签: reactjs graphql apollo apollo-client