const query = ` posts(limit: Int, offset: Int, sort: String): [Post] post(id: Int, code: String): Post `; const typeDefinitions = ` type Post { id: Int! code: String! title: String content: String author: User! views: Int voters(limit: Int, offset: Int, sort: String): [User] upVoters(limit: Int, offset: Int, sort: String): [User] downVoters(limit: Int, offset: Int, sort: String): [User] votes: Int, createdAt: Timestamp updatedAt: Timestamp } `; const mutation = ` upVote(postID: Int!): Post downVote(postID: Int!): Post `; const resolvers = { Query: { posts(root, args, context) { return applyLimitOffsetSort(Post.find({}), args).exec(); }, ... }, Mutation: { upVote(root, args, context) { ... }, downVote(root, args, context) { ... } } }; module.exports = { schema: { query, typeDefinitions, mutation }, resolvers };