Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Non-obvious moments when overloading the Connection #160

Open
iamcrookedman opened this issue Dec 28, 2022 · 1 comment
Open

Non-obvious moments when overloading the Connection #160

iamcrookedman opened this issue Dec 28, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@iamcrookedman
Copy link

Hello
I tried to define a custom Connection class to extend it with the data I need.
For this, the Node class was also redefined, and I encountered non-obvious behavior when defining the resolve_connection method

def _has_own_node_resolver(cls, name: str) -> bool:
    resolver = getattr(cls, name, None)
    if resolver is None:
        return False

    if id(resolver.__func__) == id(getattr(Node, name).__func__):
        return False

    return True

It turns out that the method described in the Node class is replaced by default with another one, and when defining a custom class, it is impossible to call super of the parent class
In other words, when defining a class and at runtime, we have different resolvers
What is the reason for this behaviour? Wouldn't it be better to immediately set the necessary behavior in the Node class?

@bellini666
Copy link
Member

What is the reason for this behaviour? Wouldn't it be better to immediately set the necessary behavior in the Node class?

The relay implementation was written to be as generic as possible, to be able to use with non-django types as well. The django type replaces the NotImplemented methods with their own, which resolves them taking querysets into consideration.

I understand that it makes using super impossible, but it is basically a limitation of the dataclass approach that strawberry in general uses. For example. when using @dataclasses.dataclass and passing eq=True or order=True, since the class already exists when it is being processed, those methods will be injected in it if they don't exist, meaning they are part of the MRO and super also cannot be used.

Currently the only way to call the original method is actually to call the method they are calling by hand. For example, if you define your own resolve_connection, you can just call resolvers.resolve_connection and pass the relevant args to it, just like the injected methods does.

But I'm open to suggestions on how to improve this

@bellini666 bellini666 added enhancement New feature or request help wanted Extra attention is needed labels Dec 28, 2022
frleb pushed a commit to frleb/strawberry-django-plus that referenced this issue Feb 28, 2023
…ptions

feat: Use Django textual metadata in GraphQL
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants