3
3
from graphene_django import DjangoObjectType
4
4
from django .contrib .auth import get_user_model
5
5
6
- from links .models import Link
6
+ from links .models import Link as LinkModel
7
7
from links .models import Vote
8
8
9
9
10
- class LinkType (DjangoObjectType ):
10
+ class Link (DjangoObjectType ):
11
11
class Meta :
12
- model = Link
12
+ model = LinkModel
13
13
14
14
15
- class VoteType (DjangoObjectType ):
15
+ class Vote (DjangoObjectType ):
16
16
class Meta :
17
17
model = Vote
18
18
19
19
20
- class UserType (DjangoObjectType ):
20
+ class User (DjangoObjectType ):
21
21
class Meta :
22
22
model = get_user_model ()
23
23
@@ -26,7 +26,7 @@ class CreateLink(graphene.Mutation):
26
26
id = graphene .Int ()
27
27
url = graphene .String ()
28
28
description = graphene .String ()
29
- postedBy = graphene .Field (UserType )
29
+ postedBy = graphene .Field (User )
30
30
31
31
class Arguments :
32
32
url = graphene .String ()
@@ -36,7 +36,7 @@ def mutate(self, info, url, description):
36
36
user = info .context .user
37
37
if user .is_anonymous :
38
38
raise Exception ("Anonymous users can't create links!" )
39
- link = Link (url = url , description = description , posted_by = user )
39
+ link = LinkModel (url = url , description = description , posted_by = user )
40
40
link .save ()
41
41
42
42
return CreateLink (
@@ -48,8 +48,8 @@ def mutate(self, info, url, description):
48
48
49
49
50
50
class CreateVote (graphene .Mutation ):
51
- user = graphene .Field (UserType )
52
- link = graphene .Field (LinkType )
51
+ user = graphene .Field (User )
52
+ link = graphene .Field (Link )
53
53
54
54
class Arguments :
55
55
linkId = graphene .Int ()
@@ -58,7 +58,7 @@ def mutate(self, info, linkId):
58
58
user = info .context .user
59
59
if user .is_anonymous :
60
60
raise Exception ("You must be logged in to vote!" )
61
- link = Link .objects .filter (id = linkId ).first ()
61
+ link = LinkModel .objects .filter (id = linkId ).first ()
62
62
if link is None :
63
63
raise Exception (f"The link ={ linkId } is invalid." )
64
64
@@ -68,7 +68,7 @@ def mutate(self, info, linkId):
68
68
69
69
70
70
class CreateUser (graphene .Mutation ):
71
- user = graphene .Field (UserType )
71
+ user = graphene .Field (User )
72
72
73
73
class Arguments :
74
74
username = graphene .String (required = True )
@@ -96,13 +96,13 @@ class Mutation(graphene.ObjectType):
96
96
97
97
98
98
class Query (graphene .ObjectType ):
99
- links = graphene .List (LinkType )
100
- votes = graphene .List (VoteType )
101
- users = graphene .List (UserType )
102
- whoami = graphene .Field (UserType )
99
+ links = graphene .List (Link )
100
+ votes = graphene .List (Vote )
101
+ users = graphene .List (User )
102
+ whoami = graphene .Field (User )
103
103
104
104
def resolve_links (self , info , ** kwargs ):
105
- return Link .objects .all ()
105
+ return LinkModel .objects .all ()
106
106
107
107
def resolve_votes (self , info , ** kwargs ):
108
108
return Vote .objects .all ()
0 commit comments