diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-01-30 12:41:01 -0500 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-01-30 12:41:01 -0500 |
| commit | cd0b07b3adb36fb5ec098f9e511ab45d774fee7b (patch) | |
| tree | a203e5010219ccea1acc6bbd2c0a4bcfa0a78615 /backend/src/resolvers/Query.js | |
| parent | 0a1648bf47490b312169c531aeb51ef4725e8d2e (diff) | |
Move to Prisma Backend
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; |
