Skip to content

Instantly share code, notes, and snippets.

@AyoubEd-zz
Created November 26, 2018 18:22
Show Gist options
  • Save AyoubEd-zz/036208d327084059240053fd17cccaf8 to your computer and use it in GitHub Desktop.
Save AyoubEd-zz/036208d327084059240053fd17cccaf8 to your computer and use it in GitHub Desktop.
import { ApolloServer, gql } from 'apollo-server-lambda';
import { CommentService } from './comment.service';
const typeDefs = gql`
type Comment{
msgId: Int
userId : String
content : String
createdAt : String
deleted : Boolean
}
type Query {
get(itemId: String): [Comment]
}
type Mutation {
add(itemId: String, userId:String, content:String): [Comment]
edit(itemId: String, msgId:Int,userId:String, content:String): [Comment]
delete(itemId: String, msgId:Int, userId:String) : [Comment]
}
`;
const resolvers = {
Query: {
get: (root, args) => {
const service = new CommentService();
return service.getComments(args.itemId);
},
},
Mutation: {
add: (roots, args) => {
const service = new CommentService();
return service.addComments(args.itemId, args.userId, args.content);
},
edit: (roots, args) => {
const service = new CommentService();
return service.editComments(args.itemId, args.msgId, args.userId, args.content);
},
delete: (roots, args) => {
const service = new CommentService();
return service.deleteComments(args.itemId, args.msgId, args.userId);
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
exports.graphqlHandler = server.createHandler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment