| 13 | |
| 14 | |
| 15 | class Query(graphene.ObjectType): |
| 16 | # Add the first and skip parameters |
| 17 | links = graphene.List( |
| 18 | LinkType, |
| 19 | search=graphene.String(), |
| 20 | first=graphene.Int(), |
| 21 | skip=graphene.Int(), |
| 22 | ) |
| 23 | votes = graphene.List(VoteType) |
| 24 | |
| 25 | # Use them to slice the Django queryset |
| 26 | def resolve_links(self, |
| 27 | info, |
| 28 | search=None, |
| 29 | first=None, |
| 30 | skip=None, |
| 31 | **kwargs): |
| 32 | qs = Link.objects.all() |
| 33 | |
| 34 | if search: |
| 35 | filter = (Q(url__icontains=search) |
| 36 | | Q(description__icontains=search)) |
| 37 | qs = qs.filter(filter) |
| 38 | |
| 39 | if skip: |
| 40 | qs = qs[skip:] |
| 41 | |
| 42 | if first: |
| 43 | qs = qs[:first] |
| 44 | |
| 45 | return qs |
| 46 | |
| 47 | def resolve_votes(self, info, **kwargs): |
| 48 | return Vote.objects.all() |
| 49 | |
| 50 | |
| 51 | class CreateLink(graphene.Mutation): |
nothing calls this directly
no outgoing calls
no test coverage detected