Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSet Serialization Groups Manually [feature] #1610
Comments
You can already do this easily by implementing the Also, please note that using request attributes will not work when using GraphQL (because a single HTTP request can contain many GraphQL request). Can you tell us a bit more about your use case? |
I didn't like your "way". Now I'm trying to make interceptors. Then I can make a group just like that (by Intercepting the request) $user = $this->security->getUser();
if ($user and ($this->security->isGranted('ROLE_ADMIN'))) {
// $key '_api_normalization_context' or '_api_serializer_context'
$context = $request->attributes->get($key);
if (!$context) {
$context = [];
}
$context['groups'][] = 'admin';
$context['groups'] = array_unique($context['groups']);
$request->attributes->set($key, $context);
} |
You can do it as easily by doing as in the example I provided isn't it? That being said I'm not against supporting such attribute (especially because it will be a very tiny patch to support it). |
I don't understand well how it works. I did an ugly hack on my fork. If you do it right. And it will work as well. I will grateful to you. |
I'm not sure. Combining REST and GraphQL will end well. I think they are too different to combine. One will limit the other. Undoubtedly.
It is possible to leave common components as a dependency for both (api-core or something else). |
Description
Make it possible to define the serialization group through the request attributes.
Something like this:
Example
https://github.com/api-platform/core/blob/22ce6399180f9408f19b0b3c857317d2ddd7ea9d/src/Serializer/SerializerContextBuilder.php#L60