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

More Constraints #23

Closed
sorenbs opened this issue Oct 12, 2016 · 9 comments
Closed

More Constraints #23

sorenbs opened this issue Oct 12, 2016 · 9 comments

Comments

@sorenbs
Copy link
Member

sorenbs commented Oct 12, 2016

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

@OlegIlyenko
Copy link

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)

@marktani
Copy link
Contributor

Might be also handled by pre-mutation function calls

@ejoebstl
Copy link
Contributor

ejoebstl commented Jan 31, 2017

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 Synchronous Mutation Callback #58 for more complex validation cases.

@lovegrovegeorge
Copy link

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

@marktani
Copy link
Contributor

marktani commented Feb 3, 2017

Another common use case:

  • a String should not be empty

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

@marktani
Copy link
Contributor

marktani commented Feb 6, 2017

Another use case:

@PierBover
Copy link

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

@kbrandwijk
Copy link
Contributor

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

@sorenbs sorenbs reopened this Sep 28, 2017
@marktani marktani changed the title Custom Constraints More Constraints Oct 6, 2017
@marktani
Copy link
Contributor

Closing in favor of #728.

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

8 participants