Skip to content

Commit 1de772e

Browse files
committed
Mutations
1 parent 4627900 commit 1de772e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

hackernews/hackernews/schema.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
class Query(links.schema.Query, graphene.ObjectType):
77
pass
88

9+
class Mutation(links.schema.Mutation, graphene.ObjectType):
10+
pass
911

10-
schema = graphene.Schema(query=Query)
12+
schema = graphene.Schema(query=Query, mutation=Mutation)

hackernews/links/schema.py

+28
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,31 @@ class Query(graphene.ObjectType):
1414

1515
def resolve_links(self, info, **kwargs):
1616
return Link.objects.all()
17+
18+
19+
#1
20+
class CreateLink(graphene.Mutation):
21+
id = graphene.Int()
22+
url = graphene.String()
23+
description = graphene.String()
24+
25+
#2
26+
class Arguments:
27+
url = graphene.String()
28+
description = graphene.String()
29+
30+
#3
31+
def mutate(self, info, url, description):
32+
link = Link(url=url, description=description)
33+
link.save()
34+
35+
return CreateLink(
36+
id=link.id,
37+
url=link.url,
38+
description=link.description,
39+
)
40+
41+
42+
#4
43+
class Mutation(graphene.ObjectType):
44+
create_link = CreateLink.Field()

0 commit comments

Comments
 (0)