Currently I am trying to get an api for my nextjs project to work. For deployment I am using zeit's NOW v2 (locally via "now dev").
Everything works fine except the graphql-server.
In playground and via client I get an 404-error. Queries are getting executed correctly, but I get an error-object(query results are in the response-field; 404).
Checking it in the playground-gui: same problem and in the playground-input field showing the message "Server cannot be reached".
Playground Initial Error:
{
"error": "Response not successful: Received status code 404"
}
Playground after hello-query:
{
"error": {
"data": {
"hello": "Hello world!"
}
}
}
Browser-Console Playground:
Error: "Response not successful: Received status code 404"
This is my graphql-server loaded with now:
import express from 'express';
import { ApolloServer, gql } from 'apollo-server-express';
const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const server = new ApolloServer({ typeDefs, resolvers,
introspection: true, playground: true,
subscriptions: {path: '/api'},
});
const app = express();
server.applyMiddleware({ app, path: "/api", cors: true });
module.exports = app;
Also tried this example. Same problem.
Can anyone tell me how to get it running properly?