From cd0b07b3adb36fb5ec098f9e511ab45d774fee7b Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Tue, 30 Jan 2018 12:41:01 -0500 Subject: Move to Prisma Backend --- backend/src/resolvers/Query.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backend/src/resolvers/Query.js (limited to 'backend/src/resolvers/Query.js') 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; -- cgit v1.3