-
Notifications
You must be signed in to change notification settings - Fork 823
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
There's some way to set the source
field param for nested fields?
#1439
Comments
I think you'll need to create a resolver returning root.actor.login/resolving the actor first depending on your setup. |
Yeah, but since it's only field configuration I created a function to generate the resolver itself: def subfield(source, separator='.'):
def resolver(self, info, *args, **kwargs):
value = self
for part in source.split(separator):
value = getattr(value, part)
return value
return resolver
def source(source, separator='.'):
return {'resolver': subfield(source, separator)} Usage: class User(DjangoObjectType):
class Meta:
model = UserModel
exclude = ['actor']
filter_fields = ['actor__login']
interfaces = [Node]
skip_registry = True
login = graphene.Field(graphene.String, **source('actor.login'))
# ... |
Sorry for the late reply, didn't get the notification. Looks interesting! Do you want to open a PR and integrate it into the main repo? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
I'm currently trying to set my model user
User
subfielduser.actor.id
as field source of myDjangoObjectType
.This happens because there's other kind of users within the application like an
Organization
or even aBot
(all of them are actors).Example
Lets define a custom
Type
:In the example above I define the login field source as
source='actor__login'
but I saw that here we're usinggetattr
function to resolve the source so it's currently impossible to set the field without defining a custom resolver.graphene/graphene/types/field.py
Lines 16 to 20 in dfece7f
I would like to know if there's an alternative solution to select a subfield like the example or we're forced to create a custom resolver by using the
resolver=lambda _, __: ...
arg or the class method declaration.Thanks for the hard work and the library!
The text was updated successfully, but these errors were encountered: