Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return ctx.photon.users.findMany();
}
});
t.list.field('feedDecks', {
type: 'Deck',
resolve: (_parent, _args, ctx) => {
return ctx.photon.decks.findMany();
}
});
t.list.field('deckConnection', {
type: 'Deck',
args: {
first: intArg(),
last: stringArg()
},
resolve: (_parent, args, ctx) => {
const { first, last } = args;
return ctx.photon.decks.findMany({
first: first,
after: last
});
}
});
// t.list.field('feed', {
// type: 'Post',
// resolve: (_parent, _args, ctx) => {
// return ctx.photon.posts.findMany({
// where: { published: true },
// })
} as any,
resolve: (parent, { name, email }, ctx) => {
return ctx.photon.users.create({
data: {
name,
email,
},
})
},
})
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg(),
content: stringArg({ nullable: true }),
authorEmail: stringArg(),
} as any,
resolve: (parent, { title, content, authorEmail }, ctx) => {
return ctx.photon.posts.create({
data: {
title,
content,
published: false,
// author: {
// connect: { email: authorEmail },
// },
},
})
},
})
definition(t) {
t.crud.createOneUser({ alias: 'signupUser' })
t.crud.deleteOnePost()
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg(),
content: stringArg({ nullable: true }),
authorEmail: stringArg(),
},
resolve: (_, { title, content, authorEmail }, ctx) => {
return ctx.photon.posts.create({
data: {
title,
content,
published: false,
author: {
connect: { email: authorEmail },
},
},
})
},
})
alias: 'post',
})
t.list.field('feed', {
type: 'Post',
resolve: (_, args, ctx) => {
return ctx.photon.posts.findMany({
where: { published: true },
})
},
})
t.list.field('filterPosts', {
type: 'Post',
args: {
searchString: stringArg({ nullable: true }),
},
resolve: (_, { searchString }, ctx) => {
return ctx.photon.posts.findMany({
where: {
OR: [
{ title: { contains: searchString } },
{ content: { contains: searchString } },
],
},
})
},
})
},
})
definition(t) {
t.crud.createOneUser({ alias: 'signupUser' })
t.crud.deleteOnePost()
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg({ nullable: false }),
content: stringArg(),
authorEmail: stringArg(),
},
resolve: (_, { title, content, authorEmail }, ctx) => {
return ctx.photon.posts.create({
data: {
title,
content,
published: false,
author: {
connect: { email: authorEmail },
},
},
})
},
})
alias: 'post',
})
t.list.field('feed', {
type: 'Post',
resolve: (_, args, ctx) => {
return ctx.photon.posts.findMany({
where: { published: true },
})
},
})
t.list.field('filterPosts', {
type: 'Post',
args: {
searchString: stringArg({ nullable: true }),
},
resolve: (_, { searchString }, ctx) => {
return ctx.photon.posts.findMany({
where: {
OR: [
{ title: { contains: searchString } },
{ content: { contains: searchString } },
],
},
})
},
})
},
})
definition(t) {
t.field('signup', {
type: 'AuthPayload',
args: {
name: stringArg({ nullable: true }),
email: stringArg(),
password: stringArg(),
isAdmin: booleanArg(),
arenaHandle: stringArg()
},
resolve: async (
_parent,
{ name, email, password, arenaHandle },
ctx
) => {
const hashedPassword = await hash(password, 10);
const user = await ctx.photon.users.create({
data: {
name,
email,
arenaHandle,
password: hashedPassword
}
});
return {
t.field('deletePost', {
type: 'Post',
nullable: true,
args: {
id: idArg(),
},
resolve: (parent, args, ctx) => {
return ctx.prisma.deletePost({ id: args.id })
},
})
t.field('signupUser', {
type: 'User',
args: {
name: stringArg(),
email: stringArg(),
},
resolve: (parent, { name, email }, ctx) => {
return ctx.prisma.createUser({ name, email })
},
})
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg(),
content: stringArg(),
authorEmail: stringArg(),
},
resolve: (parent, { title, content, authorEmail }, ctx) => {
return ctx.prisma.createPost({
title,
alias: 'post',
})
t.list.field('feed', {
type: 'Post',
resolve: (_parent, _args, ctx) => {
return ctx.photon.posts.findMany({
where: { published: true },
})
},
})
t.list.field('filterPosts', {
type: 'Post',
args: {
searchString: stringArg({ nullable: true }),
},
resolve: (_, { searchString }, ctx) => {
return ctx.photon.posts.findMany({
where: {
OR: [
{ title: { contains: searchString } },
{ content: { contains: searchString } },
],
},
})
},
})
},
})
definition(t) {
t.crud.createOneUser({ alias: 'signupUser' })
t.crud.deleteOnePost()
t.field('createDraft', {
type: 'Post',
args: {
title: stringArg(),
content: stringArg({ nullable: true }),
authorEmail: stringArg(),
},
resolve: (_, { title, content, authorEmail }, ctx) => {
return ctx.photon.posts.create({
data: {
title,
content,
published: false,
author: {
connect: { email: authorEmail },
},
},
})
},
})