Skip to content

Instantly share code, notes, and snippets.

@chathuranga94
Created January 21, 2019 10:24
Show Gist options
  • Save chathuranga94/f8f2d10cfb41fcbc5509c15b57c56a0a to your computer and use it in GitHub Desktop.
Save chathuranga94/f8f2d10cfb41fcbc5509c15b57c56a0a to your computer and use it in GitHub Desktop.
const typeDefs = gql`
type Query {
Posts: [Post],
}
type Mutation {
addPost(title: String!, content: String!): [Post]
}
type Post {
title: String
content: String
}
`;
const resolvers = {
Query: {
Posts: () => posts,
},
Mutation: {
addPost: (obj, args) => {
posts.push({title: args.title, content: args.content});
return posts;
}
}
};
let posts = [
{ title: 'Harry Potter', content: 'J.K. Rowling',},
{ title: 'Jurassic Park', content: 'Michael Crichton',},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment