Skip to content

get_node is not called on related objects #776

Closed
@McPo

Description

@McPo

Currently get_node is not called on related models. i.e.

class Customer(models.Model):
    display_name = models.CharField()
    ....

class Member(models.Model):
    customer = models.ForeignKey(Customer)
    ....
class Customer(DjangoObjectType):
    class Meta:
        model = models.Customer
        filter_fields = []
        interfaces = [graphene.Node]

    @classmethod
    def get_node(cls, info, id):
        print('NEVER CALLED')
        return None

Then querying with

member(id:"...") {
    customer {
        id
    }
}

Does not result in get_node being called. this is because get_node is only called on Relay Nodes. However relay nodes expect an ID to be passed in via GraphQL. Instead I would like the get_node to be called with the id for the related object.

If this support was added it means you can add per-object level auth.

Furthermore as get_node calls get_queryset, all you would have to do is to filter out all the objects a user isn't allowed to access i.e.

class Customer(DjangoObjectType):

    @classmethod
    def get_queryset(cls, queryset, info):
        return queryset.filter(admins__in=[info.context.user])

For example lets say Im allowed to see a list of Members, some of those Members are not under the Customer that I am an admin of. However I should still be able to interact with them, as they have some other relationship to my Customer. Maybe the Member is related to another Member under my Customer, and I can access them via that path. However I don't want to to give an admin the ability to view other Customers. This would achieve that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions