属性 'start' 在类型 'ApolloServer' 上不存在
Property 'start' does not exist on type 'ApolloServer'
我可能遗漏了一个明显的设置或其他东西,但出于某种原因 VS Code 没有看到 ApolloServer.start
,我得到一个内联错误:
Property 'start' does not exist on type 'ApolloServer'.
任何人都可以看到我错过了什么吗?它通过在服务器上调用通常的 listen
方法来工作,但我正在尝试添加中间件,这是 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 })
}
更新
这个问题是关于 Apollo Server 2.0 的。 links 已被更改,Apollo 现在在 3.0 版本中。如果您不依赖版本 2,我建议您将依赖更新为 v3。对于那些坚持这一点的人,这里是模式:
// 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,我在发布问题后立即找到了它。这是一个已弃用的模式。 (已删除陈旧的 link)
我可能遗漏了一个明显的设置或其他东西,但出于某种原因 VS Code 没有看到 ApolloServer.start
,我得到一个内联错误:
Property 'start' does not exist on type 'ApolloServer'.
任何人都可以看到我错过了什么吗?它通过在服务器上调用通常的 listen
方法来工作,但我正在尝试添加中间件,这是 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 })
}
更新
这个问题是关于 Apollo Server 2.0 的。 links 已被更改,Apollo 现在在 3.0 版本中。如果您不依赖版本 2,我建议您将依赖更新为 v3。对于那些坚持这一点的人,这里是模式:
// 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,我在发布问题后立即找到了它。这是一个已弃用的模式。 (已删除陈旧的 link)