# Taxonomies

A taxonomy is used to define hierarchical structures for content classification.

A taxonomy is a group of terms arranged in a hierarchical structure. The primary purpose of a taxonomy is to classify and logically connect related content items. This helps with content management and improves user experience with enhanced searchability.

Learn more about [Taxonomies](https://hygraph.com/docs/api-reference/schema/field-types#taxonomies).

## Fetch a taxonomy

To fetch a taxonomy, you need to access the [API Playground](https://hygraph.com/docs/api-reference/basics/api-playground) section of your Hygraph project, select `Management API` at the top of the screen, and run the following query:

  **Query**

```graphql
query MyQuery {
  viewer {
    project(id: $projectId) {
      environment(id: $environmentId) {
        contentModel {
          taxonomy(id: $taxonomyId) {
            id
            apiId
            displayName
          }
        }
      }
    }
  }
}

```

  
  **Response**

```graphql
{
  "data": {
    "viewer": {
      "project": {
        "environment": {
          "contentModel": {
            "taxonomy": {
              "id": "5f048befd53c4e4fa5e186392bf37e9c",
              "apiId": "Clothes",
              "displayName": "Clothes"
            }
          }
        }
      }
    }
  }
}
```


## Fetch taxonomy nodes

In this query, you can fetch the taxonomy nodes. The root node will return `parent:null`.

  **Query**

```graphql
query MyQuery {
  viewer {
    project(id: $projectId) {
      environment(id: $environmentId) {
        contentModel {
          taxonomy(id: $taxonomyId) {
            id
            apiId
            displayName
            taxonomyNodes {
              id
              displayName
              parent {
                id
                displayName
              }
            }
          }
        }
      }
    }
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "viewer": {
      "project": {
        "environment": {
          "contentModel": {
            "taxonomy": {
              "id": "5f048befd53c4e4fa5e186392bf37e9c",
              "apiId": "Clothes",
              "displayName": "Clothes",
              "taxonomyNodes": [
                {
                  "id": "bf416648225e45e0b43b1fc44313e9ad",
                  "displayName": "Clothes",
                  "parent": null
                },
                {
                  "id": "cefd564fa8f04f90ac64a8bb33256fcc",
                  "displayName": "Men",
                  "parent": {
                    "id": "bf416648225e45e0b43b1fc44313e9ad",
                    "displayName": "Clothes"
                  }
                },
                {
                  "id": "dcb5c00f53254df58d9c026f127b4645",
                  "displayName": "Women",
                  "parent": {
                    "id": "bf416648225e45e0b43b1fc44313e9ad",
                    "displayName": "Clothes"
                  }
                },
                {
                  "id": "c4dfc0dbe9fe4f098dada745bf44a200",
                  "displayName": "Pants",
                  "parent": {
                    "id": "dcb5c00f53254df58d9c026f127b4645",
                    "displayName": "Women"
                  }
                },
                {
                  "id": "1afb37afd21846b7b86b7b926dd5bd11",
                  "displayName": "Shirts",
                  "parent": {
                    "id": "cefd564fa8f04f90ac64a8bb33256fcc",
                    "displayName": "Men"
                  }
                },
                {
                  "id": "ee09ad8cc1dd46038a7289b773d00877",
                  "displayName": "Formal",
                  "parent": {
                    "id": "c4dfc0dbe9fe4f098dada745bf44a200",
                    "displayName": "Pants"
                  }
                },
                {
                  "id": "bf43f35e12534f2b9d96f4812ee002a1",
                  "displayName": "Casual",
                  "parent": {
                    "id": "c4dfc0dbe9fe4f098dada745bf44a200",
                    "displayName": "Pants"
                  }
                },
                {
                  "id": "c933399a04c447c797783a24b546e4a0",
                  "displayName": "Jeans",
                  "parent": {
                    "id": "c4dfc0dbe9fe4f098dada745bf44a200",
                    "displayName": "Pants"
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}
```


You can also retrieve the children of each node. In this case, you need to know how deep your taxonomy is. The following query returns the following taxonomy structure:
Root node > Child 1 > Child 2

  **Query**

```graphql
query MyQuery {
  viewer {
    project(id: $projectId) {
      environment(id: $environmentId) {
        contentModel {
          taxonomy(id: $taxonomyId) {
            id
            apiId
            displayName
            rootNode {
              displayName
              children {
                displayName
                children {
                  displayName
                  children {
                    displayName
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "viewer": {
      "project": {
        "environment": {
          "contentModel": {
            "taxonomy": {
              "id": "5f048befd53c4e4fa5e186392bf37e9c",
              "apiId": "Clothes",
              "displayName": "Clothes",
              "rootNode": {
                "displayName": "Clothes",
                "children": [
                  {
                    "displayName": "Women",
                    "children": [
                      {
                        "displayName": "Pants",
                        "children": [
                          {
                            "displayName": "Casual"
                          },
                          {
                            "displayName": "Jeans"
                          },
                          {
                            "displayName": "Formal"
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "displayName": "Men",
                    "children": [
                      {
                        "displayName": "Shirts",
                        "children": []
                      }
                    ]
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}
```


## Taxonomies in the UI

- [Create a taxonomy](https://hygraph.com/docs/developer-guides/schema/taxonomies#create-a-taxonomy)
- [Use the demo taxonomy](https://hygraph.com/docs/developer-guides/schema/taxonomies#use-demo-taxonomy)
- [Add a taxonomy to a model](https://hygraph.com/docs/developer-guides/schema/taxonomies#add-a-taxonomy-to-a-model)
- [Modify a taxonomy](https://hygraph.com/docs/developer-guides/schema/taxonomies#modify-a-taxonomy)
