Apollo Server ALWAYS returns 404 when queried from node.js
See original GitHub issue“apollo-server”: “^2.9.7”,
When querying my Apollo Server from Node.js I always receive 404 response with no further information. The Postman and curl works fine. I tried all possible options and nothing seems to work. As a result I cannot download introspection queries and my VSCODE plugins do not work.
This is my server code:
export function start(port = '4000') {
const server = new ApolloServer({
schema,
cors: {
origin: '*',
methods: 'GET,HEAD,POST'
},
context: req => initContext(req)
});
server.listen({ port }).then(() => console.log('Server is running on localhost:4000'));
}
This is WORKING curl query:
curl -X POST http://localhost:4000/graphql \
-H "Content-Type: application/json" \
-d '{"query": "query Roles { roles { description } }"}'
This is NOT working from node.js
const { createApolloFetch } = require('apollo-fetch');
const fetch = createApolloFetch({
uri: 'http://127.0.0.1:4000'
});
fetch.useAfter(({ response }, next) => {
console.log(response); // <--- WILL BE 404
next();
});
fetch({
query: 'query Roles { roles { description } }'
})
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Error handling - Apollo GraphQL Docs
If a request uses an invalid HTTP method ( GET with a mutation, or any HTTP method other than GET or POST ),...
Read more >Handling operation errors - Apollo GraphQL Docs
These are errors encountered while attempting to communicate with your GraphQL server, usually resulting in a 4xx or 5xx response status code (and...
Read more >Error handling - Apollo GraphQL Docs
A client sent the hash of a query string to execute via automatic persisted queries, but the server has disabled APQ. INTERNAL_SERVER_ERROR. None....
Read more >Full Stack Error Handling with GraphQL and Apollo
If networkError is present in your response, it means your entire query was rejected, and therefore no data was returned.
Read more >Fetching data with queries | Full-Stack Quickstart
This lets us use React Hooks to bind the results of GraphQL queries directly to our UI. Integrate with React. To connect Apollo...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also encountered something like this, where sending a request to my Next.js graphql endpoint responded correctly in the terminal with curl (and also when run with Next.js) but not when called in my node unit tests by jest.
Turns out my problem came from here (more specifically, here). For various reasons, the
url
of my request object didn’t end up being equal to thethis.graphqlPath
that it was expecting. Ensuringurl
was set properly fixed everything 😃@abernix thanks for your reply, although there is no need to be condescending. I did try spectrum. No response there for few days.
Moreover the examples you are showing … if I understand it right do the query to server from the browser (alas your request for a demo in code sandbox).
As I mentioned in my description I am trying to query the server from a node.js environment. So you need to run my query example from node. I tried with 2 machines with the same result. My package.json contains only Apollo-server and Apollo-fetch packages.
I’ll prepare a repo for it and test on more machines.