Subgraph API
Querying

Querying

The Graph is a decentralized protocol for indexing and querying data from blockchains, such as Optimism, Ethereum, and IPFS, making it easier for developers to build decentralized applications. This guide focuses on querying a particular subgraph for HNS.ID.

How to Query

Using the GraphiQL Interface

  1. Navigate to The Graph's GraphiQL interface (opens in a new tab).
  2. In the left-hand query pane, write or paste your GraphQL query.
  3. Press the "Play" button to execute the query and observe the results in the right-hand pane.

Programmatically in Your Code

https://api.thegraph.com/subgraphs/name/namebasehq/hns-id (opens in a new tab)

To query the subgraph programmatically, you can use GraphQL client libraries like Apollo or urql. Here's a sample JavaScript code snippet using Apollo Client:

import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
 
const client = new ApolloClient({
  uri: 'https://api.thegraph.com/subgraphs/name/namebasehq/hns-id',
  cache: new InMemoryCache()
});
 
client.query({
  query: gql`
    {
      tlds(first: 5) {
        id
        owner
      }
    }
  `
}).then(data => console.log(data))
  .catch(error => console.error(error));

Example Queries

Here are some sample GraphQL queries you might run against the Handshake HNS-ID subgraph:

Fetch first 5 TLDs and their owners

{
  tlds(first: 5) {
    id
    owner {
        id
    }
  }
}

Get details of a specific TLD

{
  tlds(where: {label: "hns"}) {
    id
    label
    owner {
        id
    }
    resolver {
      id
      addresses {
        cointype
        address
      }
      textRecords{
        key
        value
      }
    }
  }
}

Fetch all SLDs belonging to a specific TLD along with their addresses

{
  tlds(where: {label: "hns"}) {
    id
    label
    slds {
      id
      owner {
        id
      }
      fullName
    }
  }
}