received status code 204 (no content)
See original GitHub issueI am using Apollo client with react in the front end running on port 3001. In the back end I am running node/express on port 3000.
In the front end, I have a nav bar that is supposed to run a query and get the user data. When I look at the chrome devtools / network I see something like this:
I am not sure why there is a fetch & json at the same time and why the fetch is coming back with response of 204 (empty content). Shouldn’t I only get a fetch with 200 and no json request.
Here is my config in the front end:
const networkInterface = createNetworkInterface({
uri: '//localhost:3000/graphql' // pointing to the backend server at port 3000
});
networkInterface.use([{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}; // Create the header object if needed.
}
// get the authentication token from local storage if it exists
const token = localStorage.getItem('token');
req.options.headers.authorization = token ? `Bearer ${token}` : '';
next();
}
}]);
const client = new ApolloClient({
dataIdFromObject: o => o.id,
networkInterface
});
const reducers = combineReducers({
apollo: client.reducer()
});
const store = createStore(
reducers,
composeWithDevTools(applyMiddleware(client.middleware()))
);
Here is my code for the navbar:
const query = gql`
query {
user {
id
email
}
}
`;
export default connect(null, actions)(graphql(query)(NavBar));
And here are snippets code at the backend server:
app.use('/graphql', expressGraphQL({
schema,
graphiql: true
}));
Here is the queryType in the backend. I am returning an object just for testing. I tried to wrap the object with Promise but I get the same result.
const RootQueryType = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: UserType,
resolve(parentValue, args, req) {
return {id: "234324", email: "test@test.com"};
}
}
}
});
When I try the query in graphiql, things seems to work fine.
Could you please help me figure this out. Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
Top GitHub Comments
I am also facing same issue. Getting data from graphiql editor but getting 204 (no content) from apollo client 2.0
Facing the same issue, Anyone found any solution ?