Typescript TypeGraphQL:@Arg Type使用从本地包导入的GraphQL类时出错
我创建了一个包含多个对象的本地包。该软件包旨在通过npm安装在其他程序中,以便从通用对象库中获益。其中,我创建了一个简单的类来创建AppLoServer,用于TypeGraphQL实体、类型和解析器:Typescript TypeGraphQL:@Arg Type使用从本地包导入的GraphQL类时出错,typescript,graphql,typegraphql,Typescript,Graphql,Typegraphql,我创建了一个包含多个对象的本地包。该软件包旨在通过npm安装在其他程序中,以便从通用对象库中获益。其中,我创建了一个简单的类来创建AppLoServer,用于TypeGraphQL实体、类型和解析器: export class ClsApolloGraphQlServer { private _resolvers: any[]; private _connection: Connection; constructor( resolvers: any[],
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;
}
}
ArgType
@ArgsType()
export class PaginationArgs {
@Field(() => Int)
start: number;
@Field(() => Int)
nbRecords: number;
}
您必须使用捆绑工件的包存储库或带有依赖项的lerna monorepo。在您的例子中,您只是链接了包,但它们在节点_模块中分离了
graphql
package,这会在Int!==Int
介于图形ql
包实例之间。您必须使用包存储库来存储捆绑的工件,或者使用带有依赖项的lerna monorepo。在您的例子中,您只是链接了包,但它们在节点_模块中分离了graphql
package,这会在Int!==Int
betweengraphql
packages实例
@ArgsType()
export class PaginationArgs {
@Field(() => Int)
start: number;
@Field(() => Int)
nbRecords: number;
}