-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added travis yml and updated readme with build badge * Readme update * Renamed prohecy to generate * Updated folder structure * Added test and file manipulation dependencies * Added tests for writClassFile * Library Renamed to apollo-prophecy pythian -> prophecy, Pythian* -> Prophetic * 0.1.1 * Added version related scripts * Fixed build errors Added express types as dev dependency * 0.1.0 * Added mocha to dev dependencies * 0.1.0 pre relase clean * 0.1.0 pre release build * Update output message & moved "@types/graphql" to "devDependencies" * Readme update * Added readme logo 🔮 * Feature/ask command/#1 (#8) * Added Ask/Fetch command * Code generation clean * Updated structure and added tests * Fix: added handle method to PropheticErrorHandled * Updated readme with ask explanation * Added Table of Contents * Readme enhenced * Added nyc for test code coverage * Feature/yargs/#3 (#9) * Replaced minimist with yargs closes #3 * post release clean * Readme occurence removed * Readme update on Table of Contents * Restructured error generation * Updated readme accordingly to recent updates * Fixed tests
- Loading branch information
Showing
28 changed files
with
2,437 additions
and
198 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 |
---|---|---|
|
@@ -6,3 +6,7 @@ node_modules | |
*.log | ||
_generated/ | ||
_generated/Errors.ts | ||
.nyc_output | ||
coverage | ||
Errors.ts | ||
errors.json |
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,77 @@ | ||
Here you will find an example of client-side generated `Errors.ts`; | ||
|
||
```ts | ||
/* tslint:disable */ | ||
import { ApolloError } from "apollo-client"; | ||
import { GraphQLError } from "graphql"; | ||
|
||
export enum PropheticErrorCode { | ||
CodeLessError = 'NONE', | ||
UnknownError = "UNKNOWN", | ||
ForbiddenError = "FORBIDDEN", | ||
AuthenticationRequiredError = "AUTH_REQUIRED" | ||
} | ||
|
||
export class PropheticError { | ||
constructor(public codes: string[]){} | ||
|
||
private inCodes(code: PropheticErrorCode){ return this.codes.indexOf(code) > -1; } | ||
|
||
get isCodeLessError() { return this.inCodes(PropheticErrorCode.CodeLessError); } | ||
get isUnknownError() { return this.inCodes(PropheticErrorCode.UnknownError); } | ||
get isForbiddenError() { return this.inCodes(PropheticErrorCode.ForbiddenError); } | ||
get isAuthenticationRequiredError() { return this.inCodes(PropheticErrorCode.AuthenticationRequiredError); } | ||
} | ||
|
||
export interface Handler { | ||
(): any | ||
} | ||
|
||
export class PropheticErrorHandled { | ||
private handler: Handler = () => {} | ||
|
||
constructor(public codes: string[]){} | ||
|
||
private inCodes(code: PropheticErrorCode, handler: Handler){ | ||
if(this.codes.indexOf(code) > -1){ | ||
this.handler = handler | ||
} | ||
|
||
return this; | ||
} | ||
|
||
CodeLessError(handler: Handler) { return this.inCodes(PropheticErrorCode.CodeLessError, handler); } | ||
UnknownError(handler: Handler) { return this.inCodes(PropheticErrorCode.UnknownError, handler); } | ||
ForbiddenError(handler: Handler) { return this.inCodes(PropheticErrorCode.ForbiddenError, handler); } | ||
AuthenticationRequiredError(handler: Handler) { return this.inCodes(PropheticErrorCode.AuthenticationRequiredError, handler); } | ||
handle() { return this.handler(); } | ||
} | ||
|
||
const CODE_LESS_EXTENSION = { code: 'NONE'}; | ||
const findCodes = (error: ApolloError | GraphQLError): PropheticErrorCode[] => { | ||
if(error instanceof ApolloError) { | ||
return error.graphQLErrors.map((gError) => findCodes(gError)[0]); | ||
} else if(error.extensions) { | ||
const { extensions: { code } = CODE_LESS_EXTENSION } = error; | ||
return [code]; | ||
} | ||
|
||
return [PropheticErrorCode.CodeLessError]; | ||
} | ||
|
||
export const errorHere = (error: ApolloError | GraphQLError | undefined ) => { | ||
if(!error) { | ||
return new PropheticError([]); | ||
} | ||
const codes = findCodes(error); | ||
return new PropheticError(codes); | ||
} | ||
|
||
export const isThis = (error: ApolloError | GraphQLError | undefined) => { | ||
if(!error) { | ||
return new PropheticErrorHandled([]); | ||
} | ||
const codes = findCodes(error); | ||
return new PropheticErrorHandled(codes); | ||
} | ||
``` |
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,82 @@ | ||
/* tslint:disable */ | ||
import { ApolloError } from "apollo-client"; | ||
import { GraphQLError } from "graphql"; | ||
|
||
export enum PropheticErrorCode { | ||
CodeLessError = 'NONE', | ||
UnknownError = "CAN_NOT_FETCH_BY_ID", | ||
ForbiddenError = "null", | ||
AuthenticationRequiredError = "AUTH_REQUIRED", | ||
MagicTokenExpiredError = "MAGIC_TOKEN_EXPIRED", | ||
UserNotFoundError = "USER_NOT_FOUND", | ||
UserAlreadyExist = "USER_ALREADY_EXISTS" | ||
} | ||
|
||
export class PropheticError { | ||
constructor(public codes: string[]){} | ||
|
||
private inCodes(code: PropheticErrorCode) { return this.codes.indexOf(code) > -1; } | ||
|
||
get isCodeLessError() { return this.inCodes(PropheticErrorCode.CodeLessError); } | ||
get isUnknownError() { return this.inCodes(PropheticErrorCode.UnknownError); } | ||
get isForbiddenError() { return this.inCodes(PropheticErrorCode.ForbiddenError); } | ||
get isAuthenticationRequiredError() { return this.inCodes(PropheticErrorCode.AuthenticationRequiredError); } | ||
get isMagicTokenExpiredError() { return this.inCodes(PropheticErrorCode.MagicTokenExpiredError); } | ||
get isUserNotFoundError() { return this.inCodes(PropheticErrorCode.UserNotFoundError); } | ||
get isUserAlreadyExist() { return this.inCodes(PropheticErrorCode.UserAlreadyExist); } | ||
} | ||
|
||
export interface Handler { | ||
(): any | ||
} | ||
|
||
export class PropheticErrorHandled { | ||
private handler: Handler = () => {} | ||
|
||
constructor(public codes: string[]){} | ||
|
||
private inCodes(code: PropheticErrorCode, handler: Handler){ | ||
if(this.codes.indexOf(code) > -1){ | ||
this.handler = handler | ||
} | ||
|
||
return this; | ||
} | ||
|
||
CodeLessError(handler: Handler) { return this.inCodes(PropheticErrorCode.CodeLessError, handler); } | ||
UnknownError(handler: Handler) { return this.inCodes(PropheticErrorCode.UnknownError, handler); } | ||
ForbiddenError(handler: Handler) { return this.inCodes(PropheticErrorCode.ForbiddenError, handler); } | ||
AuthenticationRequiredError(handler: Handler) { return this.inCodes(PropheticErrorCode.AuthenticationRequiredError, handler); } | ||
MagicTokenExpiredError(handler: Handler) { return this.inCodes(PropheticErrorCode.MagicTokenExpiredError, handler); } | ||
UserNotFoundError(handler: Handler) { return this.inCodes(PropheticErrorCode.UserNotFoundError, handler); } | ||
UserAlreadyExist(handler: Handler) { return this.inCodes(PropheticErrorCode.UserAlreadyExist, handler); } | ||
handle() { return this.handler(); } | ||
} | ||
|
||
const CODE_LESS_EXTENSION = { code: 'NONE'}; | ||
const findCodes = (error: ApolloError | GraphQLError): PropheticErrorCode[] => { | ||
if(error instanceof ApolloError) { | ||
return error.graphQLErrors.map((gError) => findCodes(gError)[0]); | ||
} else if(error.extensions) { | ||
const { extensions: { code } = CODE_LESS_EXTENSION } = error; | ||
return [code]; | ||
} | ||
|
||
return [PropheticErrorCode.CodeLessError]; | ||
} | ||
|
||
export const errorHere = (error: ApolloError | GraphQLError | undefined ) => { | ||
if(!error) { | ||
return new PropheticError([]); | ||
} | ||
const codes = findCodes(error); | ||
return new PropheticError(codes); | ||
} | ||
|
||
export const isThis = (error: ApolloError | GraphQLError | undefined) => { | ||
if(!error) { | ||
return new PropheticErrorHandled([]); | ||
} | ||
const codes = findCodes(error); | ||
return new PropheticErrorHandled(codes); | ||
} |
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.