aerogear/create-graphql

Support raw GraphQL Mutation

開放

#21 建立於 2016年12月14日

 (1 則留言) (0 個反應) (0 位負責人)JavaScript (51 個分叉)batch import
help wantednew feature

倉庫指標

星標
 (440 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Example of raw graphql mutation based on https://learngraphql.com/basics/defining-mutations/2

const Mutation = new GraphQLObjectType({
  name: "BlogMutations",
  description: "Mutations of our blog",
  fields: () => ({
    createPost: {
      type: Post,
      args: {
        title: {type: new GraphQLNonNull(GraphQLString)},
        content: {type: new GraphQLNonNull(GraphQLString)}
      },
      resolve: function(source, args) {
        let post = Object.assign({}, args);
        // Generate the _id
        post._id = `${Date.now()}::${Math.ceil(Math.random() * 9999999)}`;
        // Assign a user
        post.author = "arunoda";

        // Add the Post to the data store
        PostsList.push(post);

        // return the new post.
        return post;
      }
    }
  })
});

I think this could work on apollo as well

貢獻者指南