我正在尝试实现类型it 的createUnionType()函数的扩展,在那里我可以传递一个类/ObjectType,而不是硬编码,它将返回两者的联合类型。
到目前为止,我所拥有的都不起作用,但我觉得这是可能的。有人能提供任何洞察力吗?也许这不可能?
typedefs
import { ObjectType, Field, createUnionType, ClassType } from "type-graphql";
@ObjectType()
export default class MutationSuccess {
@Field()
success: boolean = true;
}
// Doesn't work
export const MutationResponse = (objectType: ClassType) => createUnionType({
name: 'MutationResponseType',
types: () => [MutationSuccess, objectType],
})如何在我的解析器中使用它
@Resolver()
export default class RelationResolver {
@Mutation(() => MutationResponse(Relation), { description: 'follow user' })
async follow(
@Arg('relationInput') relationInput: RelationInput
): Promise<Relation | MutationSuccess> {
// do some stuff
}
}误差
UnhandledPromiseRejectionWarning: Error: Cannot determine GraphQL output type for follow发布于 2020-08-05 08:44:02
Relation类需要使用@ObjectType来修饰,并且联合类型名称必须是唯一的。
https://stackoverflow.com/questions/62945059
复制相似问题