-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_article.py
More file actions
26 lines (23 loc) · 922 Bytes
/
create_article.py
File metadata and controls
26 lines (23 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from graphene import Mutation, String, Field
from src.types import ArticleType
from src.services.article_service import ArticleService
class CreateArticle(Mutation):
class Arguments:
title = String(required=True)
sports_type = String(required=True)
published_at = String(required=True)
url = String(required=True)
slug = String(required=True)
image = String(required=False)
article = Field(lambda: ArticleType)
def mutate(self, info, title, sports_type, published_at, url, slug, image=None):
article_data = {
"title": title,
"sports_type": sports_type,
"published_at": published_at, # Already in ISO 8601 format
"url": url,
"slug": slug,
"image": image
}
new_article = ArticleService.create_article(article_data)
return CreateArticle(article=new_article)