docs: Fix examples for builtin before_action and after_action preparations (#1439)

This commit is contained in:
Rebecca Le 2024-09-06 12:24:02 +08:00 committed by GitHub
parent 295778bbf5
commit b13181730b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,11 +39,12 @@ defmodule Ash.Resource.Preparation.Builtins do
@doc ~S"""
Directly attach a `before_action` function to the query.
See `Ash.Query.before_action/2` for more information.
This function will be called by `Ash.Query.before_action/2`,
with an additional `context` argument.
## Example
prepare before_action(fn query ->
prepare before_action(fn query, _context ->
Logger.debug("About to execute query for #{query.action.name} on #{inspect(query.resource)}")
query
@ -63,11 +64,12 @@ defmodule Ash.Resource.Preparation.Builtins do
@doc ~S"""
Directly attach an `after_action` function to the query.
See `Ash.Query.after_action/2` for more information.
This function will be called by `Ash.Query.after_action/2`,
with an additional `context` argument.
## Example
prepare after_action(fn query, records ->
prepare after_action(fn query, records, _context ->
Logger.debug("Query for #{query.action.name} on resource #{inspect(query.resource)} returned #{length(records)} records")
{:ok, records}