Skip to content
Snippets Groups Projects
Commit 9ff779b1 authored by Jure's avatar Jure
Browse files

feat(graphql): add where option to connector calls where needed

parent 7fc1c5cf
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ const resolvers = { ...@@ -3,8 +3,8 @@ const resolvers = {
collection(_, { id }, ctx) { collection(_, { id }, ctx) {
return ctx.connectors.Collection.fetchOne(id, ctx) return ctx.connectors.Collection.fetchOne(id, ctx)
}, },
collections(_, { id }, ctx) { collections(_, { where }, ctx) {
return ctx.connectors.Collection.fetchAll(ctx) return ctx.connectors.Collection.fetchAll(where, ctx)
}, },
}, },
Mutation: { Mutation: {
......
...@@ -3,8 +3,8 @@ const resolvers = { ...@@ -3,8 +3,8 @@ const resolvers = {
fragment(_, { id }, ctx) { fragment(_, { id }, ctx) {
return ctx.connectors.Fragment.fetchOne(id, ctx) return ctx.connectors.Fragment.fetchOne(id, ctx)
}, },
fragments(_, { id }, ctx) { fragments(_, { where }, ctx) {
return ctx.connectors.Fragment.fetchAll(ctx) return ctx.connectors.Fragment.fetchAll(where, ctx)
}, },
}, },
Mutation: { Mutation: {
......
...@@ -6,8 +6,8 @@ const resolvers = { ...@@ -6,8 +6,8 @@ const resolvers = {
user(_, { id }, ctx) { user(_, { id }, ctx) {
return ctx.connectors.User.fetchOne(id, ctx) return ctx.connectors.User.fetchOne(id, ctx)
}, },
users(_, vars, ctx) { users(_, { where }, ctx) {
return ctx.connectors.User.fetchAll(ctx) return ctx.connectors.User.fetchAll(where, ctx, { eager: 'teams' })
}, },
// Authentication // Authentication
currentUser(_, vars, ctx) { currentUser(_, vars, ctx) {
...@@ -16,7 +16,14 @@ const resolvers = { ...@@ -16,7 +16,14 @@ const resolvers = {
}, },
}, },
Mutation: { 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) return ctx.connectors.User.create(input, ctx)
}, },
deleteUser(_, { id }, ctx) { deleteUser(_, { id }, ctx) {
...@@ -46,11 +53,6 @@ const resolvers = { ...@@ -46,11 +53,6 @@ const resolvers = {
} }
}, },
}, },
User: {
teams(user, vars, ctx) {
return ctx.connectors.Team.fetchSome(user.teams, ctx)
},
},
} }
const typeDefs = ` const typeDefs = `
...@@ -68,8 +70,8 @@ const typeDefs = ` ...@@ -68,8 +70,8 @@ const typeDefs = `
type User { type User {
id: ID! id: ID!
type: String type: String
username: String! username: String
email: String! email: String
admin: Boolean admin: Boolean
teams: [Team!]! teams: [Team!]!
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment