-
-
Notifications
You must be signed in to change notification settings - Fork 921
publish to mercure preserving the request's format and also respect t… #2672
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
Conversation
…he entity's serializer context
I thought about this during the initial implementation, unfortunately I don’t think that this design can work: we have no clue about what format is expected by the subscriber, and using the format used by the publisher may fail. Example: 1st publisher sends a JSON-LD request Subscribers receive messages in mixed formats. It doesn’t work. What we could do instead is:
WDYT? |
PS: i got it, client one using hal sends a request, client two who’s also subscribed uses jsonld. End of the internet :) options #1 and #2 are the same as having it hardcoded, still forcing the subscriber to a certain format, rather than letting them choose the format they want. so i'll start working on option #3, if it's ok. |
i realized the 3rd option involves mercure, as the topic is a request to that, not the api platform. |
@@ -47,8 +48,10 @@ final class PublishMercureUpdatesListener | |||
private $createdEntities; | |||
private $updatedEntities; | |||
private $deletedEntities; | |||
private $requestStack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn’t use request stack here, because it makes the feature not fully compliant with GraphQL, and create a hard dependency to Symfony (we want to support Laravel and maybe PSR-7 at some point).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only solution i see is making use of $GLOBALS['request']... unless api-platform has some other way to get the current request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, i think Laravel also uses Symfony's HttpFoundation...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we have our own abstraction layer: https://github.com/api-platform/core/blob/master/src/EventListener/ReadListener.php#L64-L69
However I'm not sure it's the good way to handle this problem. I would only make the format configurable for now.
Yes Laravel uses HttpFoundation, but it doesn't use the RequestStack
class.
Well, i’d say the context is way more important and required. Otherwise the mercure message will contain sensitive information about the object or object relations which someone might not include in a respose. Also, the message itself will grow a lot. I’ve had messages of 8MB and 12MB dispatched by mercure because it included information i didnt want, which i doubt it’s ok. |
Indeed it's a big issue. Maybe could we always use the default normalization context for now, so we don't have to depend on the request?
I've another idea in mind for this specific problem: we should add the option to dispatch only the properties that changed. The client will have to patch the document it retrieved originally using the API.
|
But the issue will still exist on the PUT method and disabling it isn't an option. wdyt? |
Maybe was I unclear: the idea is to serialize the Mercure Payload using the JSON Merge PATCH format for all HTTP verbs (except To summaries: When the publisher send a |
|
Oh, now i get it. |
switching to 2.4 as bug fix |
publish to mercure preserving the request's format and also respect the entity's serializer context