-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
coreRelated to codegen core/cliRelated to codegen core/clikind/enhancementNew feature or requestNew feature or requestplugins
Description
Is your feature request related to a problem? Please describe.
Currently root resolver types exported the following way:
export type QueryResolvers<ContextType = IContext, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = {
accounts?: Resolver<Maybe<ReadonlyArray<Maybe<ResolversTypes['Account']>>>, ParentType, ContextType>;
};
the accounts
type Resolver<Maybe<ReadonlyArray<Maybe<ResolversTypes['Account']>>>, ParentType, ContextType>;
is too long and complex to reuse it in TS files, for example, when I need to define resolver functions in the separate file and define its type:
export const accountsResolver: Resolver<Maybe<ReadonlyArray<Maybe<ResolversTypes['Account']>>>, ParentType, ContextType> = async (_, __, ctx) => {
const res = ...
return res.map(item => {
return {
id: item._id.toString(),
name: item.name,
balance: item.balance || 0,
};
});
};
Describe the solution you'd like
I propose to add additional optional config parameter, and in addition to this long construction generate alias for it:
export type AccountsResolverFn<ContextType = IContext, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = Resolver<Maybe<ReadonlyArray<Maybe<ResolversTypes['Account']>>>, ParentType, ContextType> | undefined;
with this change the code becomes much simpler:
export const accountsResolver: AccountsResolverFn = async (_, __, ctx) => {
const res = ...
return res.map(item => {
return {
id: item._id.toString(),
name: item.name,
balance: item.balance || 0,
};
});
};
Metadata
Metadata
Assignees
Labels
coreRelated to codegen core/cliRelated to codegen core/clikind/enhancementNew feature or requestNew feature or requestplugins