MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / CreateVote

Class CreateVote

hackernews/backend-python/links/schema.py:79–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78
79class 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
103class VoteType(DjangoObjectType):

Callers 1

mutateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected