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

RFC: Validation in scaffolded mutations #439

Open
unclecheese opened this issue Jan 27, 2022 · 0 comments
Open

RFC: Validation in scaffolded mutations #439

unclecheese opened this issue Jan 27, 2022 · 0 comments

Comments

@unclecheese
Copy link

unclecheese commented Jan 27, 2022

We're currently not invoking DataObject::validate() in mutations. That would be a start, but this problem is actually a bit more complex than that. Usually, what is required for low-level data integrity isn't necessarily what is required for business cases. Validation in the API should resemble something closer to Form::validate() than DataObject::validate().

I'm pretty sure this is as simple as creating a Validator interface, and allowing registration of them against the operation:

SilverStripe\Security\Member:
  operations:
    create:
      validator: MyApp\Validators\MemberValidator

You'd also want a default validator to be registered against the schema config to manage basic validation for all dataobjects.

Or we could even do it like resolvers, where you just have a monolithic class and methods are discovered.

class MyValidator
{
  public function validateCreateMember($data);
}

And of course, the schema config then becomes:

resolvers:
  - My\ResolverClass
validators:
  - My\Validator\Class

If not, Validator should extend Identifiable so we can use the registry (as used in Bulk Loaders) and refer to them with better semantics.

SilverStripe\Security\Member:
  operations:
    create:
      validator: memberValidator

Like resolvers, this probably isn't an either/or. You can just prefer explicitly defined validators over discovered ones, and then use a default validator when neither comes through.

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

No branches or pull requests

2 participants