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?
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?
That being said, we should probably provide a more powerful solution to create multi-field/multi-model constraints.
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.
Would you have news on this?
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.
It's actually still annoying, now the field selector looks like this: 馃槄
slug {
slug
}
That's why I'd suggest naming the field something like key, title, name.
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?
I suggest waiting for #23 and then checking the unicity when creating and updating users or organizations.
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?
See #65 and #90.
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.
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.
Please see proposed spec in https://github.com/graphcool/framework/issues/1300