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

Add beforeOperation.[create|update|delete] and afterOperation.[create|update|delete] operation routing for list hooks #8826

Merged
merged 8 commits into from Sep 25, 2023

Conversation

dcousens
Copy link
Member

@dcousens dcousens commented Sep 25, 2023

This pull request adds the .[create|update|delete] hooks for the *Operation list hooks, and adds the same for field hooks internally (but not externally, as that is a breaking change for fields).

This routing is preferred for the refined type guarantees it can offer your application without needing to branch the types yourself.

| 'views'
| '__ksTelemetryFieldTypeName'
| 'extraOutputFields'
| 'unreferencedConcreteInterfaceImplementations'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will minimize the number of breaking changes moving forward and keeps us keenly aware of what else is being copied to this type.

@@ -20,7 +20,7 @@ export type FilterOrderArgs<ListTypeInfo extends BaseListTypeInfo> = {
export type CommonFieldConfig<ListTypeInfo extends BaseListTypeInfo> = {
access?: FieldAccessControl<ListTypeInfo>;
hooks?: FieldHooks<ListTypeInfo, ListTypeInfo['fields']>;
label?: string;
label?: string; // TODO: move to ui?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently text({ label: 'a text field' }) is what we use for fields, but not for lists.
Strange

@dcousens dcousens self-assigned this Sep 25, 2023
@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 25, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit da90b62:

Sandbox Source
@keystone-6/sandbox Configuration

@gautamsi
Copy link
Member

what about validateInput and resolveInput for list and field. I hope the list and field both will have same/similar syntax.

@dcousens
Copy link
Member Author

dcousens commented Sep 25, 2023

@gautamsi resolveInput already has this syntax for lists, but not for fields.
Unfortunately for fields, it is a breaking change to add any of this to their types seeing as fields often wrap user configuration.

edit: as you can see however, I am adding this functionally for fields internally, so we can make that a clean breaking change

@dcousens
Copy link
Member Author

dcousens commented Sep 25, 2023

validateInput and validateDelete is something I am playing with in 2bad55e - but it is not ready, and I am unclear how the types should work for users if you had:

validate: {
  create: ...
  update: ...
}
validateDelete: ...

I think probably only one version should be allowed, validate*, or validate: { ... }, not both.

@dcousens
Copy link
Member Author

dcousens commented Sep 25, 2023

Alternatively, I could add validateInput.[create | update], and validateDelete.delete, and then break that in the next major to merge into validate.*.

@gautamsi
Copy link
Member

gautamsi commented Sep 25, 2023

why not validate.[create | update | delete]

Copy link
Member

@borisno2 borisno2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dcousens
Copy link
Member Author

dcousens commented Sep 25, 2023

@gautamsi what do you do if users provide both? (as I mentioned in #8826 (comment))

validate: {
  create: ...
  update: ...
  delete: ...
}
validateInput: ...
validateDelete: ...

That is the question I don't know the answer to, and thus it seems like it might end up as a breaking change, unlike this pull request.

@dcousens dcousens merged commit dc26bdf into main Sep 25, 2023
58 checks passed
@dcousens dcousens deleted the operation-routing branch September 25, 2023 03:27
@gautamsi
Copy link
Member

I guess throw error and have them provide only one, this is breaking changes so they should be able to work through

@gautamsi
Copy link
Member

Can you do that in upcoming breaking change ? It will streamline [validateInput | resolveInput | beforeOperation | afterOperation].[create | update | delete]

@dcousens
Copy link
Member Author

dcousens commented Sep 25, 2023

@gautamsi that is my intent, yes - and I might add support earlier as you said, with a throw, but I don't want to block on that

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 this pull request may close these issues.

None yet

3 participants