-
Notifications
You must be signed in to change notification settings - Fork 53
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
Convert API response JSON to Python dict #26
Convert API response JSON to Python dict #26
Conversation
This PR addresses the issue #25 |
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.
👍
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.
@lucioseki my proposal here is to change response.text
to response.json()
in the graphql client. That's the source of the issue.
Note: requests
will raise an exception if you call .json
on a response object that does not contain a 2xx or 4xx status code, that can either be handle explicitly by you, or you can call response.raise_for_status()
before moving on to calling response.json
.
Some methods in this library are returning the API response JSON string without converting it to a Python dict. This is forcing the caller to selectively call json.loads depending on the retrieved resource (e.g. `users` resource requires json.loads, but `items` doesn't). This patch makes all the API responses to be converted to a Python dict, so the caller can consistently use the return value as a dict regardless the requested resource.
Currently, the library converts the response.text returned by the GraphQL client to a Python dict using json.loads. But the requests library already has a builtin JSON decoder that converts a JSON response to a Python dict. This patch makes the GraphQL return the response.json() result. The callers no longer need to convert the return value to a dict.
also some code cleanup
5eae55b
to
669bb0e
Compare
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.
This looks good! Thanks for addressing all the comments!
Some methods in this library are returning the API response JSON
string without converting it to a Python dict.
This is forcing the caller to selectively call
json.loads
depending on the retrieved resource (e.g.
users
resource requiresjson.loads
, butitems
doesn't).This patch makes all the API responses to be converted to a Python
dict, so the caller can consistently use the return value as a dict
regardless the requested resource.