GraphQLBundle icon indicating copy to clipboard operation
GraphQLBundle copied to clipboard

json_encoding_options

Open drmax24 opened this issue 4 years ago • 2 comments

Q A
Bug report? no
Feature request? yes
Version/Branch 0.13.5

Hi. We need to add json_encoding_options to graphql response. We need response to be encoded JSON_UNESCAPED_UNICODE. Because encoding of type \u423 \u422 \u429 doubles the bandwidth compared to standard utf8 if they sent via utf8. Can you please add the feature to set json_encoding_options in a graphql config?

drmax24 avatar Mar 19 '21 07:03 drmax24

Hi. I think its possible, but there is some ugliness in it maybe. Need to work with number or (multiple) const expressions (php = okay, yaml = meh) in your config.

The encoding is currently handled by symfony JsonResponse (HttpFoundation) returned from GraphqlController. So what you might also do is listen to symfony kernel.response event, check for JsonResponse and call setEncodingOptions on the instance. Assuming you want the behavior for all JsonResponse. Outside the scope, you also can return json using Response object, which would not be handled. But GraphqlController does use JsonResponse object.

akomm avatar Mar 23 '21 16:03 akomm

https://github.com/rebing/graphql-laravel this graphql library allows to set JSON_UNESCAPED_UNICODE in a config file

i would request this convenience as a feature...

'json_encoding_options'  => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES

drmax24 avatar Apr 09 '21 11:04 drmax24