Skip to content

how to personalize resolve DjangoObjectType #1169

Answered by louisdvs
yoelvysmartinez asked this question in Q&A
Discussion options

You must be logged in to vote

You shouldn't be trying to add a resolver for Cities on the Country Node. The only reason you would add a field and resolver directly on the Type definition is if it is not defined in the django model.

You should be able to add the custom resolver in your query, like:

class Query(object):
    city = relay.Node.Field(CityNode)
    all_cities = DjangoFilterConnectionField(CityNode)

    def resolve_all_cities(self, info):
        if not info.context.user.is_authenticated():
            return City.objects.none()
        else:
            return City.objects.all()`

Hope this helps. Cheers

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by zbyte64
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #583 on April 14, 2021 20:08.