I'm probably missing an obvious setting or something, but for some reason VS Code doesn't see ApolloServer.start
, and I get an inline error:
Property 'start' does not exist on type 'ApolloServer'.
Can anyone see what I'm missing? It works by calling the usual listen
method on the server, but I'm trying to add middleware, and this is the documented flow at apollo's official docs.
tsconfig
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"types": ["node"],
"esModuleInterop": true,
},
"include": [
"apollo-server/*"
],
"exclude": ["node_modules"]
}
index.ts
#!/usr/bin/env node
import express from 'express'
import { ApolloServer, gql } from 'apollo-server-express'
import { readFileSync } from 'fs'
import { resolvers } from './resolvers'
const typeDefs = gql`readFileSync('./schema.graphql').toString('utf-8')`
async function startServer() {
const server = new ApolloServer({
typeDefs,
resolvers,
})
await server.start() // <---- VSCode complains here
const app = express()
server.applyMiddleware({ app })
}
UPDATE
This question was regarding Apollo Server 2.0. The links have since been changed and Apollo is now on in version 3.0. If you're not dependent on version 2, I suggest updating your dependency to v3. For those of you stuck on this, here's the pattern:
// The ApolloServer constructor requires two parameters: your schema
// definition and your set of resolvers.
const server = new ApolloServer({ typeDefs, resolvers });
// The `listen` method launches a web server.
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
Here's a fresh URL to confirm it in the docs
FWIW, I found it right after I posted the question. This is a deprecated pattern. (Stale link removed)