# Replacing types in GraphQL Schema: Show left over data

**URL:** <https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616>\
**Category:** Dgraph Cloud / Slash GraphQL\
**Tags:** status:accepted, kind:feature, ticket:created\
**Created:** [July 17, 2020, 4:35pm UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616 "2020-07-17T16:35:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 17, 2020, 4:35pm UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/1 "2020-07-17T16:35:18Z")

</div>

If you set type A and type B in GraphQL schema. Then you update the schema and don’t mention type A and type B at all, but set type C and type D. What happens to type A and type B data?

```auto
type A {
 ...
}

type B {
 ...
}

```

Switch that to:

```auto
type C {
 ...
}

type D {
 ...
}

```

Would type A and type B data remain intact? Or, would it be deleted?

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [July 17, 2020, 4:42pm UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/2 "2020-07-17T16:42:33Z")

</div>

from my experience with this one, changing the schema has no effect on the underlying data. Anything that was in type `A` or `B` datawise is still intact and can still be accessed via Dgraph, but is no longer available to the graphql endpoint because there are no queries or mutations to even touch that data anymore.

This has its pros/cons.

Pros:

- Data is not erased if I have a typo in my schema and have to fix it. I can then use Dgraph to fix the raw data.
- If somehow I wipe out my entire schema, then I did not also loose my data.
- I can keep historic data if I change the schema without needing to dump that old data.

Cons:

- If I change my schema, my data does not change with it. A workaround is using the @dgraph directive to point to the correct data point.
- If I do not want to keep historic data when changing my schema I have to do that manually through Dgraph or a mutation before the schema change. This could lead to larger datasets with a lot of unused data.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 17, 2020, 4:51pm UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/3 "2020-07-17T16:51:52Z")

</div>

> [@amaster507](#):
>
> This could lead to larger datasets with a lot of unused data.

Yeah, we should keep track of these types and show them as present in the dataset. So, a user can delete them as needed.

It should not happen automatically just due to schema change. But, via a manual user action (button click or something).

---

<div class="post-metadata">

**Author:** ![abhijit-kar](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/abhijit-kar/32/3726_2.png) [@abhijit-kar](https://discuss.dgraph.io/u/abhijit-kar)\
**Post date:** [July 19, 2020, 7:11am UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/4 "2020-07-19T07:11:59Z")

</div>

The scenario above is the reason, I wanted to use GraphQL± along with GraphQL.

I can still fetch the older data even after a drastic schema change using GraphQL±

> [@mrjn](#):
>
> Yeah, we should keep track of these types and show them as present in the dataset. So, a user can delete them as needed.

This would be awesome.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 19, 2020, 6:07pm UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/5 "2020-07-19T18:07:17Z")

</div>

Well, you can still fetch this data. There’s a way to map underlying Dgraph predicates explicitly in the schema, irrespective of whatever they’re named in the schema. Like, `createdAt: DateTime @dgraph(timestamp)`.

But, it is **so easy** to change the schema, that most users would just forget about the left over data. Out of sight, out of mind.

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [July 20, 2020, 6:53am UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/6 "2020-07-20T06:53:49Z")

</div>

> [@mrjn](#):
>
> Yeah, we should keep track of these types and show them as present in the dataset. So, a user can delete them as needed.

All types would be visible if a user fetches the Dgraph schema because we don’t delete the underlying Dgraph types or predicate definitions on schema change. We could possibly have a way to diff the underlying Dgraph types and the GraphQL types to get an idea of types not used by GraphQL anymore. This can tell the user of what data can be cleaned up if they are only using GraphQL.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 20, 2020, 3:50pm UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/8 "2020-07-20T15:50:06Z")

</div>

> [@pawan](#):
>
> This can tell the user of what data can be cleaned up if they are only using GraphQL.

Yup, if we can show this in the Slash UI, then a user can decide when to delete the data. CC: @gja

Perhaps, then this is a feature request for Slash. Moving to that.

---

<div class="post-metadata">

**Author:** ![gja](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gja/32/2654_2.png) [@gja](https://discuss.dgraph.io/u/gja)\
**Post date:** [July 28, 2020, 6:28am UTC](https://discuss.dgraph.io/t/replacing-types-in-graphql-schema-show-left-over-data/8616/9 "2020-07-28T06:28:51Z")

</div>

Added this to our backlog
