updated context
This commit is contained in:
parent
04b606b7fa
commit
40c35bda13
7 changed files with 67 additions and 25 deletions
|
|
@ -1,9 +1,14 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
import { MutationLoginArgs, Session } from '@generated/types';
|
||||
import bcrypt from 'bcrypt';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
export async function LoginResolver(_: any, { input }: MutationLoginArgs): Promise<Session> {
|
||||
export async function LoginResolver(
|
||||
_: any,
|
||||
{ input }: MutationLoginArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<Session> {
|
||||
const error = 'Invalid username or password';
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma, uuid } from '@app/server/prisma/client';
|
||||
import { RegisterInput } from '@generated/types';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
export async function SignUpResolver(_: any, input: RegisterInput): Promise<void> {
|
||||
export async function SignUpResolver(
|
||||
_: any,
|
||||
input: RegisterInput,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<void> {
|
||||
const existingUsername = await prisma.user.findUnique({
|
||||
where: { username: input.username },
|
||||
select: { id: true }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { Book, QueryBookOneArgs } from '@generated/types';
|
||||
import { books } from './booksManyResolver';
|
||||
|
||||
export async function BookOneResolver(_: any, { id }: QueryBookOneArgs): Promise<Book> {
|
||||
export async function BookOneResolver(
|
||||
_: any,
|
||||
{ id }: QueryBookOneArgs,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<Book> {
|
||||
const book = books.filter(item => item.id === id)[0];
|
||||
|
||||
return book;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { Book } from '@generated/types';
|
||||
|
||||
export const books = [
|
||||
|
|
@ -13,6 +14,10 @@ export const books = [
|
|||
}
|
||||
];
|
||||
|
||||
export async function BooksManyResolver(_: any): Promise<Book[]> {
|
||||
export async function BooksManyResolver(
|
||||
_: any,
|
||||
__: any,
|
||||
{ identity }: IdentityContext
|
||||
): Promise<Book[]> {
|
||||
return books;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue