Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Unicity across different models #24

Closed
sedubois opened this issue Oct 17, 2016 · 14 comments
Closed

Unicity across different models #24

sedubois opened this issue Oct 17, 2016 · 14 comments

Comments

@sedubois
Copy link

sedubois commented Oct 17, 2016

I want to create two models, User and Org which both have a slug, ensuring that this slug is unique across all users and orgs (similar to GitHub and such sites). I don't think graph.cool currently allows this?

@sorenbs
Copy link
Member

sorenbs commented Oct 24, 2016

One approach that might or might not work based on your use case is to create a separate Slug model with a unique slug field. Then you can either reference this from the User and Org models or simply use it as a "slug generator" that simply verifies that a slug is unique before you assign it to a new User or Org.

Would either of these solutions work for you?

@schickling
Copy link
Member

That being said, we should probably provide a more powerful solution to create multi-field/multi-model constraints.

@sedubois
Copy link
Author

Agreed with both comments, the stated workarounds is OK for now, it's just not very clean and maintainable. Something more intuitive would be very appreciated.

@sedubois
Copy link
Author

sedubois commented Feb 6, 2017

Would you have news on this?

@marktani
Copy link
Contributor

marktani commented Feb 6, 2017

In this case, adding a Slug model with a unique key: String! field is the way to go. User and Org will have a one-to-one relation to Slug.

@marktani marktani closed this as completed Feb 6, 2017
@sedubois
Copy link
Author

sedubois commented Feb 6, 2017

It's actually still annoying, now the field selector looks like this: 😅

    slug {
      slug
    }

@marktani
Copy link
Contributor

marktani commented Feb 6, 2017

That's why I'd suggest naming the field something like key, title, name.

@sedubois
Copy link
Author

sedubois commented Feb 6, 2017

OK, next question is that now I lose the ability to select a User(slug: $slug), because I cannot add a unique constraint on the relation. How do I work around that?

@marktani
Copy link
Contributor

marktani commented Feb 6, 2017

I suggest waiting for #23 and then checking the unicity when creating and updating users or organizations.

@sedubois
Copy link
Author

sedubois commented Feb 6, 2017

Actually, couldn't you instrument the code to mark the linked field as unique? After all, it is unique in the linked model. That sounds simple enough and would answer the issue I think?

@marktani marktani changed the title Unicity across different models Unicity per related node Feb 6, 2017
@marktani marktani reopened this Feb 6, 2017
@marktani
Copy link
Contributor

marktani commented Feb 6, 2017

See #65 and #90.

@marktani marktani closed this as completed Feb 6, 2017
@marktani marktani changed the title Unicity per related node Unicity across different models Feb 6, 2017
@kbrandwijk
Copy link
Contributor

Unicity across different models could be solved using a scope parameter for @isUnique, and a @scope directive on Types, so you have some kind of 'grouping' for this kind of functionality.

@kbrandwijk
Copy link
Contributor

Or maybe when interfaces are implemented, and you specify a isUnique directive on an interface field, that field will be unique across all Types that implement the interface.

schickling pushed a commit that referenced this issue Sep 28, 2017
@sorenbs
Copy link
Member

sorenbs commented Nov 20, 2017

Please see proposed spec in https://github.com/graphcool/framework/issues/1300

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants