Created
November 26, 2018 18:22
-
-
Save AyoubEd-zz/036208d327084059240053fd17cccaf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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