<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayemitibo Abiodun</title>
    <description>The latest articles on DEV Community by Ayemitibo Abiodun (@ayemitibo).</description>
    <link>https://dev.to/ayemitibo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F486673%2Ffb9fe582-fdd3-4a18-bd87-bf86cd4e151d.jpeg</url>
      <title>DEV Community: Ayemitibo Abiodun</title>
      <link>https://dev.to/ayemitibo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayemitibo"/>
    <language>en</language>
    <item>
      <title>Writing Mutations with Apollo Client</title>
      <dc:creator>Ayemitibo Abiodun</dc:creator>
      <pubDate>Fri, 30 Oct 2020 20:29:29 +0000</pubDate>
      <link>https://dev.to/ayemitibo/writing-mutations-with-apollo-client-heb</link>
      <guid>https://dev.to/ayemitibo/writing-mutations-with-apollo-client-heb</guid>
      <description>&lt;h1&gt;
  
  
  What is Apollo Client?
&lt;/h1&gt;

&lt;p&gt;Apollo Client is a comprehensive state management library for JavaScript that enables you to manage both local and remote data with GraphQL. Use it to fetch, cache, and modify application data, all while automatically updating your UI. Mostly, while working with apollo I don't think you need any other state management library like(vuex or redux)&lt;/p&gt;

&lt;h1&gt;
  
  
  what are mutations and queries?
&lt;/h1&gt;

&lt;p&gt;we all know while working with REST APIs we have the basic request we make which are 'GET, POST, PUT, PATCH ...etc', but when making requests to a graphql endpoint we have two major requests which are QUERIES AND MUTATIONS. A QUERY is any request that reads from the server i.e getting all post from an API endpoint will require us to use a query and MUTATION on the other end is any request that writes to the server i.e saving a post to an API endpoint will require you to write a mutation.&lt;/p&gt;

&lt;h1&gt;
  
  
  How To Write A Simple Mutation
&lt;/h1&gt;

&lt;p&gt;let's assume we have an API Endpoint to create a blog post(mutation)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--djOl9w4z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dhootdh4f/image/upload/v1602784226/Screenshot_2020-10-15_at_18.46.13_ns62nm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--djOl9w4z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dhootdh4f/image/upload/v1602784226/Screenshot_2020-10-15_at_18.46.13_ns62nm.png" alt="Create Blog Post"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;as you can see from the image above we have the createPost mutation takes an 'input' object that contains 'data' and the data property takes post_title, post_date, post_detail, etc. You will notice each property on the data object has a type of property that can be String, String!, ID, Date, Upload, and Enum types also which won't cover in the article.&lt;/p&gt;

&lt;p&gt;Our Mutation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mutation createPost(
    $post_title: String
    $post_date: Date
    $post_detail: String
    $post_image: ID
  ) {
    createPost(
      input: {
        data: {
          post_title: $post_title
          post_detail: $post_detail
          post_date: $post_date
          post_image: $post_image
        }
      }
    ) {
      post {
        id
      }
    }
  }`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to Write multiple Mutations
&lt;/h1&gt;

&lt;p&gt;mutations fields run in series i.e the first mutation must finish before the second starts. Let's assume we have a button that does two things it creates a post and also creates a post collection.&lt;br&gt;
This is the playground&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bdeB5t3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dhootdh4f/image/upload/v1602785188/Screenshot_2020-10-15_at_19.06.09_g6zskq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bdeB5t3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dhootdh4f/image/upload/v1602785188/Screenshot_2020-10-15_at_19.06.09_g6zskq.png" alt="Create Blog Post"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mutation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const CREATE_POST = gql`
  mutation createPost(
    $post_title: String
    $post_date: Date
    $post_detail: String
    $post_image: ID
    $name: String
  ) {
    createPost(
      input: {
        data: {
          post_title: $post_title
          post_detail: $post_detail
          post_date: $post_date
          post_image: $post_image
        }
      }
    ) {
      post {
        id
      }
    }
    createCollection(input: { data: { name: $name } }) {
      collection {
        name
      }
    }
  }
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can pull this &lt;a href="https://github.com/ayemitibo/vue-apollo-blog.git"&gt;Vue&lt;/a&gt; repo to check the full source code&lt;/p&gt;

</description>
      <category>apollo</category>
    </item>
  </channel>
</rss>
