YAML as a result format instead of JSON
alexander-myltsev opened this issue · 5 comments
alexander-myltsev commented
Is there an easy way to override the serializer to return YAML instead of JSON?
rscarrera27 commented
How about this script
import yaml
yaml.dump(<json obj>)alexander-myltsev commented
@devArtoria I know how to dump YAML :) Whal elements of Flask-GraphQL should I override to paste your code in?
rscarrera27 commented
GraphQLView is works as view function for graphql endpoint, and GraphQLView's dispatch_request is dispatch request. it uses get_response to make response with json_encode. if you want GraphQLView return YAML, just edit get_response to user your own yaml_encode
def get_response(self, request, data, show_graphiql=False):
query, variables, operation_name, id = self.get_graphql_params(request, data)
execution_result = self.execute_graphql_request(
data,
query,
variables,
operation_name,
show_graphiql
)
status_code = 200
if execution_result:
response = {}
......
result = self.json_encode(request, response, show_graphiql) <<<<< THIS PART
else:
result = None I hope my answer is helpful.
rscarrera27 commented
@alexander-myltsev Could I close this?
alexander-myltsev commented
Yes, thanks.