0
I have a problem with graphql and Apollo server and do not know why this error persists and do not know how to solve. Even putting 'await server.start()' still giving error SyntaxError: await is only valid in async functions and the top level bodies of modules
console error
Error: You must `await server.start()` before calling `server.applyMiddleware()`
at Object.<anonymous> (C:\Desenvolvedor\Quiz_JovemGenios\jovemgenio-app\packages\server\src\main.js:15:8)
at Generator.next (<anonymous>)
main.js
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import typeDefs from './graphql/typeDefs';
import resolvers from './graphql/resolvers';
const app = express();
const server = new ApolloServer ({
typeDefs: typeDefs,
resolvers: resolvers,
});
server.applyMiddleware({
app,
cors: {
origin: 'http://localhost:30000'
},
bodyParserConfig: true,
});
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 80000
const HOSTNAME = process.env.HOSTNAME || '127.0.0.1'
app.listen(8000, '127.0.0.1', async() => {
console.log(`app is listening at http://${HOSTNAME}:${PORT}`)
});