Example Requests 💡

All example requests on this page are contained in the example project.

Queries

Get the User

When you want to request the user you can do this by this way in Client.swift.

static func user(success: @escaping Success<ValuePage<YoliUser>>, failure: @escaping Failure) {
  let variables: GraphQLVariables = ["language": "en"]
  _ = authorizedRequest(script: .user, variables: variables, success: success, failure: failure)
}

We map the result - wrapped in a ValuePage - to a YoliUser. The implementation looks like this

struct YoliUser: Codable {
  let username: String
  let contracts: [Contract]?
}

As you can see a YoliUser contains also a list of Contracts. The implementation of that model can be viewed in the example project. As you might have noticed you send the desired language as a variable alongside the request. This is needed since the category of a Contract is a so called Translatable. It maps directly in the language you need in your Client.

The query itself looks like this:

query user($language: String!) {
  value: me {
    username
    contracts {
      mainCategory {
        id
        text(lang: $language)
      }
      amount
      interval
      contractPartner {
        name
      }
    }
  }
}

Bank Login Status

Since the bank login process can take some time, especially when the user has a lot of transactions, we provide an endpoint to add the bank account (described below) which responses with a so called bank login task token. This token can be used to request the status of the bank login process.

The request implementation looks like this:

static func bankLoginStatus(token: String, success: @escaping Success<ValuePage<BankLoginStatus>>, failure: @escaping Failure) {
  let variables: GraphQLVariables = ["token": token]
  _ = authorizedRequest(script: .bankLoginStatus, variables: variables, success: success, failure: failure)
}

The response is mapped into BankLoginStatus. To be sure that the mapping always works, even when new status cases are added, we map the status from the API into a String property and make the enumeration mapping via a computed property.

struct BankLoginStatus: Codable {

  // MARK: - Enums

  enum State {
    case pending
    case success
    case failed
  }

  // MARK: - Properties

  private let status: String

  let message: String?

  var state: State {
    return State(rawValue: status) ?? .pending
  }
}

The query looks like below. Like above with the language, we use here the bank login task token as variable.

query bankLoginStatus($token: String!) {
  value: bankLoginStatus(taskToken: $token) {
    status
    message
  }
}

Mutations

Create a New User

You can create a user via the createMe endpoint from the API. Please note that this is the only request in this example page where an authorizedRequest isn't needed. Also we don't need any variables here. That's why the request looks pretty clear. Also there is no custom model needed to map the result, since the result is just a String with the refresh token.

static func createMe(success: @escaping Success<ValuePage<String>>, failure: @escaping Failure) {
  _ = request(script: .createMe, success: success, failure: failure)
}

The mutation itself looks clear, too.

mutation createMe {
  value: createMe
}

Change User's Username

To change the username of the user you can use the request below. We use a SuccessPage as the result. Therefore there is no additional custom model needed. Alternatively it would be possible to use ValuePage<Bool>, too.

static func changeName(name: String, success: @escaping Success<SuccessPage>, failure: @escaping Failure) {
  let variables: GraphQLVariables = ["name": name]
  _ = authorizedRequest(script: .changeName, variables: variables, success: success, failure: failure)
}

The mutation looks like this. Please note that we don't rename changeName to value but to success because we use SuccessPage here like mentioned above.

mutation changeName($name: String!) {
  success: changeName(username: $name)
}

Add a Bank Account

To add a bank account to Yoli you can do it like in the request below. As result you get a bank login task token which can be used to request the status via the bankLoginStatus query. As you can see in this example you can send multiple variables, too.

static func addBankAccount(bankCode: String, credentials: [String], success: @escaping Success<ValuePage<String>>, failure: @escaping Failure) {
  let variables: GraphQLVariables = [
    "bankCode": bankCode,
    "credentials": credentials
  ]

  _ = authorizedRequest(script: .addBankAccount, variables: variables, success: success, failure: failure)
}

The mutations looks like this below:

mutation addBankAccount($bankCode: String!, $credentials: [String]!) {
  value: addBankAccount(bankCode: $bankCode, credentials: $credentials)
}