import {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLID,
  GraphQLString,
  GraphQLList,
} from 'graphql';

import POST from 'server/models/post';

const PostType = new GraphQLObjectType({
  name: 'post',
  fields: () => ({
    _id: {
      type: GraphQLID,
    },
    title: {
      type: GraphQLString,
    },
    body: {
      type: GraphQLString,
    },
  }),
});

const PostQuery = new GraphQLObjectType({
  name: 'query',
  fields: () => ({
    posts: {
      type: new GraphQLList(PostType),
      args: {
        title: {
          name: 'title',
          type: GraphQLString,
        },
        _id: {
          name: '_id',
          type: GraphQLID,
        },
      },
      resolve: async (root, args) => {
        const posts = await POST.find(args);
        return posts;
      },
    },
  }),
});

const PostSchema = new GraphQLSchema({
  query: PostQuery,
});

export default PostSchema;

@@ -112,19 +112,19 @@
 import P
-OST
+ost
  from 's
@@ -750,11 +750,11 @@
 it P
-OST
+ost
 .fin
@@ -803,32 +803,469 @@
   %7D,%0A  %7D),%0A%7D);%0A%0A
+const PostMutation = new GraphQLObjectType(%7B%0A  name: 'mutation',%0A  fields: () =%3E (%7B%0A    add: %7B%0A      type: PostType,%0A      args: %7B%0A        title: %7B%0A          name: 'title',%0A          type: GraphQLString,%0A        %7D,%0A        body: %7B%0A          name: 'body',%0A          type: GraphQLString,%0A        %7D,%0A      %7D,%0A      resolve: async (root, args) =%3E %7B%0A        const post = new Post(args);%0A        return post.save();%0A      %7D,%0A    %7D,%0A  %7D),%0A%7D);%0A%0A
 const PostSchema
@@ -1307,16 +1307,42 @@
 tQuery,%0A
+  mutation: PostMutation,%0A
 %7D);%0A%0Aexp

add mutation to graphql example