trying to setup apollo with express and keep getting the error
semantic error TS2554: Expected 0 arguments, but got 1.
with this code:
import { PrismaClient } from '@prisma/client';
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import express from 'express';
import { getDatabaseConnectionString } from './utils/config';
import bodyParser from 'body-parser';
import http from 'http';
const app = express();
const httpServer = http.createServer(app);
const typeDefs = `#graphql
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;
const books = [
{
title: 'Good Book',
author: 'Person Man'
}
];
const resolvers = {
Query: {
books: () => books
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })]
});
await server.start();
app.use(
'/',
bodyParser.json(),
// expressMiddleware accepts the same arguments:
// an Apollo Server instance and optional configuration options
expressMiddleware(server, {
context: async ({ req }) => ({
prismaClient: new PrismaClient({
datasources: {
db: {
url: getDatabaseConnectionString()
}
}
})
})
})
);
await new Promise<void>(resolve => httpServer.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000/`);
says line 38 where I do new ApolloServer(...
, if i remove the parameters it says start() doesn’t exist on ApolloServer. not sure what the issue is.
thanks.