-
Notifications
You must be signed in to change notification settings - Fork 764
DjangoConnectionField should have non-null edge and node types #901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jarcoal I think you're right in your assumptions however the underlying ConnectionField class is defined in Graphene (https://github.com/graphql-python/graphene/blob/master/graphene/relay/connection.py) and the Relay GraphQL spec doesn't define the edges to be required: https://relay.dev/graphql/connections.htm I think it makes sense for the DjangoConnectionField to have required edges (because of it's implementation) but it might be a bit tricky to implement. If you can create a PR for it that would be great though! Let me know if you need any help. |
I'm also having problems here. With a |
Same problem here! IMO at least we should have an option to make edges and nodes to be required. |
same problem here! @jarcoal I also think that you are right |
same problem, has anyone found a workaround for this? |
I am able to work around this with the following connection subclass: class MyConnection(Connection):
@classmethod
def __init_subclass_with_meta__(cls, node=None, **options):
type_name = re.sub("Connection$", "", cls.__name__)
node_for_edge = node
if node != None and not isinstance(node, NonNull):
node_for_edge = NonNull(node)
class Edge(ObjectType):
node = Field(node_for_edge, description="The item at the end of the edge")
cursor = String(required=True, description="A cursor for use in pagination")
class Meta:
description = f"A Relay edge containing a `{type_name}` and its cursor."
edge_type = type(f"{type_name}Edge", (Edge,), {"Meta": Meta})
cls.Edge = edge_type
cls.edges = Field(
NonNull(List(NonNull(edge_type))),
description="Contains the nodes in this connection.",
)
super(MyConnection, cls).__init_subclass_with_meta__(node=node, **options) This can be used in a subclass of class MyObject(DjangoObjectType):
class Meta:
connection_class = MyConnection As well, I opened this PR which if it lands would obviate the need for a custom subclass: graphql-python/graphene#1504 |
I believe this issue has been fixed upstream by the release of graphene 3.3.0, since graphql-python/graphene#1504 has been merged. It is not the default behavior for backwards compat, but can be made so with the following much simpler connection subclass: class MyConnection(Connection):
@classmethod
def __init_subclass_with_meta__(cls, **options):
options['strict_types'] = options.pop('strict_types', True)
super(MyConnection, cls).__init_subclass_with_meta__(**options) |
I've tried the subclass snippet here and get this error:
Any examples for implementing that Thanks! |
There's been a bit of discussion around this in #566 and #560 , but I really think this should get another look.
Currently
DjangoConnectionField
'sedges
property is required, but the types inside are not:Given how
DjangoConnectionField
works, it's not really possible forEdgeType
to be optional. It should look like this:And then if you look at the
EdgeType
itself,node
is optional:But that also is never going to happen. It should be required:
Before I start digging and open a PR, are these assumptions correct? Or am I missing something?
The text was updated successfully, but these errors were encountered: