{"id":292789,"date":"2019-07-30T21:00:20","date_gmt":"2019-07-30T21:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=292789"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=292789","title":{"rendered":"\u0413\u043e\u0434 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441 graphene-python"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<h1 id=\"god-priklyucheniy-s-graphene-python\">\u0413\u043e\u0434 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441 graphene-python<\/h1>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/700\/1*tcauWKwK_D32_tNRbLXOpg.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u044f python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 graphene-python + django ORM \u0438 \u0437\u0430 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u044f \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 graphene \u0443\u0434\u043e\u0431\u043d\u0435\u0435. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 <code>graphene-framework<\/code> \u0438 \u043d\u0430\u0431\u043e\u0440 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b, \u0447\u0435\u043c \u044f \u0431\u044b \u0438 \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/700\/1*f9Z_MDM8YhecDjzQJGxRAg.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 graphene-python?<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0435\u0440\u0438\u0442\u044c <a href=\"https:\/\/graphene-python.org\/\">graphene-python.org<\/a>, \u0442\u043e:<\/p>\n<p>  <\/p>\n<blockquote><p>Graphene-Python \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f GraphQL APIs \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Python. \u0415\u0435 \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435, \u043d\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0435 API, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043f\u0440\u043e\u0449\u0435.<\/p><\/blockquote>\n<p><strong>\u0415\u0435 \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435, \u043d\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0435 API, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043f\u0440\u043e\u0449\u0435.<\/strong><\/p>\n<p>  <\/p>\n<p>\u0414\u0430, \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 graphene \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u044b\u0439, \u043d\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u0431\u044b\u0441\u0442\u0440\u043e\u0440\u0430\u0441\u0442\u0443\u0449\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f (\u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043a\u043e\u0434 \u2014 \u043e\u043d \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u0435\u043d), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e API.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0431\u044b \u0442\u043e \u043d\u0438 \u0431\u044b\u043b\u043e, \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u0440\u044f\u0434\u043e\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0440\u0435\u0448\u0438\u0432 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0431\u043e\u0433\u0430\u0442\u044b\u043c \u043d\u0435\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c graphene). \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043c\u043e\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0447\u0438\u0441\u0442\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b &quot;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&quot;, \u0431\u0435\u0437 \u043c\u043e\u0435\u0433\u043e &quot;\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430&quot;. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u0445 \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435 \u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u2014 \u043d\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u0430 \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0441\u043c\u044b\u0441\u043b\u0435 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e \u043f\u0443\u0442\u0438, \u0447\u0442\u043e \u044f \u043f\u0440\u043e\u0448\u0435\u043b \u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0447\u0442\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0441 \u043a\u0440\u0430\u0442\u043a\u0438\u043c \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u043e\u0435\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0443\u0434\u0435\u043b\u0438\u043b \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u044f\u043c \u0438 \u0432\u0435\u0449\u0430\u043c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c \u0441 \u043d\u0438\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0426\u0435\u043b\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <strong>\u043b\u044e\u0431\u0443\u044e \u0437\u043d\u0430\u0447\u0438\u043c\u0443\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c<\/strong>, \u0442\u0430\u043a \u0447\u0442\u043e \u0431\u0443\u0434\u0443 \u0436\u0434\u0430\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u043a\u0443 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<\/p>\n<p>  <\/p>\n<p><em>\u0417\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 GraphQL.<\/em> <\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h2 id=\"mutacii\">\u041c\u0443\u0442\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<blockquote><p>\u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0439 \u043e GraphQL \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0434\u043d\u0430\u043a\u043e \u043b\u044e\u0431\u0430\u044f \u0443\u0432\u0430\u0436\u0430\u044e\u0449\u0430\u044f \u0441\u0435\u0431\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p><\/blockquote>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043c\u0443\u0442\u0430\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(graphene.Mutation):     class Arguments:         post_id = graphene.ID(required=True)         title = graphene.String(required=True)         content = graphene.String(required=True)         image_urls = graphene.List(graphene.String, required=False)         allow_comments = graphene.Boolean(required=True)         contact_email = graphene.String(required=True)      ok = graphene.Boolean(required=True)     errors = graphene.List(graphene.String, required=True)      def mutate(_, info, post_id, title, content, image_urls, allow_comments, contact_email):         errors = []         try:             post = get_post_by_id(post_id)         except PostNotFound:             return UpdatePostMutation(ok=False, errors=['post_not_found'])          if not info.context.user.is_authenticated:             errors.append('not_authenticated')          if len(title) &lt; TITLE_MIN_LENGTH:             errors.append('title_too_short')          if not is_email(contact_email):             errors.append('contact_email_not_valid')          if post.owner != info.context.user:             errors.append('not_post_owner')          if Post.objects.filter(title=title).exists():             errors.append('title_already_taken')          if not errors:             post = Utils.update_post(post, title, content, image_urls, allow_comments, contact_email)         return UpdatePostMutation(ok=bool(errors), errors=errors)<\/code><\/pre>\n<p>  <\/p>\n<p><code>UpdatePostMutation<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u043e\u0441\u0442 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c <code>id<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0435 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u044b. <\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043b\u0438\u0448\u044c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u043a\u0430\u043a \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0438\u0434\u043d\u0430 \u0435\u0433\u043e \u043d\u0435\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438\u0437-\u0437\u0430:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>mutate<\/code>, \u0447\u0438\u0441\u043b\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0435\u0449\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043f\u043e\u043b\u044f, \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/li>\n<li>\u0427\u0442\u043e\u0431\u044b \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>errors<\/code> \u0438 <code>ok<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0445 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0447\u0435\u043c \u043e\u043d \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d.<\/li>\n<li>\u041f\u043e\u0438\u0441\u043a \u0438 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 <em>\u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/em> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>mutate<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u043c, \u0430 \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442, \u0442\u043e \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c.<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0432 \u043c\u0443\u0442\u0430\u0446\u0438\u0438. \u041c\u0443\u0442\u0430\u0446\u0438\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432 \u043d\u0430 \u044d\u0442\u043e (\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442).<\/li>\n<li>\u0411\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 (<em>\u043a\u043e\u0440\u0435\u043d\u044c<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 <code>None<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0447\u0435\u043c \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0448\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f).<\/li>\n<li>\u041d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0448\u0438\u0431\u043e\u043a: \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438\u043b\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0442\u043e \u0432\u044b \u043d\u0435 \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u0442\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043d\u0435 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u044b \u0432 \u0441\u0445\u0435\u043c\u0435.<\/li>\n<li>\u0421\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>mutate<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 <em>\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435<\/em> \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043d\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438. \u0418\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 <code>mutate<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0412\u043a\u0440\u0430\u0442\u0446\u0435, <strong><code>mutate<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435<\/strong>, \u0430 \u043d\u0435 \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0442\u0430\u043a\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u043f\u0440\u0438\u0439\u0442\u0438 \u043a \u0447\u0435\u043c\u0443-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    def mutate(post, info, input):         post = Utils.update_post(post, **input)         return UpdatePostMutation(post=post)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0443\u043d\u043a\u0442\u044b \u0432\u044b\u0448\u0435.<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"polzovatelskie-tipy\">\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0442\u0438\u043f\u044b<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0435 <code>email<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0430, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u044d\u0442\u043e <em>\u0441\u0442\u0440\u043e\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430<\/em>. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 API \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 email, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c. \u0422\u0430\u043a \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0442\u0438\u043f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class Email(graphene.String):     # ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u0442\u043e\u0438\u043b\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"vhodnye-tipy\">\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u0438\u043f\u044b<\/h3>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043c\u0443\u0442\u0430\u0446\u0438\u0439. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u043f\u043e\u0434\u043b\u0435\u0436\u0430\u0442 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0445 \u043f\u0440\u043e\u0449\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostInput(graphene.InputObjectType):     title = graphene.String(required=True)     content = graphene.String(required=True)     image_urls = graphene.List(graphene.String, required=False)     allow_comments = graphene.Boolean(required=True)     contact_email = graphene.String(required=True)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">mutation(     $post_id: ID!,     $title: String!,     $content: String!,     $image_urls: String!,     $allow_comments: Boolean!,     $contact_email: Email! ) {     updatePost(         post_id: $post_id,         title: $title,         content: $content,         image_urls: $image_urls,         allow_comments: $allow_comments,         contact_email: $contact_email,     ) {         ok     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">mutation($id: ID!, $input: UpdatePostInput!) {     updatePost(id: $id, input: $input) {         ok     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(graphene.Mutation):     class Arguments:         input = UpdatePostInput(required=True)         id = graphene.ID(required=True)      ok = graphene.Boolean(required=True)     errors = graphene.List(graphene.String, required=True)      def mutate(_, info, input, id):         # ...         if not errors:             post = Utils.update_post(post, **input.__dict__)         return UpdatePostMutation(errors=errors)<\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"bazovyy-klass-mutaciy\">\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043c\u0443\u0442\u0430\u0446\u0438\u0439<\/h3>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e \u0432 \u043f\u0443\u043d\u043a\u0442\u0435 \u21167, <em>\u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>errors<\/code> \u0438 <code>ok<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0445 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0447\u0435\u043c \u043e\u043d \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d<\/em>. \u042d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class MutationPayload(graphene.ObjectType):     ok = graphene.Boolean(required=True)     errors = graphene.List(graphene.String, required=True)     query = graphene.Field('main.schema.Query', required=True)      def resolve_ok(self, info):         return len(self.errors or []) == 0      def resolve_errors(self, info):         return self.errors or []      def resolve_query(self, info):         return {}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 <code>resolve_ok<\/code>, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c <code>ok<\/code> \u0441\u0430\u043c\u0438\u043c.<\/li>\n<li>\u041f\u043e\u043b\u0435 <code>query<\/code> \u2014 \u044d\u0442\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 <code>Query<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u044f\u043c\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 (\u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u0438).<br \/> \n<pre><code class=\"plaintext\">mutation($id: ID!, $input: PostUpdateInput!) { updatePost(id: $id, input: $input) {     ok     query {         profile {             totalPosts         }     } } }<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0431\u0435\u043a\u0435\u043d\u0434\u0435\u0440\u0430 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0435\u0441\u044c \u044d\u0442\u043e\u0442 \u043d\u0430\u0431\u043e\u0440. \u0427\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u0434\u0430 \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435, \u0442\u0435\u043c \u043f\u0440\u043e\u0449\u0435 \u0435\u0433\u043e \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c. \u042d\u0442\u0443 \u0438\u0434\u0435\u044e \u044f \u0432\u0437\u044f\u043b <a href=\"https:\/\/github.com\/nodkz\/conf-talks\/tree\/master\/articles\/graphql\/schema-design#rule-6.6.3\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043a\u043e\u0434 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(MutationPayload, graphene.Mutation):     class Arguments:         input = UpdatePostInput(required=True)         id = graphene.ID(required=True)      def mutate(_, info, input, id):         # ...<\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"kornevye-mutacii\">\u041a\u043e\u0440\u043d\u0435\u0432\u044b\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0438<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">mutation($id: ID!, $input: PostUpdateInput!) {     updatePost(id: $id, input: $input) {         ok     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0435 \u043b\u0443\u0447\u0448\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430. \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d \u043f\u043e\u0447\u0435\u043c\u0443:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0421 \u0440\u043e\u0441\u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u0439, \u0432\u0441\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0442\u0443 \u043c\u0443\u0442\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430.<\/li>\n<li>\u0418\u0437-\u0437\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 &quot;\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u044f&quot;, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>update<\/code><strong><code>Post<\/code><\/strong>.<\/li>\n<li>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c <code>id<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u0438.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>\u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0438<\/em>. \u0418\u0445 \u0446\u0435\u043b\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u0439 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043e\u0442 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0443 \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0438 \u043f\u0440\u0430\u0432\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">mutation($id: ID!, $input: PostUpdateInput!) {     post(id: $id) {         update(input: $input) {             ok         }     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f &quot;\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f&quot; \u0432\u043d\u0443\u0442\u0440\u0438 <code>post<\/code>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0415\u0441\u043b\u0438 <code>id<\/code> \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 <code>post<\/code>, \u0442\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>{}<\/code>. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0443\u0442\u0430\u0446\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432).<\/li>\n<li>\u0415\u0441\u043b\u0438 <code>id<\/code> \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>None<\/code> \u0438 \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430\u0439\u0434\u0435\u043d, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u043d\u0430\u0434 \u043d\u0438\u043c.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u043f\u0440\u0430\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>None<\/code> \u0438 \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f, \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0430\u0432\u0430 \u0435\u0441\u0442\u044c, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u0440\u043d\u044f \u2014 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u0434 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(MutationPayload, graphene.Mutation):     class Arguments:         input = UpdatePostInput()      def mutate(post, info, input):         if post is None:             return None          errors = []          if not info.context.user.is_authenticated:             errors.append('not_authenticated')          if len(title) &lt; TITLE_MIN_LENGTH:             errors.append('title_too_short')          if Post.objects.filter(title=title).exists():             errors.append('title_already_taken')          if not errors:             post = Utils.update_post(post, **input.__dict__)         return UpdatePostMutation(errors=errors)<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041a\u043e\u0440\u0435\u043d\u044c \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2014 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Post<\/code>, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0443\u0442\u0430\u0446\u0438\u044f.<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u0430 \u0432 \u043a\u043e\u0434 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0443\u0442\u0430\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0443\u0442\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class PostMutationRoot(MutationRoot):     class Meta:         model = Post         has_permission = lambda post, user: post.owner == user      update = UpdatePostMutation.Field()<\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"interfeys-oshibok\">\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c, \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u044b \u0432 \u0441\u0445\u0435\u043c\u0435.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0431\u044b\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u043e\u043c<\/li>\n<li>\u0422\u0430\u043a \u043a\u0430\u043a \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <code>Union<\/code> \u043e\u0448\u0438\u0431\u043e\u043a.<\/li>\n<li>\u0427\u0442\u043e\u0431\u044b \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430, \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e <code>ErrorInterface<\/code>. \u041f\u0443\u0441\u0442\u044c \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u043f\u043e\u043b\u044f: <code>ok<\/code> \u0438 <code>message<\/code>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0442\u0438\u043f <code>[SomeMutationErrorsUnion]!<\/code>. \u0412\u0441\u0435 \u043f\u043e\u0434\u0442\u0438\u043f\u044b <code>SomeMutationErrorsUnion<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c <code>ErrorInterface<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class NotAuthenticated(graphene.ObjectType):     message = graphene.String(required=True, default_value='not_authenticated')     class Meta:         interfaces = [ErrorInterface, ]  class TitleTooShort(graphene.ObjectType):     message = graphene.String(required=True, default_value='title_too_short')     class Meta:         interfaces = [ErrorInterface, ]  class TitleAlreadyTaken(graphene.ObjectType):     message = graphene.String(required=True, default_value='title_already_taken')     class Meta:         interfaces = [ErrorInterface, ]  class UpdatePostMutationErrors(graphene.Union):     class Meta:         types = [NotAuthenticated, TitleIsTooShort, TitleAlreadyTaken, ]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u043d\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u0430\u043a\u043b\u0430\u0441\u0441, \u0447\u0442\u043e\u0431\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u043b\u0435\u0442\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class PostErrors(metaclass=ErrorMetaclass):     errors = [         'not_authenticated',         'title_too_short',         'title_already_taken',     ]  class UpdatePostMutationErrors(graphene.Union):     class Meta:         types = [PostErrors.not_authenticated, PostErrors.title_too_short, PostErrors.title_already_taken, ]<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043c\u0443\u0442\u0430\u0446\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(MutationPayload, graphene.Mutation):     class Arguments:         input = UpdatePostInput()      errors = graphene.List(UpdatePostMutationErrors, required=True)      def mutate(post, info, input):         # ...<\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"proverka-na-nalichie-oshibok\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p>  <\/p>\n<p>\u041c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 <code>mutate<\/code> \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0447\u0435\u043c-\u043b\u0438\u0431\u043e, \u043a\u0440\u043e\u043c\u0435 <em>\u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/em>. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0438\u0447\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u0445 \u043a\u043e\u0434\u0430 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0443\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0432\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(DefaultMutation):     class Arguments:         input = UpdatePostInput()      class Meta:         root_required = True         authentication_required = True # \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0443\u0449\u0435\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0432\u043d\u043e True \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e         # An iterable of tuples (error_class, checker)         checks = [             (                 PostErrors.title_too_short,                 lambda post, input: len(input.title) &lt; TITLE_MIN_LENGTH             ),             (                 PostErrors.title_already_taken,                 lambda post, input: Post.objects.filter(title=input.title).exists()             ),         ]      def mutate(post, info, input):         post = Utils.update_post(post, **input.__dict__)         return UpdatePostMutation()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>mutate<\/code>, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 <em>checker<\/em> (\u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0447\u043b\u0435\u043d\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>checks<\/code>). \u0415\u0441\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043e <code>True<\/code> \u2014 \u043d\u0430\u0439\u0434\u0435\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430. \u0415\u0441\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>mutate<\/code>. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u044f\u0441\u043d\u044e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0424\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0442\u0435 \u0436\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u0447\u0442\u043e \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>mutate<\/code>.<\/li>\n<li>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c <code>True<\/code>, \u0435\u0441\u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430.<\/li>\n<li>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u0449\u0438\u0435 \u0438 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u0444\u043b\u0430\u0433\u0438 <code>Meta<\/code>.<\/li>\n<li><code>authentication_required<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0435\u0441\u043b\u0438 \u0440\u0430\u0432\u043d\u043e <code>True<\/code>.<\/li>\n<li><code>root_required<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 &quot;<code>root is not None<\/code>&quot; \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443.<\/li>\n<li><code>UpdatePostMutationErrors<\/code> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. \u042e\u043d\u0438\u043e\u043d \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043b\u0435\u0442\u0443 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>checks<\/code>.<\/li>\n<\/ul>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"dzheneriki\">\u0414\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438<\/h3>\n<p>  <\/p>\n<p><code>DefaultMutation<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 <code>pre_mutate<\/code> \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a, \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0443\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u0434 \u043a\u043e\u0440\u043e\u0447\u0435, \u0430 \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0449\u0435.<br \/>  <em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u0434 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u043d \u0434\u043b\u044f django ORM<\/em><\/p>\n<p>  <\/p>\n<h4 id=\"createmutation\">CreateMutation<\/h4>\n<p>  <\/p>\n<p>\u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <code>model<\/code> \u0438\u043b\u0438 <code>create_function<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>create_function<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">model._default_manager.create(**data, owner=user)<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u0438\u043f\u043e\u0432 \u0432 graphql, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 \u043c\u0443\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <code>post_mutate<\/code> \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 <code>create_function<\/code> \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 <code>(instance_created, user)<\/code>, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d \u043a\u043b\u0438\u0435\u043d\u0442\u0443. <\/p>\n<p>  <\/p>\n<h4 id=\"updatemutation\">UpdateMutation<\/h4>\n<p>  <\/p>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c <code>update_function<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def default_update_function(instance, user=None, **data):     instance.__dict__.update(data)     instance.save()     return instance<\/code><\/pre>\n<p>  <\/p>\n<p><code>root_required<\/code> \u0440\u0430\u0432\u0435\u043d <code>True<\/code> \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 <code>post_mutate<\/code> \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 <code>update_function<\/code> \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 <code>(instance_updated, user)<\/code>, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d \u043a\u043b\u0438\u0435\u043d\u0442\u0443. <\/p>\n<p>  <\/p>\n<p>\u0418 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e!<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class UpdatePostMutation(UpdateMutation):     class Arguments:         input = UpdatePostInput()      class Meta:         checks = [             (                 PostErrors.title_too_short,                 lambda post, input: len(input.title) &lt; TITLE_MIN_LENGTH             ),             (                 PostErrors.title_already_taken,                 lambda post, input: Post.objects.filter(title=input.title).exists()             ),         ]<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"deletemutation\">DeleteMutation<\/h4>\n<p>  <\/p>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0442\u044c <code>delete_function<\/code>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e: <\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def default_delete_function(instance, user=None, **data):     instance.delete()<\/code><\/pre>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<h3 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0430\u0441\u043f\u0435\u043a\u0442, \u0445\u043e\u0442\u044c \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043e\u043d \u0438 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439. \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b\u0441\u043b\u0438 \u043e \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440\u0430\u0445 \u0438 \u0442\u0438\u043f\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0449\u0438\u0445 \u0432\u0435\u0449\u0430\u0445 \u0432 graphene-python.<\/p>\n<p>  <\/p>\n<p>\u041c\u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u043f\u044b\u0442\u043d\u044b\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0443 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0434 \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/Donnyyyyy\/graphene-framework\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/461939\/\"> https:\/\/habr.com\/ru\/post\/461939\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<h1 id=\"god-priklyucheniy-s-graphene-python\">\u0413\u043e\u0434 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0441 graphene-python<\/h1>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/700\/1*tcauWKwK_D32_tNRbLXOpg.png\" alt=\"image\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u044f python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u043e\u0434 \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 graphene-python + django ORM \u0438 \u0437\u0430 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u044f \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 graphene \u0443\u0434\u043e\u0431\u043d\u0435\u0435. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 <code>graphene-framework<\/code> \u0438 \u043d\u0430\u0431\u043e\u0440 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b, \u0447\u0435\u043c \u044f \u0431\u044b \u0438 \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-292789","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292789"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292789\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}