| 77 | |
| 78 | |
| 79 | class CreateVote(graphene.Mutation): |
| 80 | user = graphene.Field(UserType) |
| 81 | link = graphene.Field(LinkType) |
| 82 | |
| 83 | class Arguments: |
| 84 | link_id = graphene.Int() |
| 85 | |
| 86 | def mutate(self, info, link_id): |
| 87 | user = info.context.user |
| 88 | if user.is_anonymous: |
| 89 | raise GraphQLError('You must be logged to vote!') |
| 90 | |
| 91 | link = Link.objects.filter(id=link_id).first() |
| 92 | if not link: |
| 93 | raise Exception('Invalid Link!') |
| 94 | |
| 95 | Vote.objects.create( |
| 96 | user=user, |
| 97 | link=link, |
| 98 | ) |
| 99 | |
| 100 | return CreateVote(user=user, link=link) |
| 101 | |
| 102 | |
| 103 | class VoteType(DjangoObjectType): |