# Variants

Variants are used to personalize your content.

## Overview

Variants and Segments work together to deliver tailored experiences to different groups of users.

After you add a Segment or a Variant, it is added to the Hygraph schema and is immediately queryable through the API. You need to access the [API Playground](https://hygraph.com/docs/api-reference/basics/api-playground) section of your Hygraph project, select `Content API` at the top of the screen, and then run the query.

## Fetch Variants

You can fetch all the Variants associated with a specific content entry.

  **Query**

```graphql
query MyQuery {
  post(where: {id: "<Post_ID>"}) {
    variants {
      id
      title
      description
    }
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "post": {
      "variants": [
        {
          "id": "cmdqahfag01fi07vwnqt0z9oe",
          "title": "Overview document for beginners",
          "description": "This is the overview document for beginners."
        },
        {
          "id": "cmdqaitbw01gs07vwfkwrnu9f",
          "title": "Overview document for intermediate users",
          "description": "This is the overview document for intermediate users."
        },
        {
        "id": "cmdqaj9hl01hk07vwpgom2lo6",
        "title": "Overview document for advanced users",
        "description": "This is the overview document for advanced users."
        }
      ]
    }
  }
}
```


## Fetch a Variant and its linked Segments

  **Query**

```graphql
query myquery {
  post(where: {id: "<Post_ID>"}) {
    variants(where: {segments_some: {name: "Beginners"}}) {
      title
      description
      segments {
        name
      }
    }
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "post": {
      "variants": [
        {
          "title": "Overview document for beginners",
          "description": "This is the overview document for beginners.",
          "segments": [
            {
              "name": "Beginners"
            }
          ]
        }
      ]
    }
  }
}
```


## Fetch a Variant from a Segment

  **Query**

```graphql
query MyQuery {
  post(where: {id: "<Post_ID>"}) {
    variants(where:{segments_some:{name:"Beginners"}}) {
      title
      description
    }
    description
    title
    }
  }
```

  
  **Response**

```graphql
{
  "data": {
    "post": {
      "variants": [
        {
          "title": "Overview document for beginners",
          "description": "This is the overview document for beginners."
        }
      ],
      "description": "This is the overview document.",
      "title": "Overview document"
    }
  }
}
```


## Fetch a Variant from multiple Segments

  **Query**

```graphql
query myquery {
  post(where: {id: "cmfy1om0l025y07vw1b0sc8os"}) {
    variants(
     where: {
        AND: [
          { segments_some: { slug: "intermediate" } }
          { segments_some: { slug: "returning-users" } }
        ]
      }) {
       title
       description
       segments {
         name
       }
    }
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "post": {
      "variants": [
        {
          "title": "Overview document for Intermediate users",
          "description": "This is the overview document for intermediate users.",
          "segments": [
            {
              "name": "Intermediate"
            },
            {
              "name": "Returning users"
            }
          ]
        }
      ]
    }
  }
}
```


## Fetch all Segments

  **Query**

```graphql
query MyQuery {
  segments {
    id
    name
    description
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "segments": [
      {
        "id": "cmdq856yk00l207uuzrspz4xh",
        "name": "Beginners",
        "description": "This segment is for beginners."
      },
      {
        "id": "cmdq8bdua00lg07vw8s6klbqt",
        "name": "Intermediate",
        "description": "This segment is for intermediate users."
      },
      {
        "id": "cmdq8bivp00lk07vw0h6hcjoi",
        "name": "Advanced",
        "description": "This segment is for advanced users."
      }
    ]
  }
}
```


## Fetch a Segment

You can fetch a specific Segment by providing its ID.

  **Query**

```graphql
query MyQuery {
  segment(where: {id: "<Segment_ID>"}) {
    name
    description
  }
}
```

  
  **Response**

```graphql
{
  "data": {
    "segment": {
      "description": "This segment is for beginners.",
      "name": "Beginners"
    }
  }
}
```
