Apollo-react:网络请求失败,状态为0

时间:2017-07-30 14:00:03

标签: cors cross-domain graphql react-apollo

我正在使用react-apollo和typescript构建一个简单的前端应用程序。 但是当我发送我的graphql请求时,尽管状态为200并且我的响应向我发送了我想要的数据,但是apollo会抛出一个错误。这是堆栈:

Error: Network error: Network request failed with status 0 - ""
at new ApolloError (C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\errors\ApolloError.js:32)
at ObservableQuery.currentResult (C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\ObservableQuery.js:76)
at GraphQL.dataForChild (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-apollo\react-apollo.browser.umd.js:491)
at GraphQL.render (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-apollo\react-apollo.browser.umd.js:534)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:795
at measureLifeCyclePerf (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:75)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:794)
at ReactCompositeComponentWrapper._renderValidatedComponent (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:821)
at ReactCompositeComponentWrapper._updateRenderedComponent (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:745)
at ReactCompositeComponentWrapper._performComponentUpdate (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:723)
at ReactCompositeComponentWrapper.updateComponent (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:644)
at ReactCompositeComponentWrapper.performUpdateIfNecessary (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactCompositeComponent.js:560)
at Object.performUpdateIfNecessary (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactReconciler.js:156)
at runBatchedUpdates (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactUpdates.js:150)
at ReactReconcileTransaction.perform (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\Transaction.js:143)
at ReactUpdatesFlushTransaction.perform (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\Transaction.js:143)
at ReactUpdatesFlushTransaction.perform (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactUpdates.js:89)
at Object.flushBatchedUpdates (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactUpdates.js:172)
at ReactDefaultBatchingStrategyTransaction.closeAll (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\Transaction.js:209)
at ReactDefaultBatchingStrategyTransaction.perform (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\Transaction.js:156)
at Object.batchedUpdates (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactDefaultBatchingStrategy.js:62)
at Object.enqueueUpdate (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactUpdates.js:200)
at enqueueUpdate (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactUpdateQueue.js:24)
at Object.enqueueForceUpdate (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-dom\lib\ReactUpdateQueue.js:156)
at GraphQL.ReactComponent.forceUpdate (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react\lib\ReactBaseClasses.js:85)
at GraphQL.forceRenderChildren (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-apollo\react-apollo.browser.umd.js:463)
at next (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-apollo\react-apollo.browser.umd.js:438)
at Object.handleError [as error] (C:\Users\Pierre\WebstormProjects\healthy\node_modules\react-apollo\react-apollo.browser.umd.js:442)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\ObservableQuery.js:300
at Array.forEach (<anonymous>)
at Object.error (C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\ObservableQuery.js:298)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\QueryManager.js:288
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\QueryManager.js:726
at Array.forEach (<anonymous>)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\QueryManager.js:723
at Array.forEach (<anonymous>)
at QueryManager.broadcastQueries (C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\QueryManager.js:720)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\QueryManager.js:66
at dispatch (C:\Users\Pierre\WebstormProjects\healthy\node_modules\redux\es\createStore.js:173)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\ApolloClient.js:187
at Object.dispatch (C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\store.js:18)
at C:\Users\Pierre\WebstormProjects\healthy\node_modules\apollo-client\core\QueryManager.js:239

以下是我的Apollo客户端的配置:

    const networkInterface = createNetworkInterface({
    uri: 'http://localhost:8080/graphql',
    opts: {
        mode: 'no-cors'
    }
});


    const client = new ApolloClient({
        networkInterface,
        connectToDevTools: true
    });

服务器有答案:

{
    "data": {
        "foods": [
            {
                "__typename": "Food",
                "category": "vegetables",
                "image": null,
                "name": "carrot",
                "season": [
                    "march"
                ]
            }
        ]
    }
}

0 个答案:

没有答案