Guest User

Untitled

a guest
Feb 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. const resolvers = {
  2. Query: {
  3. async feed(parent, { authorId }, ctx, info) {
  4. // build filter
  5. const authorFilter = authorId ? { author: { id: authorId } } : {}
  6.  
  7. // retrieve (potentially filtered) posts
  8. const posts = await ctx.db.query.posts({ where: authorFilter })
  9.  
  10. // retrieve (potentially filtered) element count
  11. const postsConnection = await ctx.db.query.postsConnection(
  12. { where: authorFilter },
  13. `{ aggregate { count } }`,
  14. )
  15. return {
  16. count: postsConnection.aggregate.count,
  17. posts: posts,
  18. }
  19. },
  20. },
  21. }
Add Comment
Please, Sign In to add comment