如何解决使用 typescript 和 type-graphql 错误创建 apollo-express-server
我正在尝试设置 apollo 服务器,但出现错误。
import { createConnection } from "typeorm";
import { Post } from "./entity/Post";
const express = require("express");
import { buildSchema } from "type-graphql";
import { ApolloServer } from "apollo-server-express";
import { PostResolver } from "./Resolvers/post";
createConnection()
.then(async (connection) => {
console.log("Inserting a new user into the database...");
const post = new Post();
post.firstName = "Timber";
post.lastName = "Saw";
post.age = 25;
await connection.manager.save(post);
console.log("Saved a new user with id: " + post.id);
console.log("Loading users from the database...");
const posts = await connection.manager.find(Post);
console.log("Loaded users: ",posts);
const app = express();
const PORT = process.env.PORT || 4000;
app.listen(PORT,() => console.log(`Listening on PORT: ${PORT}`));
const apolloServer = new ApolloServer({
schema: await buildSchema({
resolvers: [PostResolver],}),});
await apolloServer.start();
apolloServer.applyMiddleware({ app });
})
.catch((error) => console.log(error));
[错误] 16:49:21 ⨯ 无法编译 TypeScript: src/index.ts:27:43 - 错误 TS2345: '{ schema: GraphQLSchema; 类型的参数; }' 不能分配给类型为 'Config' 的参数。 类型 '{ 架构:GraphQLSchema; }' 缺少 'Config' 类型的以下属性:formatError、debug、rootValue、validationRules 等 6 个。
我再次尝试安装依赖项,更改 TypeScript 配置,重新启动整个项目,但似乎没有任何解决问题的方法。有什么线索吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。