-
Notifications
You must be signed in to change notification settings - Fork 176
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
Bidirectional scalars #24
Conversation
Codecov Report
@@ Coverage Diff @@
## master #24 +/- ##
==========================================
+ Coverage 99.5% 99.62% +0.11%
==========================================
Files 7 8 +1
Lines 202 265 +63
==========================================
+ Hits 201 264 +63
Misses 1 1
Continue to review full report at Codecov.
|
@salwator I've renamed |
ariadne/resolvers.py
Outdated
def add_resolve_functions_to_scalar(name: str, obj: GraphQLObjectType, resolvers: dict): | ||
scalar_resolvers = resolvers.get(name, {}) | ||
|
||
serializer = scalar_resolvers.get("serializer", obj.serialize) |
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.
Nitpick: parse_*
are imperative verbs, serializer
is a noun.
ariadne/resolvers.py
Outdated
obj.serialize = serializer | ||
|
||
parse_literal = scalar_resolvers.get("parse_literal", obj.parse_literal) |
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.
Maybe we could default to calling parse_value
with ast.value
when only one function is provided?
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 requires further study. IntValue
, StringValue
and friends are obvious to deal with, but but complex types like ListValue
may require some extra unpacking magic.
Imho its worth pursuing in separate task.
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.
tests/test_custom_scalars.py
Outdated
|
||
from ariadne import make_executable_schema | ||
|
||
type_defs = """ |
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.
We might want to use ALL_CAPITAL_WITH_UNDERSCORE convention for constants, just like pep8 suggests.
This is especially useful when dealing with module-scoped entities.
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 don't have strong opinion either way, but I've been looking at type_defs
and resolvers
more like Django's urlpatterns
that are supposed to be defined and modified as it is comfortable to the dev. I know that people will look at our tests suite for examples and inspiration, and hence wanted this approach to be reflected in them.
ad52408
to
21455d2
Compare
This PR updates
add_resolve_functions_to_schema
to passserializer
,parse_literal
andparse_value
functions toScalar
.Fixes #13
TODO