-
Notifications
You must be signed in to change notification settings - Fork 766
-
Is there a way to get direct access to a nodes
list alongside with totalCount
inside DjangoFilterConnectionField
?
I'm going after this schema structure (from the GitHub GraphQL API)
type LabelConnection { edges: [LabelEdge] nodes: [Label] # <-- nodes shorthand pageInfo: PageInfo! totalCount: Int! }
I tried subclassing both ConnectionField
and DjangoFilterConnectionField
but without luck
Beta Was this translation helpful? Give feedback.
All reactions
Found a very hacky workaround for anyone interested, this patch works for
graphene==2.1.9
graphql-relay==2.0.1
graphene-django==2.15.0
You'll need to patch the packages after install.
--- site-packages/graphql_relay/connection/connectiontypes.py 2022年05月21日 14:17:29.000000000 +0200 +++ site-packages/graphql_relay/connection/connectiontypes.py 2022年05月21日 14:17:17.000000000 +0200 @@ -1,13 +1,17 @@ class Connection(object): - def __init__(self, edges, page_info): + def __init__(self, edges, page_info, nodes, total_count): self.edges = edges self.page_info = page_info + self.nodes = nodes + self.total_count = total_count def to_dict(self): ...
Replies: 2 comments 2 replies
-
Found a very hacky workaround for anyone interested, this patch works for
graphene==2.1.9
graphql-relay==2.0.1
graphene-django==2.15.0
You'll need to patch the packages after install.
--- site-packages/graphql_relay/connection/connectiontypes.py 2022年05月21日 14:17:29.000000000 +0200 +++ site-packages/graphql_relay/connection/connectiontypes.py 2022年05月21日 14:17:17.000000000 +0200 @@ -1,13 +1,17 @@ class Connection(object): - def __init__(self, edges, page_info): + def __init__(self, edges, page_info, nodes, total_count): self.edges = edges self.page_info = page_info + self.nodes = nodes + self.total_count = total_count def to_dict(self): return { 'edges': [e.to_dict() for e in self.edges], 'pageInfo': self.page_info.to_dict(), + 'nodes': self.nodes, + 'totalCount': len(self.nodes) }
--- site-packages/graphql_relay/connection/arrayconnection.py 2022年05月21日 14:06:15.000000000 +0200 +++ site-packages/graphql_relay/connection/arrayconnection.py 2022年05月21日 14:04:43.000000000 +0200 @@ -95,6 +95,8 @@ return connection_type( edges=edges, + nodes=_slice, + total_count=list_length, page_info=pageinfo_type( start_cursor=first_edge_cursor, end_cursor=last_edge_cursor,
--- site-packages/graphene/relay/connection.py 2022年05月21日 14:06:29.000000000 +0200 +++ site-packages/graphene/relay/connection.py 2022年05月21日 14:11:51.000000000 +0200 @@ -91,6 +91,7 @@ cls.Edge = edge options["name"] = name + options["description"] = "The connection type for {}.".format(base_name) _meta.node = node _meta.fields = OrderedDict( [ @@ -106,10 +107,26 @@ ( "edges", Field( - NonNull(List(edge)), + # NonNull(List(edge)), + NonNull(List(NonNull(edge))), description="Contains the nodes in this connection.", ), ), + ( + "nodes", + Field( + # NonNull(List(_node)), + NonNull(List(NonNull(_node))), + description="A list of nodes.", + ), + ), + ( + "total_count", + Field( + NonNull(Int), + description="Identifies the total count of items in the connection.", + ), + ), ] ) return super(Connection, cls).__init_subclass_with_meta__(
Beta Was this translation helpful? Give feedback.
All reactions
-
Ma diventerà mai una feature ufficiale? Non riusciamo ad ottenerla estendendo qualcosa?
Beta Was this translation helpful? Give feedback.
All reactions
-
From the looks of it, doesn't looks like it's ever going to make it as a feature.
I've been using strawberrygraphql before moving away from python, it seemed very promising
Beta Was this translation helpful? Give feedback.
All reactions
-
Io stavo guardando anche questo per restare in
django https://pypi.org/project/graphene-django-extras/
Beta Was this translation helpful? Give feedback.