From 9ff779b111661b6044aa1ab0a9ac447440df265e Mon Sep 17 00:00:00 2001 From: Jure Triglav <juretriglav@gmail.com> Date: Sat, 26 Jan 2019 01:10:55 +1300 Subject: [PATCH] feat(graphql): add where option to connector calls where needed --- .../model-collection/src/graphql.js | 4 ++-- .../components/model-fragment/src/graphql.js | 4 ++-- packages/components/model-user/src/graphql.js | 22 ++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/components/model-collection/src/graphql.js b/packages/components/model-collection/src/graphql.js index 5c76ff92b..ad8c63137 100644 --- a/packages/components/model-collection/src/graphql.js +++ b/packages/components/model-collection/src/graphql.js @@ -3,8 +3,8 @@ const resolvers = { collection(_, { id }, ctx) { return ctx.connectors.Collection.fetchOne(id, ctx) }, - collections(_, { id }, ctx) { - return ctx.connectors.Collection.fetchAll(ctx) + collections(_, { where }, ctx) { + return ctx.connectors.Collection.fetchAll(where, ctx) }, }, Mutation: { diff --git a/packages/components/model-fragment/src/graphql.js b/packages/components/model-fragment/src/graphql.js index 324f19e3f..24dadc455 100644 --- a/packages/components/model-fragment/src/graphql.js +++ b/packages/components/model-fragment/src/graphql.js @@ -3,8 +3,8 @@ const resolvers = { fragment(_, { id }, ctx) { return ctx.connectors.Fragment.fetchOne(id, ctx) }, - fragments(_, { id }, ctx) { - return ctx.connectors.Fragment.fetchAll(ctx) + fragments(_, { where }, ctx) { + return ctx.connectors.Fragment.fetchAll(where, ctx) }, }, Mutation: { diff --git a/packages/components/model-user/src/graphql.js b/packages/components/model-user/src/graphql.js index d4be96a95..1d26c3191 100644 --- a/packages/components/model-user/src/graphql.js +++ b/packages/components/model-user/src/graphql.js @@ -6,8 +6,8 @@ const resolvers = { user(_, { id }, ctx) { return ctx.connectors.User.fetchOne(id, ctx) }, - users(_, vars, ctx) { - return ctx.connectors.User.fetchAll(ctx) + users(_, { where }, ctx) { + return ctx.connectors.User.fetchAll(where, ctx, { eager: 'teams' }) }, // Authentication currentUser(_, vars, ctx) { @@ -16,7 +16,14 @@ const resolvers = { }, }, Mutation: { - createUser(_, { input }, ctx) { + async createUser(_, { input }, ctx) { + if (input.password) { + input.passwordHash = await ctx.connectors.User.model.hashPassword( + input.password, + ) + delete input.password + } + return ctx.connectors.User.create(input, ctx) }, deleteUser(_, { id }, ctx) { @@ -46,11 +53,6 @@ const resolvers = { } }, }, - User: { - teams(user, vars, ctx) { - return ctx.connectors.Team.fetchSome(user.teams, ctx) - }, - }, } const typeDefs = ` @@ -68,8 +70,8 @@ const typeDefs = ` type User { id: ID! type: String - username: String! - email: String! + username: String + email: String admin: Boolean teams: [Team!]! } -- GitLab