-
Notifications
You must be signed in to change notification settings - Fork 1
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
Deprecate decoding using atoms #69
Conversation
Nice job 😄 I don't know if someone has anything else to say |
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.
Overall the approach is good, I'd change a couple of things:
- I would rename the
decoder
param todecode_keys
everywhere, to be more consistent with the naming ofencode_variables
andformat_variables
- I would personally restrict the
decode_keys
option to just:atoms
and:strings
, because:- I don't think the behavior of the
existing_atoms
is something desirable (throwing an error doesn't look very robust) - I feel that providing a custom decoder function is a bit out of scope for the goal in the Roadmap and I don't see any use-cases for that
- I don't think the behavior of the
As for the custom decoder, I think it's worthwhile since it would allow decoding non-json endpoints like, for instance, gRPC (or XML 😱). Having custom decoders is almost "zero effort" on this lib side, and allows more flexibility on the user side. |
Ok, you convinced me 😄
Non-JSON endpoints are not supported by the library (since it's fully committed to GraphQL) and won't be for the foreseeable future. |
Ah yes, I didn't consider it at all! Ok you convinced me this time 😄 |
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.
I've proposed a few nitpicks/improvements to the documentation, the rest is already looking good
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.
I've pushed a small fix for an unrelated typo that screwed up the documentation on HexDocs.
LGTM!
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.
Nice 🎉
Updated
Client.call
function, which now also accepts adecoder
(just before options). Decoder is just a function with arity 1 which accepts a body and returns a tuple{:ok, decoded_body}
or{:error, any}
. Since the arity of thecall
function has changed, I also created a (deprecated) function with the old arity which fallbacks to atoms keeping the current behavior intact.Updated the
BridgeEx.Graphql
macro, which now accepts thedecoder
too, and prints a warning when it's not provided (since it falls back to atom decoding).Also provided three basic decoders in the
Utils
module (to decode keys instrings
,atoms
andexisting_atoms
) which simply mirrorJason
behavior. This approach allows lib users to define their own decode functions which may be useful for some applications.