Skip to content

#16 Written error class in typescript #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2017

Conversation

lakhansamani
Copy link
Contributor

  • This branch contains apollo-error code in Typescript

Copy link
Owner

@thebigredgeek thebigredgeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks great! Let's see if we can make a few more changes before I merge this. Thanks, man!

src/index.ts Outdated
import ExtendableError from 'es6-error';

import * as assert from 'assert';
import ExtendableError from 'extendable-error';
const isString = d => Object.prototype.toString.call(d) === '[object String]';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you skip a line between the imports and the isString definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Makefile Outdated
@@ -13,7 +13,7 @@ endif
.FORCE:

all: clean
babel src -d dist --source-maps
npm run build
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run the command directly from the makefile rather than from npm scripts? The PATH environment variable will already be set from the Makefile, so you can run project-scoped npm binaries from Makefile without having to use npm scripts

Copy link
Contributor Author

@lakhansamani lakhansamani Sep 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do that

package.json Outdated
"es6-error": "^4.0.0"
"assert": "^1.4.1",
"extendable-error": "^0.1.5",
"install": "^0.10.1"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"extendable-error": "^0.1.5"is required for parent class of ApolloError, so it typescript version of es6-error
"assert": "^1.4.1" is required for asserting types in typescript

Have removed install

package.json Outdated
@@ -4,7 +4,8 @@
"description": "Machine-readable custom errors for Apollostack's GraphQL server",
"main": "dist/index.js",
"scripts": {
"test": "make test"
"test": "make test",
"build": "tsc"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to the makefile for the build step. I added the test script to run make test just to keep things canonical with npm init

src/index.ts Outdated
super(m);
name: string;
message: string;
time_thrown: any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we type time_thrown? That should also be in ISODate (string)

src/index.ts Outdated
data: any;
path: any;
locations: any;
_showLocations: any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably type this as boolean and make sure that it is set or defaulted to false

src/index.ts Outdated
message: string;
time_thrown: any;
data: any,
options: any,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explicitly type the options? That seems like a good idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, why not?

src/index.ts Outdated

interface ErrorConfig {
message: string;
time_thrown: any;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we explicitly type time_thrown? See the comment on the class property

src/index.ts Outdated
return error;
}
}

export const isInstance = e => e instanceof ApolloError;

export const createError = (name, config) => {
export const createError = (name, config: ErrorConfig) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we type name to string?

tsconfig.json Outdated
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we prune this down at all? We don't need experimental decorator support, etc.

* Adds build script in make file
* Removes un-used modules from package.json
* Changes type of time_thrown and _showLocation
* Gives default type as string to name parameter in constructor and createError
* Removes unsued configurations from tsconfig
@lakhansamani
Copy link
Contributor Author

@thebigredgeek have made the requested changes, please review and let me know if there are any other

@thebigredgeek thebigredgeek merged commit 7fce29b into thebigredgeek:master Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants