-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
65f538e
commit 0e370b6
Showing
24 changed files
with
1,803 additions
and
1,532 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
# Changelog | ||
|
||
## [2.0.0] - 2019-11-24 | ||
|
||
### Added | ||
- Add user error in payload with union fragments | ||
|
||
### Changed | ||
- Standardize arguments | ||
|
||
### Removed | ||
- Lazy relation in entities | ||
|
||
## [1.0.0] - 2019-07-14 | ||
First release |
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
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
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,22 @@ | ||
import { MyError } from "../../utils/error"; | ||
|
||
export class InvalidEmailOrPasswordError extends MyError { | ||
constructor() { | ||
const message = "invalid email or password"; | ||
super(message); | ||
} | ||
} | ||
|
||
export class EmailAlreadyUseError extends MyError { | ||
constructor() { | ||
const message = "email already use"; | ||
super(message); | ||
} | ||
}; | ||
|
||
export class UsernameAlreadyUseError extends MyError { | ||
constructor() { | ||
const message = "username already use"; | ||
super(message); | ||
} | ||
}; |
18 changes: 10 additions & 8 deletions
18
...plates/src/graphql/auth/register.input.ts → .../templates/src/graphql/auth/auth.input.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
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,13 @@ | ||
|
||
import { ObjectType, Field } from "type-graphql"; | ||
import { User } from "../../entities/user"; | ||
import { userResponse } from "../../utils/genericTypes"; | ||
|
||
@ObjectType() | ||
export class LoginType { | ||
@Field() | ||
public token: string; | ||
} | ||
|
||
export const LoginPayload = userResponse("LoginPayload", LoginType); | ||
export const RegisterPayload = userResponse("RegisterPayload", User); |
38 changes: 24 additions & 14 deletions
38
generators/app/templates/src/graphql/auth/auth.resolver.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 |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import { Resolver, Query, Arg, Mutation } from "type-graphql"; | ||
|
||
import { RegisterInput } from "./register.input"; | ||
import { LoginInput } from "./login.input"; | ||
import { Arg, Mutation, Query, Resolver } from "type-graphql"; | ||
import { Inject } from "typedi"; | ||
import { MyError } from "../../utils/error"; | ||
import { UserError } from "../../utils/genericTypes"; | ||
import { LoginInput, RegisterInput } from "./auth.input"; | ||
import { LoginPayload, LoginType, RegisterPayload } from "./auth.payload"; | ||
import { UserService } from "./user.service"; | ||
import { User } from "../../entities/user"; | ||
import { AuthenticationError } from "apollo-server"; | ||
|
||
|
||
@Resolver() | ||
export class AuthResolver { | ||
@Inject() | ||
private readonly userService: UserService; | ||
|
||
@Query((): StringConstructor => String) | ||
public async login(@Arg("login") loginInput: LoginInput): Promise<string> { | ||
@Query((): typeof LoginPayload => LoginPayload) | ||
public async login(@Arg("input") input: LoginInput): Promise<typeof LoginPayload> { | ||
try { | ||
return await this.userService.login(loginInput); | ||
const loginType = new LoginType(); | ||
const token = await this.userService.login(input.email, input.password); | ||
|
||
loginType.token = token; | ||
return loginType; | ||
} catch(e) { | ||
throw new AuthenticationError("invalid login or password"); | ||
if (e instanceof MyError) { | ||
return new UserError(e.message); | ||
} | ||
} | ||
} | ||
|
||
@Mutation((): typeof User => User) | ||
public async register(@Arg("user") registerInput: RegisterInput): Promise<User> { | ||
return this.userService.register(registerInput); | ||
@Mutation((): typeof RegisterPayload => RegisterPayload) | ||
public async register(@Arg("input") input: RegisterInput): Promise<typeof RegisterPayload> { | ||
try { | ||
return await this.userService.register(input.username, input.password, input.email); | ||
} catch(e) { | ||
if (e instanceof MyError) { | ||
return new UserError(e.message); | ||
} | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
generators/app/templates/src/graphql/project/project.error.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 { MyError } from "../../utils/error"; | ||
|
||
export class ProjectSameNameError extends MyError { | ||
constructor(projectName: string) { | ||
const message = `project ${projectName} already exists`; | ||
super(message); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
generators/app/templates/src/graphql/project/project.payload.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,4 @@ | ||
import { userResponse } from "../../utils/genericTypes"; | ||
import { Project } from "../../entities/project"; | ||
|
||
export const CreateProjectPayload = userResponse("CreateProjectPayload", Project); |
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.