Storefront graphQL API - Access customer order count in Checkout

Hi there,

We have a requirement to identify customers who place order-first time to show some custom marketing messages. To do that I would like to get customer order count in checkout object.

While I am trying to customer information incheckout, always return null.

Can someone help me on how can approach this problem

Query I tried:

{
node(id: “{{checkoutID}}”) {
id
… on Checkout {
id
webUrl

shippingLine {
title
handle
priceV2 {
amount
}
}
order{
originalTotalPrice {
amount
currencyCode
}
}
lineItemsSubtotalPrice {
amount
currencyCode
}
subtotalPriceV2 {
amount
currencyCode
}
totalTaxV2 {
amount
currencyCode
}
totalPriceV2 {
amount
currencyCode
}

completedAt
createdAt
taxesIncluded
discountApplications(first: 250) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
node {
allocationMethod,…on ManualDiscountApplication { title,description },… on DiscountCodeApplication { code,applicable },… on ScriptDiscountApplication { description },… on AutomaticDiscountApplication { title,value,targetSelection }}
}
}
lineItems(first: 250) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
node {
id
title
variant {
id
sku
title
currentlyNotInStock
selectedOptions {
name
value
}
image {
originalSrc
altText
width
height
}
priceV2 {
amount
currencyCode
}
compareAtPriceV2 {
amount
currencyCode
}
product {
handle
}
}
quantity
}
}
}
email
customAttributes{
key
value
}
customer{
acceptsMarketing
lastName
orders{
edges {
node {
id
}
}
}
}
}
}
}

The field ‘customer’ inside Checkout is deprecated and will return ‘null’ always. You’ve to query the customer endpoint directly sending the customer access token, something like:

{
  node(id: "{{checkoutID}}") {
    id
    ... on Checkout {
      id
    }
  }
  customer(customerAccessToken: $customerAccessToken) {
    orders(first: 100) {
      edges {
        node {
          id
        }
      }
    }
  }
}