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

Unable to use new validate.{create|update|delete} field-level hooks with most built-in fields #9165

Open
acburdine opened this issue Jun 5, 2024 · 1 comment · May be fixed by #9166
Open

Comments

@acburdine
Copy link
Contributor

I looked around for a similar issue/discussion but didn't see one, apologies if this is a duplicate.

At the moment, it appears to be impossible to use the new validate.{create|update|delete} field-level hooks with most of the built-in Keystone field types.

This appears to be due to this list check which asserts the mutual exclusivity of the new validate syntax and the old validate syntax.

Most of the built-in fields define a validateInput check that's automatically added if db.isNullable is set to false or if you specify validation options (example). Attempting to define a custom validate.create/validate.update check results in the following error:

TypeError: "hooks.validate" conflicts with "hooks.validateInput" for the "name" field
    at parseFieldHooks (myapp/node_modules/@keystone-6/core/dist/createSystem-b6c61fe6.cjs.dev.js:3793:50)
    at getListsWithInitialisedFields (myapp/node_modules/@keystone-6/core/dist/createSystem-b6c61fe6.cjs.dev.js:3871:16)
    at initialiseLists (myapp/node_modules/@keystone-6/core/dist/createSystem-b6c61fe6.cjs.dev.js:4305:25)
    at Object.createSystem (myapp/node_modules/@keystone-6/core/dist/createSystem-b6c61fe6.cjs.dev.js:4548:17)

Given that the validateInput/validateDelete syntax has been marked as deprecated (at least code comments seem to indicate that), I expected the built-in fields to allow usage of the new syntax (maybe it would make sense to have them automatically switch based on the presence of the validate object?)

Happy to submit a PR for this, but figured I'd also file an issue.

Keystone Version: latest (6.1.0)
Node Version: v20

@acburdine acburdine changed the title Unable to use new validate.{create|update|delete} field-level hooks with most fields Unable to use new validate.{create|update|delete} field-level hooks with most built-in fields Jun 5, 2024
acburdine added a commit to acburdine/keystone that referenced this issue Jun 5, 2024
closes keystonejs#9165
- this updates the built-in fields using validateInput to use the new unified validation syntax, and handles merging with the old syntax to ensure user-land old syntax still works
@acburdine acburdine linked a pull request Jun 5, 2024 that will close this issue
@dcousens
Copy link
Member

dcousens commented Jun 5, 2024

As mentioned in #9057

This won't be compatible with many of the native field types, but that compatibility can come later.

In other words, I didn't have the time to adapt each native field type, so a pull request is welcome 💚

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

Successfully merging a pull request may close this issue.

2 participants