Created
December 18, 2020 07:18
-
-
Save devxoul/4829d3a31561afd11a4851a281497a42 to your computer and use it in GitHub Desktop.
Graphene NonNullConnection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NonNullConnection(graphene.relay.Connection): | |
class Meta: | |
abstract = True | |
@classmethod | |
def __init_subclass_with_meta__(cls, node=None, **options): | |
if node is not None and not isinstance(node, graphene.NonNull): | |
node = graphene.NonNull(node) | |
super(NonNullConnection, cls).__init_subclass_with_meta__( | |
node=node, **options | |
) | |
edges_field: graphene.Field = cls._meta.fields['edges'] | |
field_type: graphene.NonNull = edges_field._type | |
edges: graphene.List = field_type._of_type | |
edge = edges._of_type | |
cls._meta.fields['edges'] = graphene.Field( | |
graphene.NonNull( | |
graphene.List( | |
graphene.NonNull(edge) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment