Prisma1: More Constraints

Created on 12 Oct 2016  路  9Comments  路  Source: prisma/prisma1

Make field constraints much more flexible.
This feature can probably be delivered in smaller chunks

Use case 1

A phone number field should match a regex

Use case 2

A phone number field should be required if and only if the roles field is STORE_MANAGER

Use case 3

A money field should only allow prime numbers

Most helpful comment

Might be also handled by pre-mutation function calls

All 9 comments

I have another use-case: email and URL validation. I think these are pretty common so it would be nice to have a dedicated validators for them (though it is possible to express it via regexp)

Might be also handled by pre-mutation function calls

Thoughts:

  • This approach somehow breaks the typing approach of graphql, since an mutation might still fail even if the data types were correct. On the other side, that's a general problem of universal data types like strings.
  • The user will only be able to map very basic use cases to regex. Especially, this kind of validation does not take other nodes into account. On the other side, regex is well understood, simple and fast.
  • I very much like the idea of pre-mutation hooks as in #58 for more complex validation cases.

@ejoebstl Massive one up on pre-mutation hooks. Would complete the ability to do any logic you need before mutating something.

Another common use case:

  • a String should not be empty

more inspiration: https://github.com/aldeed/meteor-simple-schema

Another use case:

  • unicity across models #24

What about a constrain that specifies that if a type has 3 fields, at least one of them must be non null.

For example a Customer type wth these fields where at least one is required:

  • Individual
  • Organization
  • School

Also see: https://github.com/APIs-guru/graphql-constraints-spec, maybe that's relevant for these use cases?

Closing in favor of #728.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlessandroAnnini picture AlessandroAnnini  路  3Comments

thomaswright picture thomaswright  路  3Comments

notrab picture notrab  路  3Comments

Fi1osof picture Fi1osof  路  3Comments

marktani picture marktani  路  3Comments