首页 > 解决方案 > Graphql 变异返回值

问题描述

下面的 graphql 突变Account在成功时返回一个类型:

@Mutation(() => Account)
async updateAccount(
  @Arg('accountIdentifier', () => String) accountIdentifier: string,
  @Arg('input', () => AccountUpdateInput) input: AccountUpdateInput
) {
  await Account.update({ accountIdentifier }, input)
  return Account.findOne({ accountIdentifier })
}

要执行此突变,可以使用以下命令:

mutation {
  updateAccount(
    accountIdentifier: "06760b98-9a9b-4686-961c-051d6b01581f", 
    input: {
      name: "mark"
    }) {
    accountIdentifier
    email
  }
}

但是,使用相同的突变而不指定返回值会导致错误。我想知道是否可以执行上述突变或以下突变(未指定返回值)并且同时正确执行了突变?

mutation {
  updateAccount(
    accountIdentifier: "06760b98-9a9b-4686-961c-051d6b01581f", 
    input: {
      name: "mark"
    }
  )
}

标签: javascripttypescriptgraphqltypegraphql

解决方案


推荐阅读