A Glimpse Into GraphQL

Table of Contents


Introduction

Information on TFChain is indexed over GraphQL and is available for queries.

You can query the following ThreeFold networks with GraphQL:

The GraphQL interface used to query TF-Chain is the one offered by Subsquid. See more info on supported queries here.


GraphQL Examples

We present here some example on how to use GraphQL to query the ThreeFold Grid and find suitable nodes depending on your specific needs.


Getting Many Nodes

query MyQuery {
  nodes(orderBy: nodeId_ASC, limit: 5000, where: {
      cru_gt: "2", hru_gt: "500000000", mru_gt: "50000000", sru_gt: "1000000000", 
      deletedAt_eq: null
    }) 
    {
    twinId
    city
    certificationType
    country
    created
    createdById
    cru
    farmId
    hru
    id
    uptime
    version
    mru
    sru
    nodeId
    interfaces {
      ips
      name
      node {
        city
        country
        cru
        hru
        sru
        mru
      }
    }
    location {
      latitude
      longitude
    }
    publicConfig {
      domain
      gw4
      gw6
      ipv4
      ipv6
    }
    deletedById
  }
}



Finding Gateways

gateway typically needs to be a node with public ipv4 or ipv6 and a domain configured otherwise it won't be able to create NameContracts

 query MyQuery {
  nodes {
    nodeId
    publicConfig {
      domain
      ipv4
    }
  }
}

Finding Farms with Public IPs

query MyQuery {
  farms {
    farmId
    name

    publicIPs {
      ip
      
    }
  }
}


Finding Nodes on a Specific Farm

query MyQuery {
  nodes(where: {farmId_eq: 1}) {
    twinId
  }
}

Finding Nodes by Country

query MyQuery {
  nodes(where: {country_eq: "BE"}) {
    twinId
  }
}

Filtering Nodes with GPU Devices

query MyQuery {
  nodes(where: {hasGpu_eq: true}) {
    hasGpu
    id
  }
}

Finding Nodes by Capacity

query MyQuery {
  nodes() {
    cru,
    hru,
    mru,
    sru,
  }
}

Note that the cru are in bytes.


Filtering Nodes with Specific Capacity

query MyQuery {
  nodes(where: {cru_gt: "2", hru_gt: "500000000", mru_gt: "50000000", sru_gt: "1000000000"}) {
    nodeId
    cru
    hru
    mru
    sru
  }
}

Note that the cru are in bytes.


GraphQL and the ThreeFold Explorer

Note that most of those examples have their equivalent searches available in our ThreeFold Explorer.