# Inline fragments

GraphQL's permits [polymorphism](https://en.wikipedia.org/wiki/Polymorphism_\(computer_science\)) through [inline fragments](https://graphql.org/learn/queries/#inline-fragments), through objects being available as[ GraphQL Unions](https://graphql.org/learn/schema/#union-types) and [Interfaces](https://graphql.org/learn/schema/#interfaces). Eduflow uses inline fragments across the various [activity object types](https://docs.eduflow.com/guides/flows-and-activities#activities).

Eduflow activities all have `Activity.title`, so all activities inherit from `ActivityInterface`.

### Querying

{% tabs %}
{% tab title="Query" %}

```graphql
{
  course(id: "00000000-5945-95c7-65fc-a9747b200320") {
    flows {
      activities {
        ... on ActivityInterface {
          title
        }
      }
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "course": {
      "flows": [
        {
          "activities": [
            {
              "title": "Welcome to the root-level Activity"
            }
          ]
        },
        {
          "activities": [
            {
              "title": "Learn about paper"
            },
            {
              "title": "Environmental friendliness"
            },
            {
              "title": "Climate change"
            }
          ]
        },
        {
          "activities": [
            {
              "title": "Introduction to sales"
            },
            {
              "title": "CRM technology"
            },
            {
              "title": "Funnel configuration"
            }
          ]
        }
      ]
    }
  }
}
```

{% endtab %}
{% endtabs %}

### Inline fragments

Using specific activity fragments act as a way to [upcast ](https://en.wikipedia.org/wiki/Type_conversion)objects. Here's an example of `PeerReview` ran against the connection above, and via direct activity lookup.

{% tabs %}
{% tab title="Query (Connection)" %}

```graphql
{
  course(id: "00000000-5945-95c6-65fc-a9747b200320") {
    flows {
      activities {
        __typename
        ... on ActivityInterface {
          title
        }
        ... on PeerReviewActivity {
          reviews {
            edges {
              node {
                reviewType
                createdAt
              }
            }
          }
        }
      }
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}
Notice the specialized fields only return for the activity type that are `PeerReview`s:

```javascript
{
  "data": {
    "course": {
      "flows": [
        {
          "activities": [
            {
              "__typename": "ContentActivity",
              "title": "Welcome aboard!"
            }
          ]
        },
        {
          "activities": [
            {
              "__typename": "ContentActivity",
              "title": "Our Mission"
            },
            {
              "__typename": "SubmissionActivity",
              "title": "Make an impact"
            },
            {
              "__typename": "PeerReviewActivity",
              "title": "Spot-check and team build",
              "reviews": {
                "edges": [
                  {
                    "node": {
                      "reviewType": "PeerReview",
                      "createdAt": "2021-02-08T17:56:30.576582"
                    }
                  },
                  {
                    "node": {
                      "reviewType": "PeerReview",
                      "createdAt": "2021-02-08T17:56:30.617394"
                    }
                  },
                  {
                    "node": {
                      "reviewType": "PeerReview",
                      "createdAt": "2021-02-08T17:56:30.661450"
                    }
                  },
                  {
                    "node": {
                      "reviewType": "PeerReview",
                      "createdAt": "2021-02-08T17:56:30.703841"
                    }
                  },
                  {
                    "node": {
                      "reviewType": "PeerReview",
                      "createdAt": "2021-02-08T17:56:32.501897"
                    }
                  }
                ]
              }
            },
            {
              "__typename": "FeedbackReflectionActivity",
              "title": "Introspect and reflect"
            },
            {
              "__typename": "TeacherReviewActivity",
              "title": "From your manager"
            },
            {
              "__typename": "SelfReviewActivity",
              "title": "How would you improve?"
            },
            {
              "__typename": "ContentActivity",
              "title": "Water cooler"
            },
            {
              "__typename": "ContentActivity",
              "title": "Networking: Meet across divisions"
            }
          ]
        },
        {
          "activities": [
            {
              "__typename": "ContentActivity",
              "title": "Paper: Relevant today?"
            },
            {
              "__typename": "SubmissionActivity",
              "title": "How do you use paper?"
            },
            {
              "__typename": "ContentActivity",
              "title": "Our philosophy"
            }
          ]
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="Query (Direct lookup)" %}
`title` exists in `PeerReviewActivity` as well, no need to use `ActivityInterface`:

```graphql
{
  activity(id: "10aa7684-f0b2-4595-9161-4845e3602312") {
    ... on PeerReviewActivity {
      title
      reviews {
        edges {
          node {
            reviewType
            createdAt
          }
        }
      }
    }
  }
}
```

![title exists on PeerReviewActivity, as it inherits from ActivityInterface](https://2518674650-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3GmK_EkZyQQJhTJyLh%2F-MT15rSgaF_WktWe1E4F%2F-MT16Ggg_C1Dyyudl0f1%2Fimage.png?alt=media\&token=a5058c66-4387-4ab8-85eb-ec63d1d248f6)
{% endtab %}

{% tab title="Response" %}

```javascript
{
  "data": {
    "activity": {
      "title": "Spot-check and team build",
      "reviews": {
        "edges": [
          {
            "node": {
              "reviewType": "PeerReview",
              "createdAt": "2021-02-08T17:56:30.576582"
            }
          },
          {
            "node": {
              "reviewType": "PeerReview",
              "createdAt": "2021-02-08T17:56:30.617394"
            }
          },
          {
            "node": {
              "reviewType": "PeerReview",
              "createdAt": "2021-02-08T17:56:30.661450"
            }
          },
          {
            "node": {
              "reviewType": "PeerReview",
              "createdAt": "2021-02-08T17:56:30.703841"
            }
          },
          {
            "node": {
              "reviewType": "PeerReview",
              "createdAt": "2021-02-08T17:56:32.501897"
            }
          }
        ]
      }
    }
  }
}
```

{% endtab %}
{% endtabs %}

### See also

* [Inline fragments](https://graphql.org/learn/queries/#inline-fragments) on graphql.org
* [Unions](https://graphql.org/learn/schema/#union-types) on on graphql.org
* [Interfaces](https://graphql.org/learn/schema/#interfaces) on graphql.org
