aerogear/create-graphql

Support raw GraphQL Mutation

Open

#21 aberto em 14 de dez. de 2016

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (51 forks)batch import
help wantednew feature

Métricas do repositório

Stars
 (440 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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

Guia do colaborador