Skip to content

Instantly share code, notes, and snippets.

@richmondwang
Created March 31, 2017 07:17
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 richmondwang/247626fb005e2605dbfd55b11a4e7e7c to your computer and use it in GitHub Desktop.
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.
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