Created
March 31, 2017 07:17
-
-
Save richmondwang/247626fb005e2605dbfd55b11a4e7e7c to your computer and use it in GitHub Desktop.
Connection factory for graphene-sqlalchemy. This will add the field `totalCount` based on the specification of graphql.
This file contains 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
def connection_for_type(_type): | |
"""Added totalCount node on the Connectionfield""" | |
class Connection(graphene.Connection): | |
total_count = graphene.Int( | |
description="Total count of {}s.".format(_type._meta.name)) | |
class Meta: | |
description = name = _type._meta.name + 'Connection' | |
node = _type | |
def resolve_total_count(self, args, context, info): | |
return self.length | |
return Connection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment