summaryrefslogtreecommitdiffstats
path: root/backend/src/resolvers/Query.js
blob: a2eb749b4d2e4634df8f68f0d8c728acc6b53ab7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { getUserId, Context } = require('../utils');
const { forwardTo } = require('prisma-binding');

const Query = {
  items(parent, args, ctx, info) {
    // check auth
    return ctx.db.query.items({ ...args }, info);
  },

  itemsConnection: forwardTo('db'),

  feed(parent, args, ctx, info) {
    return ctx.db.query.posts({}, 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;