Giter Site home page Giter Site logo

Comments (9)

bellini666 avatar bellini666 commented on August 16, 2024 2

@dennisv you need to define your connection as a generic class, just like the original, and pass the NodeType captured by the Generic in Connection, just like this:

@gql.type
class CustomConnection(Generic[NodeType], Connection[NodeType]):
    ...

from strawberry-django-plus.

dennisv avatar dennisv commented on August 16, 2024 2

Thanks for the quick fix and feedback @bellini666 !

I got it to work by doing this:

from strawberry_django_plus.relay import NodeType

@gql.type
class CustomConnection(gql.Connection[NodeType]):
    ...

from strawberry-django-plus.

bellini666 avatar bellini666 commented on August 16, 2024 1

@K0Te I just made this change (0762f40) which got released in 1.23.

It allows to define a custom Connection class for a Node, similar to how graphene does. It also allows the Connection to define a custom Edge.

Do you think this is enough?

from strawberry-django-plus.

bellini666 avatar bellini666 commented on August 16, 2024

Hi @eloff ,

Currently you would need to implement your own Edge and Connection classes and override their logic. But I'm thinking in how to make that relay implementation more generic to allow things like what you want to do.

I'll probably take a look at this soon

from strawberry-django-plus.

eloff avatar eloff commented on August 16, 2024

Ok, good to know. I'll come up with a temporary workaround for now, but I'll revisit it when you close this ticket.

from strawberry-django-plus.

K0Te avatar K0Te commented on August 16, 2024

More generic connections would simplify migration from graphene-django.
I am currently migrating project that uses multiple subtotals in connections.
For example:

class AccountClientConnection(Connection):
    total_account_clients = graphene.Int()
    total_active_account_clients = graphene.Int()
    active_clients_count = graphene.Int()

Such use-case is trivial with graphene-django connection_class, but complicated with the current connection implementation in strawberry.

from strawberry-django-plus.

dennisv avatar dennisv commented on August 16, 2024

@bellini666 I'm trying to add some fields to a connection as well and can't seem to get it to work using CONNECTION_CLASS

Could it be that it is still always using the default Connection because of this line?

Connection[get_args(resolved)[0]], # type:ignore

I'm trying it like this:

@gql.django.type(models.ObjectType)
class ObjectType(gql.Node):
    name: gql.auto

@gql.type
class TestObjectTypeConnection(gql.Connection):
    test: str = "test"

ObjectType.CONNECTION_CLASS = TestObjectTypeConnection

@gql.type
class ObjectTypeQuery:
    @gql.connection
    def object_types(
        self,
        ...
    ) -> Iterable[ObjectType]:
        ...

But the test field does not show up in graphiql and returns "Cannot query field 'test' on type 'ObjectTypeConnection'."

from strawberry-django-plus.

bellini666 avatar bellini666 commented on August 16, 2024

Hey @dennisv ,

I just noticed that the field was not using the CONNECTION_CLASS to create itself.
I just published the version 1.25.1, which should solve this issue. Can you please try to use it and confirm to me if it works?

from strawberry-django-plus.

dennisv avatar dennisv commented on August 16, 2024

@bellini666 I get a bit further now, but it's now throwing the following:
TypeError: <class '[...].TestObjectTypeConnection'> is not a generic class

from strawberry-django-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.