[英]TypeGraphQL : @Arg Type Error when using a GraphQL class imported from a local Package
I have created a local package with several objects.我创建了一个带有多个对象的本地 package。 this package is aimed to be installed via npm in other programs in order to benefit from a common librairy of objects.此 package 旨在通过 npm 在其他程序中安装,以便从通用对象库中受益。 Among them, I have created a simple class to create a AppoloServer, to be used with TypeGraphQL entities, types and resolvers:其中,我创建了一个简单的 class 来创建 AppoloServer,与 TypeGraphQL 实体、类型和解析器一起使用:
export class ClsApolloGraphQlServer {
private _resolvers: any[];
private _connection: Connection;
constructor(
resolvers: any[],
connection: Connection,
) {
this._resolvers = resolvers;
this._connection = connection;
}
public async initApolloServer(
app: express.Application,
corsOpt: cors.CorsOptions
): Promise<ApolloServer> {
const {
typeDefs,
resolvers,
} = await buildTypeDefsAndResolvers({
resolvers: this._resolvers,
});
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
addSchemaLevelResolveFunction(
schema,
(_, __, context) =>
!!getSession(context, this._SESSION_TYPE)
);
const apolloServer: ApolloServer = new ApolloServer({
schema,
context: ({
req,
res,
}: {
req: Request;
res: Response;
}): IGlobalContext => {
return {
req,
res,
dbConnection: this._connection,
};
},
formatError: (err: GraphQLError) =>
FormatErrorMessageGraphQlServer(err),
});
apolloServer.applyMiddleware({ app, cors: corsOpt });
return apolloServer;
}
}
Duplicating this code in one of the final program and importing the class from this final program works fine.在最终程序之一中复制此代码并从该最终程序导入 class 工作正常。
However, importing the class in the final program after installing the common library makes TypeGraphQL failing with the error " Cannot determine GraphQL input type for start
".但是,在安装公共库后在最终程序中导入 class 会导致 TypeGraphQL 失败,并出现错误“ Cannot determine GraphQL input type for start
”。
Below is an example of the resolver that is falling and the type defined for Arg, since 'start' is an argument of resolvers to manage pagination.下面是正在下降的解析器示例和为 Arg 定义的类型,因为“开始”是解析器管理分页的参数。
Don't know what is wrong.不知道有什么问题。 Just mentionning that I'm importing 'reflect-metadata' in the class Definition file in the librairy, and also at the very beginning of the final program.只是提到我在图书馆的 class 定义文件中导入“反射元数据”,也是在最终程序的开头。
Resolver解析器
@Query(() => [objectTypeCls], { name: `getAll${suffix}` })
async getAll(
@Ctx() context: IGlobalContext,
@Args() { start, nbRecords }: PaginationArgs
): Promise<TExposeApi[]> {
if (context.dbConnection && context.dbConnection.isConnected) {
const resu: TExposeApi[] = await context.dbConnection
.getRepository<TExposeApi>(objectTypeCls)
.createQueryBuilder(suffix)
.skip(start)
.take(nbRecords)
.getMany();
return resu;
} else return [];
}
ArgType参数类型
@ArgsType()
export class PaginationArgs {
@Field(() => Int)
start: number;
@Field(() => Int)
nbRecords: number;
}
You have to use package repository for bundled artifacts or a lerna monorepo with dependencies hoisting.对于捆绑的工件,您必须使用 package 存储库或具有依赖项提升的 lerna monorepo。 In your case you just linking the packages but they have separated graphql
package in their node_modules, which raises a conflict where Int !== Int
between graphql
packages instances.在您的情况下,您只是链接包,但它们在其 node_modules 中分离了graphql
package,这会引发冲突,其中Int !== Int
在graphql
实例之间包实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.