docs: document running a processor on read operations (write: true)#2295
Merged
Conversation
Closes api-platform/core#8089 — users declaring processor: on GetCollection found the processor silently ignored. Root cause: WriteProcessor skips dispatch when the operation's write flag is false, which is the default for safe methods (GET/GetCollection). Setting write: true opts the operation into running the processor, which doubles as the command/query handler in a CQRS design.
8947159 to
e0806c4
Compare
Member
Author
|
we eventually need to rename or alias |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gap
Declaring a
processor:on aGetCollection(orGET) operation silently does nothing — the processor is never invoked. This trips users up (see api-platform/core#8089) and is currently undocumented.Why
WriteProcessoronly dispatches to a custom processor when the operation'swriteflag is truthy. For safe HTTP methods (GET/GetCollection)writedefaults tofalse, so the processor is skipped. Settingwrite: trueopts the operation in.What
New section in
core/state-processors.md: Running a Processor on Read (GET) Operations.writeflag default andWriteProcessordispatch.processor= command/query handler,provider= read/query side — withwrite: truea processor serves as the handler for a read operation, completing the CQRS picture already referenced at the top of the page.Closes api-platform/core#8089
Note:
canWrite()/ thewriteflag is semantically "run the processor", not strictly "mutate state" — worth a rename later, but documenting the current behavior first.