我无法进行删除突变,函数返回时会发生错误。
如果我在 GraphQL 中运行 BairroDelete,那么 graphql 中的 Mutation 会发生错误。
消息:
Field \ BairroDelete \ must not have a selection since type \" Boolean! \ Has no subfields.,
代码:
import { Resolver, Query, Mutation, Arg } from "type-graphql";
import { Bairro } from "../entities/Bairro";
import { status } from "../enumerador";
@Resolver(of => Bairro)
export class BairroResolver {
@Query(returns => [Bairro])
async Bairros() {
return await Bairro.find();
}
@Mutation(() => Bairro)
async BairroSave(
@Arg("nome") nome : string
)
{
const ativo = await status.Ativo;
const bairro = await Bairro.create({
nome,
status: ativo
}).save()
return bairro;
}
@Mutation(() => Boolean)
async BairroDelete(
@Arg("id") id : string
)
{
const sucesso = await Bairro.delete({ id });
return sucesso; // <<<<<< ERROR HERE
}
}
最佳答案
Field \ BairroDelete \ must not have a selection since type \" Boolean! \ Has no subfields.
您需要向我们展示您的 graphql 突变文档。
看起来你正在做这样的事情:
mutation {
BairroDelete(id: 123) {
status
}
}
这是非法的,因为 BairroDelete
返回 bool 标量,而不是您可以从中选择字段的对象类型。
但是,这是合法的:
mutation {
BairroDelete(id: 123)
}
关于typescript - 返回类型ORM删除突变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57595631/