Skip to content

Commit

Permalink
Merge pull request #7 from sennder/feature/pagination
Browse files Browse the repository at this point in the history
Pagination
  • Loading branch information
edelvalle authored Jul 14, 2017
2 parents 8fddf40 + 67469a6 commit e66efcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.egg-info/
.cache/
__pycache__/
/.idea/
19 changes: 17 additions & 2 deletions carbon14/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,28 @@ class ModelCollection(Collection):

_auth_required = True

def _resolve(self, level, instances, ctx, ids=None, **kwargs):
def _resolve(
self,
level,
instances,
ctx,
ids=None,
limit=None,
offset=0,
**kwargs
):
if self._auth_required and not ctx.user.is_authenticated():
instances = instances.none()
else:
if ids is not None:
instances = instances.filter(id__in=ids)
return instances.all()

instances = instances.all()[offset:]

if limit:
instances = instances[:limit]

return instances


class GraphQLView(APIView):
Expand Down

0 comments on commit e66efcd

Please sign in to comment.