我正在使用TS和Graphql
在使用订阅之前,我的解析器键入(名为ResolverMap-如下所示)可以在没有Subscription的情况下正常工作。现在我想添加订阅解析器,我的打字稿对我大叫。从订阅解析器的形状来看,它与查询解析器和变异解析器不同。
我使用了SubscriptionResolverMap-如下所示。它适用于我的订阅解析器,但是其他错误会清楚显示,因为解析器类型的形状与“查询和变异”不匹配
我应该如何键入ResolverMap以支持所有三个-订阅,突变和查询?
谢谢
解析器
export const TaskResolvers: ResolverMap = {
Subscription: {
taskAdded: {
subscribe: (_: any, __: any, { pubsub }: any) => {
return pubsub.asyncIterator(TASK_ADDED);
},
},
},
Query: {
getTasks: combineResolvers(isAuthenticated, async (_, __, { Task }) => {
const tasks = await Task.find({});
return tasks;
}),
countTaskComment: async (
_,
{ taskId }: QueryCountTaskCommentArgs,
{ Task }
) => {
const task = await Task.findById(taskId);
const count = task.commentCount;
return count;
},
},
ResolverMap
export interface ResolverMap {
[key: string]: {
[key: string]: Resolver;
};
}
SubscriptionResolverMap
export interface SubscriptionResolverMap {
[key: string]: {
[key: string]: {
[key: string]: Resolver;
};
};
}