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

[Do not merge] Example of adding hooks to mutation #78

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ninabernick
Copy link
Collaborator

Example of adding hooks to create, update, delete mutations. This example validates the name of a sample before it is created.

Right now a before callback receives three args (inputs to the mutation) and the after callback receives four (inputs to the mutation + the result). This is weird.


after_callback = RegisteredPlatformicsPlugins.getCallback("after", self.type, self.action)
if after_callback:
result = after_callback(result, source, info, **kwargs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should before and after callbacks accept the same number of args?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd also send the result to the after callbacks so that they can manipulate the result



@register_plugin("before", "sample", "create")
def validate_sample_name(source: Any, info: Info, **kwargs: SampleCreateInput) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think **kwargs might include everything that gets sent to the resolver, so in addition to SampleCreateInput, session, cerbos_client, principal, is_system_user, etc.

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.

3 participants