问题描述
我正在尝试设置 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 (将#修改为@)