django-graphql-apollo-react-demo
django-graphql-apollo-react-demo copied to clipboard
Always return 400 error from /gql end-point
Dear Martin,
Thanks for this great tutorial. I'm trying to replicate this. It all works fine, except that at the point where I submit a query through apollo, the response is an error, here is the error I get from console.log:
Error: Network error: Response not successful: Received status code 400 at new ApolloError (http://mydomain.com:3000/static/js/bundle.js:3799:28) at ObservableQuery../node_modules/apollo-client/core/ObservableQuery.js.ObservableQuery.currentResult (http://mydomain.com:3000/static/js/bundle.js:2284:24) at GraphQL.dataForChild (http://mydomain.com:3000/static/js/bundle.js:18832:62) at GraphQL.render (http://mydomain.com:3000/static/js/bundle.js:18882:33) at finishClassComponent (http://mydomain.com:3000/static/js/bundle.js:27404:31) at updateClassComponent (http://mydomain.com:3000/static/js/bundle.js:27381:12) at beginWork (http://mydomain.com:3000/static/js/bundle.js:27756:16) at performUnitOfWork (http://mydomain.com:3000/static/js/bundle.js:29755:16) at workLoop (http://mydomain.com:3000/static/js/bundle.js:29819:26) at HTMLUnknownElement.callCallback (http://mydomain.com:3000/static/js/bundle.js:20073:14) at Object.invokeGuardedCallbackDev (http://mydomain.com:3000/static/js/bundle.js:20112:16) at invokeGuardedCallback (http://mydomain.com:3000/static/js/bundle.js:19969:27) at renderRoot (http://mydomain.com:3000/static/js/bundle.js:29897:7) at performWorkOnRoot (http://mydomain.com:3000/static/js/bundle.js:30545:24) at performWork (http://mydomain.com:3000/static/js/bundle.js:30498:7) at requestWork (http://mydomain.com:3000/static/js/bundle.js:30409:7) at scheduleWorkImpl (http://mydomain.com:3000/static/js/bundle.js:30263:11) at scheduleWork (http://mydomain.com:3000/static/js/bundle.js:30220:12) at Object.enqueueForceUpdate (http://mydomain.com:3000/static/js/bundle.js:25781:7) at GraphQL../node_modules/react/cjs/react.development.js.Component.forceUpdate (http://mydomain.com:3000/static/js/bundle.js:43047:16) at GraphQL.forceRenderChildren (http://mydomain.com:3000/static/js/bundle.js:18800:26) at next (http://mydomain.com:3000/static/js/bundle.js:18775:27) at Object.handleError [as error] (http://mydomain.com:3000/static/js/bundle.js:18779:32) at SubscriptionObserver.error (http://mydomain.com:3000/static/js/bundle.js:51335:20) at http://mydomain.com:3000/static/js/bundle.js:2523:82 at Array.forEach (
and here is part of my code: const client = new ApolloClient({ link: new HttpLink({ uri:'http://mydomain.com:8000/gql'}), credentials: 'same-origin', cache: new InMemoryCache() });
class App extends Component { render() { return ( <ApolloProvider client={client}> <Router>
- <Link to="/">Home</Link>
- <Link to="/login/">Login</Link>
- <Link to="/logout/">Logout</Link>
export default App
userlistview:
const query = gql{ user(id:"VXNlclR5cGU6MQ=="){ email } }
class UsersListView extends React.Component { render() { let {data}=this.props console.log(data) if (data.loading || !data.allUsers) { return
return (
<div>
{data}
</div>
)
}
}
Thank you so much
Another note, the same query works in graphiql, not sure when apollo submits it does not work.
actually, when I change the http-link to batch-http-link, it does the magic, not sure why.