Skip to main content

Variables

Variables allow you to pass dynamic values to your queries and mutations, making them reusable.

Using variables

Define variables in your query and pass them separately:
query GetDeal($id: ID!) {
  deal(id: $id) {
    id
    friendlyId
  }
}
Variables:
{
  "id": "123"
}

Variable types

GraphQL supports various variable types:
  • ID! - Required ID
  • String - Optional string
  • Int - Integer
  • Float - Floating point number
  • Boolean - True/false
  • Custom input types

Example with multiple variables

query GetDeals($first: Int, $sortDirection: SortDirection) {
  deals(first: $first, sortDirection: $sortDirection) {
    edges {
      node {
        id
        friendlyId
      }
    }
  }
}
Variables:
{
  "first": 10,
  "sortDirection": "DESC"
}

Fragments

Fragments allow you to reuse field selections across multiple queries.

Basic fragment

fragment BorrowerFields on Borrower {
  id
  personalInformation {
    firstName
    lastName
    email
  }
}

query GetDeal {
  deal(id: "123") {
    id
    borrowers {
      edges {
        node {
          ...BorrowerFields
        }
      }
    }
  }
}

Multiple fragments

You can use multiple fragments in a single query:
fragment BorrowerFields on Borrower {
  id
  personalInformation {
    firstName
    lastName
  }
}

fragment IncomeFields on Income {
  statedMonthlyAmount
  payPeriodFrequency
}

query GetDeal {
  deal(id: "123") {
    id
    borrowers {
      edges {
        node {
          ...BorrowerFields
          incomes {
            edges {
              node {
                ...IncomeFields
              }
            }
          }
        }
      }
    }
  }
}

Selecting loan fields

Request the fields you need directly on a loan:
query GetLoan {
  loan(id: "123") {
    id
    loanPurpose
    purchasePrice
    maxLoanAmount
  }
}

Inline fragments

Use inline fragments to select fields that only exist on a specific implementation of an interface. For example, institutionName is only available on assets that implement FinancialAccountAsset:
query GetBorrowerAssets($id: ID!) {
  borrower(id: $id) {
    id
    assets {
      id
      amount
      ... on FinancialAccountAsset {
        institutionName
      }
    }
  }
}

Best practices

  1. Use variables for dynamic values - Never hardcode IDs or filters
  2. Create reusable fragments - Define common field selections once
  3. Name fragments descriptively - Use clear, descriptive names
  4. Keep fragments focused - Don’t create overly large fragments

Common patterns

Reusable borrower fragment

fragment BorrowerDetails on Borrower {
  id
  personalInformation {
    firstName
    lastName
    email
    phoneNumbers {
      number
      type
    }
  }
  incomes {
    edges {
      node {
        statedMonthlyAmount
        payPeriodFrequency
      }
    }
  }
  assets {
    id
    amount
    ... on FinancialAccountAsset {
      institutionName
    }
  }
}

Using in multiple queries

query GetDeal($id: ID!) {
  deal(id: $id) {
    id
    borrowers {
      edges {
        node {
          ...BorrowerDetails
        }
      }
    }
  }
}

query GetBorrower($id: ID!) {
  borrower(id: $id) {
    ...BorrowerDetails
  }
}