diff options
Diffstat (limited to 'backend/src/resolvers/Query.js')
| -rw-r--r-- | backend/src/resolvers/Query.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/backend/src/resolvers/Query.js b/backend/src/resolvers/Query.js new file mode 100644 index 0000000..9d9d142 --- /dev/null +++ b/backend/src/resolvers/Query.js @@ -0,0 +1,31 @@ +const { getUserId, Context } = require('../utils'); + +const Query = { + feed(parent, args, ctx, info) { + return ctx.db.query.posts({ where: { isPublished: true } }, info); + }, + + drafts(parent, args, ctx, info) { + const id = getUserId(ctx); + + const where = { + isPublished: false, + author: { + id, + }, + }; + + return ctx.db.query.posts({ where }, info); + }, + + post(parent, { id }, ctx, info) { + return ctx.db.query.post({ where: { id } }, info); + }, + + me(parent, args, ctx, info) { + const id = getUserId(ctx); + return ctx.db.query.user({ where: { id } }, info); + }, +}; + +module.exports = Query; |
