Hopefully someone can help with this -- I'm trying to start apollo server in a TypeScript project running Express. My app.ts is below. I am getting the following error:
Argument of type '(value: unknown) => void' is not assignable to parameter of type '() => void'.ts(2769)
I think this has something to do with resolving that last promise to actually start the server. Thanks for answering this presumably very basic question!
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import depthLimit from 'graphql-depth-limit';
import compression from 'compression';
import cors from 'cors';
import schema from './schema';
const corsConfig = {
origin: '*',
credentials: true
};
async function startApolloServer() {
const server = new ApolloServer({ schema, validationRules: [depthLimit(7)] });
await server.start();
const app = express();
app.use(cors(corsConfig));
app.use(compression());
server.applyMiddleware({ app });
await new Promise(resolve => app.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
}
Try the following to match the expected callback signature:
async function startApolloServer() {
const server = new ApolloServer({ schema, validationRules: [depthLimit(7)] });
await server.start();
const app = express();
app.use(cors(corsConfig));
app.use(compression());
server.applyMiddleware({ app });
await new Promise(resolve => app.listen({ port: 4000 }, (value) => resolve(value)));
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
}
Hopefully that helps!