# Query Examples

sidebar\_position: 3 title: Sample Queries

***

## Querying

Below are some sample queries you can use to gather information from the Domains contracts.

You can build your own queries using a GraphQL Explorer and enter your endpoint to limit the data to exactly what you need.

### Get the top domain for an account based on the longest registry.

```graphql
query getDomainForAccount {
  account(id: "0xa508c16666c5b8981fa46eb32784fccc01942a71") {
    registrations(first: 1, orderBy: expiryDate, orderDirection: desc) {
      domain {
        name
      }
    }
    id
  }
}
```

#### Returns

```graphql
{
  "data": {
    "account": {
      "registrations": [
        {
          "domain": {
            "name": "datanexus.tomi"
          }
        }
      ],
      "id": "0xa508c16666c5b8981fa46eb32784fccc01942a71"
    }
  }
}
```

### Search for subdomain

```graphql
query getSubDomains($Account: String = "messari.tomi") {
  domains(where: { name: "messari.tomi" }) {
    name
    id
    subdomains(first: 10) {
      name
    }
    subdomainCount
  }
}
```

#### Returns

```graphql
{
  "data": {
    "domains": [
      {
        "name": "messari.tomi",
        "id": "0x498ada62251a1227664ace8d97b0de2dcc6652ddf61e6fb5d3150f43ccf599e6",
        "subdomains": [
          {
            "name": "subgraphs.messari.tomi"
          },
          {
            "name": "bd.messari.tomi"
          }
        ],
        "subdomainCount": 2
      }
    ]
  }
}
```

### Get an expiration for an Domains domain

```graphql
query getDomainExp($Account: String = "paulieb.tomi") {
  registrations(
    where: { domain_: { name: $Account } }
    first: 1
    orderBy: expiryDate
    orderDirection: desc
  ) {
    expiryDate
  }
}
```

#### Returns

```graphql
{
  "data": {
    "registrations": [
      {
        "expiryDate": "1714752524"
      }
    ]
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tomi-domain-name-service.gitbook.io/titled/subgraph/query-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
