Replacing types in GraphQL Schema: Show left over data

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?

type A {
 ...
}

type B {
 ...
}

Switch that to:

type C {
 ...
}

type D {
 ...
}

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

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.

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).

2 Likes

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±

This would be awesome.

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.

1 Like

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.

2 Likes

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.

Added this to our backlog