Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@devxoul
Created December 18, 2020 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/4829d3a31561afd11a4851a281497a42 to your computer and use it in GitHub Desktop.
Save devxoul/4829d3a31561afd11a4851a281497a42 to your computer and use it in GitHub Desktop.
Graphene NonNullConnection
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