-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Santos
authored and
Lucas Santos
committed
Mar 17, 2021
1 parent
ac5dd33
commit 37b4d76
Showing
26 changed files
with
192 additions
and
15,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL=mysql://root:root@localhost:3306/serverless-db?schema=public |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/api/prisma/migrations/20210317084929_add_users_table/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- CreateTable | ||
CREATE TABLE `User` ( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`first_name` VARCHAR(100) NOT NULL, | ||
`last_name` VARCHAR(100) NOT NULL, | ||
`email` VARCHAR(500) NOT NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { GraphqlContext } from './graphql/context'; | ||
|
||
|
||
|
||
|
||
|
||
export type Action<T, S> = (req: T, ctx: GraphqlContext) => S | Promise<S> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { User } from '@prisma/client'; | ||
import { Action } from '../../../action'; | ||
import { AddUserRequest } from '../requests'; | ||
|
||
|
||
|
||
|
||
const addUserAction: Action<AddUserRequest, User> = async (req, ctx) => { | ||
|
||
const user = await ctx.prisma.user.create({ | ||
data: { | ||
email: req.email, | ||
first_name: req.name, | ||
last_name: req.name | ||
} | ||
}) | ||
return user; | ||
|
||
} | ||
|
||
|
||
export default addUserAction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
import { User } from '@prisma/client'; | ||
import { Action } from '../../../action'; | ||
import { GetAllUsersRequest } from '../requests'; | ||
|
||
export const getAllUsersAction: Action<GetAllUsersRequest, User[]> = async (req, ctx) => { | ||
const users = await ctx.prisma.user.findMany(); | ||
return users; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import { User } from '@prisma/client'; | ||
import { Action } from '../../../action'; | ||
import { GetUserRequest } from '../requests'; | ||
|
||
|
||
|
||
|
||
|
||
export const getUserAction: Action<GetUserRequest, User | null> = async (req, ctx) => { | ||
//todo: infer nullable type - prismic issue | ||
const user = await ctx.prisma.user.findUnique({ | ||
rejectOnNotFound: false, | ||
where: { | ||
id: req.id | ||
} | ||
}); | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
return user; | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import ApiRequest from '../../../request'; | ||
|
||
|
||
|
||
|
||
export default class AddUserRequest extends ApiRequest { | ||
|
||
|
||
} | ||
/** | ||
* | ||
*/ | ||
export class AddUserRequest extends ApiRequest { | ||
|
||
name: string; | ||
email: string; | ||
} |
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
packages/api/src/features/user/requests/getAllUsersRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ApiRequest from '../../../request'; | ||
|
||
|
||
|
||
export class GetAllUsersRequest extends ApiRequest { | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ApiRequest from '../../../request'; | ||
|
||
|
||
|
||
export class GetUserRequest extends ApiRequest { | ||
id: number; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
export * from "./addUserRequest"; | ||
export * from "./getAllUsersRequest"; | ||
export * from "./getUserRequest"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { User } from '@prisma/client'; | ||
import { stringArg } from 'nexus'; | ||
import { ObjectDefinitionBlock } from 'nexus/dist/blocks'; | ||
import { GraphQResolver } from '../../types'; | ||
import addUserAction from './actions/addUser'; | ||
import { AddUserRequest } from './requests'; | ||
|
||
|
||
|
||
const addUser: GraphQResolver<AddUserRequest, User | null> = async (parent, args, ctx) => { | ||
const user = await addUserAction(args, ctx) | ||
return user; | ||
} | ||
|
||
export default (t: ObjectDefinitionBlock<"Mutation">) => { | ||
t.field('addUser', { | ||
args: { | ||
name: stringArg({}), | ||
first_name: stringArg({}), | ||
last_name: stringArg({}), | ||
email: stringArg({}) | ||
}, | ||
type: 'User', | ||
resolve: addUser | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { User } from '@prisma/client'; | ||
import { intArg } from 'nexus'; | ||
import { ObjectDefinitionBlock } from 'nexus/dist/blocks'; | ||
import { GraphQResolver } from '../../types'; | ||
import { getAllUsersAction } from './actions/getAllUsers'; | ||
import { getUserAction } from './actions/getUser'; | ||
import { GetAllUsersRequest, GetUserRequest } from './requests'; | ||
|
||
|
||
|
||
|
||
const getUser: GraphQResolver<GetUserRequest, User> = async (parent, args, ctx) => { | ||
const users = await getUserAction(args, ctx) | ||
return users; | ||
} | ||
|
||
const getAllUsers: GraphQResolver<GetAllUsersRequest, User[]> = async (parent, args, ctx) => { | ||
const users = await getAllUsersAction(args, ctx) | ||
return users; | ||
} | ||
|
||
|
||
export default (t: ObjectDefinitionBlock<"Query">) => { | ||
t.field('allUsers', { | ||
type: 'User', | ||
resolve: getAllUsers | ||
}); | ||
|
||
t.field('user', { | ||
args: { | ||
id: intArg({}), | ||
}, | ||
type: 'User', | ||
resolve: getUser | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.