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
    status
  }
}
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, $status: DealStatus) {
  deals(first: $first, status: $status) {
    id
    status
  }
}
Variables:
{
  "first": 10,
  "status": "ACTIVE"
}

Fragments

Fragments allow you to reuse field selections across multiple queries.

Basic fragment

fragment BorrowerFields on Borrower {
  id
  firstName
  lastName
  email
}

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

Multiple fragments

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

fragment IncomeFields on Income {
  statedMonthlyAmount
  payPeriodFrequency
}

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

Inline fragments

Use inline fragments for union types or interfaces:
query GetLoan {
  loan(id: "123") {
    id
    ... on ConventionalLoan {
      loanAmount
      ltv
    }
    ... on JumboLoan {
      loanAmount
      jumboLimit
    }
  }
}

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
  firstName
  lastName
  email
  phoneNumber
  incomes {
    statedMonthlyAmount
    payPeriodFrequency
  }
  assets {
    amount
    institutionName
  }
}

Using in multiple queries

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

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