0

The graphql mutation below returns an Account type on success:

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

To execute this mutation one can use the following:

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

However, using this same mutation without specifying a return value results in an error. I was wondering if it's possible to execute the above mutation or the below mutation (without return value specified) and at the same time have the mutation executed correctly?

mutation {
  updateAccount(
    accountIdentifier: "06760b98-9a9b-4686-961c-051d6b01581f", 
    input: {
      name: "mark"
    }
  )
}
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
  • If the return type of a field is an object type, you must specify a selection set of at least one child field when requesting the field. – Daniel Rearden Jul 01 '20 at 12:41
  • Thank you, I've noticed that. But I was wondering if this is possible: "If the user provided a field from Account as return value, return the Account fields needed. If the user didn't define a return value simply return Boolean true on success" – DarkLite1 Jul 01 '20 at 12:42
  • You'd have to utilize a custom scalar (like a JSON scalar) and then implement that logic inside your resolver, using the info parameter to determine whether a selection set was provided. – Daniel Rearden Jul 01 '20 at 12:44
  • Ok. I'll look into that thank you. – DarkLite1 Jul 01 '20 at 12:45

0 Answers0