Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create predicates from type fields #4085

Closed
campoy opened this issue Sep 27, 2019 · 5 comments
Closed

Create predicates from type fields #4085

campoy opened this issue Sep 27, 2019 · 5 comments
Labels
area/schema Issues related to the schema language and capabilities. area/types Issues related to the type system. kind/enhancement Something could be better. priority/P2 Somehow important but would not block a release. status/accepted We accept to investigate/work on it.

Comments

@campoy
Copy link
Contributor

campoy commented Sep 27, 2019

Experience Report

It is confusing that when you declare a field in a type this is not taken into account automatically by the schema.

What you wanted to do

In issue #4080, a user created a type with a field head of type uid to keep a 1:1 relationship.

What you actually did

Since they didn't create the corresponding predicate in the schema head: uid ., once they sent the first mutation with a head predicate pointing to a uid, the predicate was created.

The problem is this predicate was created with type head: [uid] . therefore breaking the user's expectations.

Why that wasn't great, with examples

This made the user think 1:1 relationships were not supported.
Their expectations were justified.

Instead, I would have expected that if you create a type with field head uid in a type a corresponding predicate would be created.

This also includes the fact that if two types are created with the same name but different types an error should be returned.

Any external references to support your case

N/A

@campoy campoy added area/schema Issues related to the schema language and capabilities. area/types Issues related to the type system. kind/enhancement Something could be better. priority/P2 Somehow important but would not block a release. status/accepted We accept to investigate/work on it. labels Sep 27, 2019
@martinmr
Copy link
Contributor

We are simplifying type definitions to not have to include a type so once that is added this shouldn't be an issue.

PR: #4017

@campoy
Copy link
Contributor Author

campoy commented Sep 27, 2019

Then we should still fail if a type is defined with a field that doesn't have a corresponding predicate on the schema, right?

@martinmr
Copy link
Contributor

Ideally yes but I think implementing that would have a lot of edge cases. For example, it would mean you have to first add all the predicates, before you can declare a type. Or, what to do with the types when a predicates is removed?

It's definitely something we could do but I am not sure if the benefits outweigh the costs. Maybe better documentation or examples would be enough. I think getting rid of the field types would make it clearer that types and predicates both have to be declared before Dgraph works correctly.

@campoy
Copy link
Contributor Author

campoy commented Sep 27, 2019

Thanks for the clarification, Martin.

We should sit down all together and come up with a clear design for types and their relationship with predicates before continuing any changes.

I'll schedule something for next week.

@minhaj-shakeel
Copy link
Contributor

Github issues have been deprecated.
This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.

drawing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Issues related to the schema language and capabilities. area/types Issues related to the type system. kind/enhancement Something could be better. priority/P2 Somehow important but would not block a release. status/accepted We accept to investigate/work on it.
Development

No branches or pull requests

3 participants