From ee09df7dee16a7b44711159c60c54cc9365be35e Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Tue, 14 Aug 2018 15:39:34 -0400 Subject: stepped --- .../35/backend/src/resolvers/Query.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 stepped-solutions/35/backend/src/resolvers/Query.js (limited to 'stepped-solutions/35/backend/src/resolvers/Query.js') diff --git a/stepped-solutions/35/backend/src/resolvers/Query.js b/stepped-solutions/35/backend/src/resolvers/Query.js new file mode 100755 index 0000000..8af7b6c --- /dev/null +++ b/stepped-solutions/35/backend/src/resolvers/Query.js @@ -0,0 +1,34 @@ +const { forwardTo } = require('prisma-binding'); +const { hasPermission } = require('../utils'); + +const Query = { + items: forwardTo('db'), + item: forwardTo('db'), + itemsConnection: forwardTo('db'), + me(parent, args, ctx, info) { + // check if there is a current user ID + if (!ctx.request.userId) { + return null; + } + return ctx.db.query.user( + { + where: { id: ctx.request.userId }, + }, + info + ); + }, + async users(parent, args, ctx, info) { + // 1. Check if they are logged in + if (!ctx.request.userId) { + throw new Error('You must be logged in!'); + } + console.log(ctx.request.userId); + // 2. Check if the user has the permissions to query all the users + hasPermission(ctx.request.user, ['ADMIN', 'PERMISSIONUPDATE']); + + // 2. if they do, query all the users! + return ctx.db.query.users({}, info); + }, +}; + +module.exports = Query; -- cgit v1.3