Apollo-client: received status code 204 (no content)

Created on 24 Mar 2017  路  10Comments  路  Source: apollographql/apollo-client

I 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:

screen shot 2017-03-24 at 12 11 22 pm

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: "[email protected]"}; 
             }
        }
    }
});

When I try the query in graphiql, things seems to work fine.

screen shot 2017-03-24 at 12 33 19 pm

Could you please help me figure this out.
Thanks

Most helpful comment

I am also facing same issue. Getting data from graphiql editor but getting 204 (no content) from apollo client 2.0

All 10 comments

Hi @ablbol! I think this is a help question that would be better suited to stackoverflow.

@helfer might be nice to mention that we watch Stack Overflow closely on the apollo tag so you're just as likely to get an answer there!

I will ask all my questions there.
Thanks

@ablbol I have the same issue, how do you do to resolve that?

Same issue. Please open again.

I am also facing same issue. Getting data from graphiql editor but getting 204 (no content) from apollo client 2.0

Same issue. How did you resolve?

For future reference, it looks like it was related to our CORS settings within our GraphQL server not including the domain where the user is using the website.

Is there any particular solution? I have the same issue and really can't figure out what else to try.

the same issue, what is the solution?

Was this page helpful?
0 / 5 - 0 ratings