Skip to content

GraphQL mutations

Mutations are used to change data. In BankGround, we can use them to create accounts, or transactions.

Creating a new bank account

Similarly, we can create a new bank account using GraphQL mutation.

mutation CreateAccount {
    createAccount(
      accountName: "Business", 
      balance: 20000
    ) {   
        id 
        accountName
        balance
        iban }
}

The response will contain the newly created account:

{
    "data": {
        "createAccount": {
            "id": 180,
            "accountName": "Business",
            "balance": 20000.0,
            "iban": "GB18WKWK75967002909474"
        }
    }
}

Creating a new transaction

We can also create a new transaction using GraphQL mutation.

mutation CreateTransaction {
    createTransaction(
      accountId: 180
      amount: 25, 
      note: "apples",
      counterpartyIban: "GB994554425", 
      counterpartyName: "Bakery"
    ) 
  {
    counterpartyIban
    counterpartyName
    note
    amount
    account {
      id
      accountName
      balance
    }
  }
}

Note that we have requested the account information in the response.

{
    "data": {
        "createTransaction": {
            "counterpartyIban": "GB994554425",
            "counterpartyName": "Bakery",
            "note": "apples",
            "amount": 25.0,
            "account": {
                "id": 180,
                "accountName": "Business",
                "balance": 19950.0
            }
        }
    }
}

Feel free to experiment with the request. 🥼 🧪🧪🧪