Skip to content

Commit

Permalink
Relate Links and Votes
Browse files Browse the repository at this point in the history
  • Loading branch information
zsl-abyss committed Aug 6, 2021
1 parent b8d6798 commit 84879cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hackernews/hackernews/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Meta:
model = Link


class VoteType(DjangoObjectType):
class Meta:
model = Vote


class UserType(DjangoObjectType):
class Meta:
model = get_user_model()
Expand Down Expand Up @@ -92,12 +97,16 @@ class Mutation(graphene.ObjectType):

class Query(graphene.ObjectType):
links = graphene.List(LinkType)
votes = graphene.List(VoteType)
users = graphene.List(UserType)
whoami = graphene.Field(UserType)

def resolve_links(self, info, **kwargs):
return Link.objects.all()

def resolve_votes(self, info, **kwargs):
return Vote.objects.all()

def resolve_users(self, info):
return get_user_model().objects.all()

Expand Down
2 changes: 2 additions & 0 deletions hackernews/queries.curl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ curl -s -X POST -H "Content-Type: application/json" -H "Authorization: JWT `cat
curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query{links{id, url, description}}"}' http://localhost:8000/graphql/
curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query{users{id, email, password}}"}' http://localhost:8000/graphql/
curl -s -X POST -H "Content-Type: application/json" -H "Authorization: JWT `cat token`" -d '{"query":"query{whoami{username email}}"}' http://localhost:8000/graphql/
curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query{votes{user{username} link{url}}}"}' http://localhost:8000/graphql/
curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query{links{url votes{user{username}}}}"}' http://localhost:8000/graphql/

0 comments on commit 84879cf

Please # to comment.