gpt4 book ai didi

typescript - 如何修复此 typescript 和 graphql 错误?

转载 作者:行者123 更新时间:2023-12-05 07:06:35 24 4
gpt4 key购买 nike

在我的索引文件中,我试图将我所有的 typedef 和解析器聚集到一个 GraphQLSchema[] 中,使用 graphql-tools 方法 makeExicutableSchemabuildSchema 然后从 graphql-yoga 放入 GraphQLServer。

import { importSchema } from "graphql-import";
import { GraphQLServer } from 'graphql-yoga';
import * as path from 'path';
import * as fs from 'fs';
import { createTypeOrmConnection } from "./utils/createTypeOrmConn";
import { mergeSchemas, makeExecutableSchema } from "graphql-tools";
import { GraphQLSchema } from 'graphql';

export const startServer = async () => {
const schemas: GraphQLSchema[] = [];
const folders = fs.readdirSync(path.join(__dirname, "./modules"));
folders.forEach(folder => {
const { resolvers } = require(`./modules/${folder}/resolvers`);
const typeDefs = importSchema(
path.join(__dirname, `./modules/${folder}/schema.graphql`)
);
schemas.push(makeExecutableSchema({
resolvers,
typeDefs
}));
});

const server = new GraphQLServer({
schema: mergeSchemas({ schemas })
});
await createTypeOrmConnection();
const app = await server.start({port: process.env.NODE_ENV === "test" ? 0 : 4000})
console.log('Server is running on http://localhost:4000')

return app;
};

这是错误在 schema: mergeSchema({ schemas }):

Type 'import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/graphql/type/schema").GraphQLSchema' is not assignable to type 'import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/apollo-utilities/node_modules/graphql/type/schema").GraphQLSchema'.
The types returned by 'getQueryType()' are incompatible between these types.
Type 'Maybe<GraphQLObjectType<any, any>>' is not assignable to type 'Maybe<GraphQLObjectType<any, any, { [key: string]: any; }>>'.
Type 'GraphQLObjectType<any, any>' is not assignable to type 'Maybe<GraphQLObjectType<any, any, { [key: string]: any; }>>'.
Types of property 'isTypeOf' are incompatible.
Type 'import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/graphql/jsutils/Maybe").Maybe<import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/graphql/type/definition").GraphQLIsTypeOfFn<any, any>>' is not assignable to type 'import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/apollo-utilities/node_modules/graphql/tsutils/Maybe").default<import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/apollo-utilities/node_modules/graphql/type/definition").GraphQLIsTypeOfFn<any, any>>'.
Type 'GraphQLIsTypeOfFn<any, any>' is not assignable to type 'Maybe<GraphQLIsTypeOfFn<any, any>>'.
Types of parameters 'info' and 'info' are incompatible.
Property 'cacheControl' is missing in type 'import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/apollo-utilities/node_modules/graphql/type/definition").GraphQLResolveInfo' but required in type 'import("/Users/jackrisse/Projects/project-da-league/backend/node_modules/graphql/type/definition").GraphQLResolveInfo'.

最佳答案

我通过将模式分配给任何类型找到了解决方法常量架构:any = mergeSchemas({ schema });

关于typescript - 如何修复此 typescript 和 graphql 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62415099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com