I have developed a local package containing various objects. The main purpose of this package is to be installed via npm in other programs so that they can utilize a common library of objects. One of the objects I created is a simple class for setting up an AppoloServer, which is intended to work with TypeGraphQL entities, types, and resolvers:
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;
}
}
Copying this code into one of the final programs and importing the class from there works perfectly fine.
However, when importing the class in the final program after installing the common library, TypeGraphQL encounters an error "
Cannot determine GraphQL input type for start
".
Below is an example of the failing resolver and the type definition for Arg, as 'start' is an argument used in resolvers for pagination purposes.
I'm not sure what the issue might be. Just want to mention that I am importing 'reflect-metadata' in the class Definition file within the library, as well as at the beginning of the final program.
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;
}