-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apollo Server ALWAYS returns 404 when queried from node.js #3476
Comments
Here is repro for you using latest apollo-server and example from apollo page: // server.js
const { ApolloServer, gql } = require('apollo-server');
// A schema is a collection of type definitions (hence "typeDefs")
// that together define the "shape" of queries that are executed against
// your data.
const typeDefs = gql`
# Comments in GraphQL strings (such as this one) start with the hash (#) symbol.
# This "Book" type defines the queryable fields for every book in our data source.
type Book {
title: String
author: String
}
# The "Query" type is special: it lists all of the available queries that
# clients can execute, along with the return type for each. In this
# case, the "books" query returns an array of zero or more Books (defined above).
type Query {
books: [Book]
}
`;
const books = [
{
title: 'Harry Potter and the Chamber of Secrets',
author: 'J.K. Rowling'
},
{
title: 'Jurassic Park',
author: 'Michael Crichton'
}
];
const resolvers = {
Query: {
books: () => books
}
};
const server = new ApolloServer({ typeDefs, resolvers });
// The `listen` method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
}); Run
This works:
This gives 404 const { createApolloFetch } = require('apollo-fetch');
const fetch = createApolloFetch({
uri: 'http://localhost:4000/graphql'
});
fetch.useAfter(({ response }, next) => {
console.log(response); // <--- WILL BE 404
next();
});
fetch({
query: 'query Books { books { title } }'
})
.then(res => {
console.log(res); // <--- WILL BE "{}"
}) |
I just tried the reproductions you provided in the second comment and they work perfectly for me, with the second returning the result of the query as expected: You can also see them working in these two glitches which work with each other: Server: https://glitch.com/edit/#!/better-chime Perhaps make sure that you have no other servers running on port 4000. If you continue to have problems, please share a runnable reproduction, preferably in an isolated environment like Glitch or CodeSandbox — rather than copy/pasted code samples which don't portray your |
@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. |
@tomitrescak I wasn't aiming to be or trying to be condescending (Further, I don't believe I said anything condescending, but that's obviously subjective.) What I am demonstrating is what I observed with your provided reproduction — which behaved the same in both environments I tested: prior to uploading them them to Glitch, I'd created and ran both examples locally using Node.js (Glitch is also using Node.js to do the querying, so there should be no effective difference). If your results still differ, there must be other local environmental circumstances which are affecting the result (as I alluded to). To figure out exactly what those differences are, we'll need more to work with — which is why I was suggesting the preference of a runnable reproduction. Feel free to ping me on Spectrum if nobody from the community is able to help you and I'll do my best to jump in! |
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 |
"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:
This is WORKING curl query:
This is NOT working from node.js
The text was updated successfully, but these errors were encountered: