-
Notifications
You must be signed in to change notification settings - Fork 33
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
Andrew E. Rhyne
committed
Nov 11, 2016
1 parent
f7d919f
commit 668819d
Showing
15 changed files
with
509 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"sourceMaps": true | ||
} |
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,10 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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,20 @@ | ||
{ | ||
"ecmaFeatures": { | ||
"modules": true | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"parser": "babel-eslint", | ||
"rules": { | ||
"quotes": [2, "single"], | ||
"strict": [2, "never"], | ||
"babel/new-cap": 1, | ||
"babel/object-shorthand": 0, | ||
"babel/arrow-parens": 0 | ||
}, | ||
"plugins": [ | ||
"babel" | ||
] | ||
} |
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 |
---|---|---|
|
@@ -35,3 +35,6 @@ jspm_packages | |
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Yarn | ||
yarn.lock |
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 @@ | ||
src | ||
test | ||
.babelrc | ||
.editorconfig | ||
.eslintrc | ||
.gitignore | ||
circle.yml | ||
Makefile |
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 @@ | ||
1.0.1 / 2016-11-10 | ||
================== | ||
|
||
* Initial 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
PATH := node_modules/.bin:$(PATH) | ||
SHELL := /bin/bash | ||
|
||
UNAME_S := $(shell uname -s) | ||
|
||
ifeq ($(UNAME_S),Linux) | ||
OS_TYPE := linux | ||
endif | ||
ifeq ($(UNAME_S),Darwin) | ||
OS_TYPE := osx | ||
endif | ||
|
||
.FORCE: | ||
|
||
all: clean | ||
babel src -d dist --source-maps | ||
|
||
clean: .FORCE | ||
rimraf npm-debug.log dist | ||
|
||
osx-syspackages: .FORCE | ||
brew update | ||
brew install yarn | ||
|
||
linux-syspackages: .FORCE | ||
sudo apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3 | ||
echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list | ||
sudo apt-get -y update | ||
sudo apt-get install yarn | ||
|
||
environment: .FORCE | ||
@if [ "${OS_TYPE}" = "osx" ]; then \ | ||
make osx-syspackages; \ | ||
else \ | ||
make linux-syspackages; \ | ||
fi | ||
|
||
dependencies: .FORCE | ||
yarn | ||
|
||
test: all | ||
mocha | ||
|
||
lint: .FORCE | ||
eslint src |
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,2 +1,104 @@ | ||
# apollo-errors | ||
A sane way to create and throw custom errors with Apollo's graphql server | ||
Machine-readable custom errors for Apollostack's GraphQL server | ||
|
||
[![NPM](https://nodei.co/npm/apollo-errors.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/apollo-errors/) | ||
|
||
[![CircleCI](https://circleci.com/gh/thebigredgeek/apollo-errors.svg?style=shield)](https://circleci.com/gh/thebigredgeek/apollo-errors/tree/master) | ||
|
||
|
||
## Installation and usage | ||
|
||
Install the package: | ||
|
||
```bash | ||
npm install apollo-errors | ||
``` | ||
|
||
Create some errors: | ||
|
||
```javascript | ||
import { createError } from 'apollo-errors'; | ||
|
||
export const FooError = createError('FooError', { | ||
message: 'A foo error has occurred' | ||
}); | ||
``` | ||
|
||
Hook up formatting: | ||
|
||
```javascript | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import { formatError } from 'apollo-errors'; | ||
import schema from './schema'; | ||
|
||
const app = express(); | ||
|
||
app.use('/graphql', | ||
bodyParser.json(), | ||
graphqlExpress({ | ||
formatError, | ||
schema | ||
}) | ||
); | ||
|
||
app.listen(8080) | ||
``` | ||
|
||
Throw some errors: | ||
|
||
```javascript | ||
import { FooError } from './errors'; | ||
|
||
const resolverThatThrowsError = (root, params, context) => { | ||
throw new FooError({ | ||
data: { | ||
something: 'important' | ||
} | ||
}); | ||
} | ||
``` | ||
|
||
Witness glorious simplicity: | ||
|
||
`POST /graphql (200)` | ||
|
||
```json | ||
{ | ||
"data": {}, | ||
"errors": [ | ||
{ | ||
"message":"A foo error has occurred", | ||
"name":"FooError", | ||
"time_thrown":"2016-11-11T00:40:50.954Z", | ||
"data":{ | ||
"something": "important" | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### ApolloError ({ [time_thrown: String, data: Object]}) | ||
|
||
Creates a new ApolloError object. Note that `ApolloError` in this context refers | ||
to an error class created and returned by `createError` documented below. Error can be | ||
initialized with a custom `time_thrown` ISODate (default is current ISODate) and `data` object (which will be merged with data specified through `createError`, if it exists). | ||
|
||
|
||
### createError(name, {message: String, [data: Object]}): ApolloError | ||
|
||
Creates and returns an error class with the given `name` and `message`, optionally initialized with the given `data`. `data` passed to `createError` will later be merged with any data passed to the constructor. | ||
|
||
### formatError (error, strict = false): ApolloError|Error|null | ||
If the error is a known ApolloError, returns the serialized form of said error. | ||
|
||
**Otherwise**, *if strict is not truthy*, returns the original error passed into formatError. | ||
|
||
**Otherwise**, *if strict is truthy*, returns null. | ||
|
||
## TODO | ||
|
||
- Add better docs |
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,14 @@ | ||
machine: | ||
node: | ||
version: 5.5.0 | ||
|
||
dependencies: | ||
override: | ||
- make environment | ||
- make dependencies | ||
|
||
test: | ||
override: | ||
- make lint | ||
- make | ||
- make test |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "apollo-errors", | ||
"version": "1.0.1", | ||
"description": "Machine-readable custom errors for Apollostack's GraphQL server", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/thebigredgeek/apollo-errors.git" | ||
}, | ||
"keywords": [ | ||
"apollostack", | ||
"graphql", | ||
"error", | ||
"api" | ||
], | ||
"author": "Andrew E. Rhyne <rhyneandrew@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/thebigredgeek/apollo-errors/issues" | ||
}, | ||
"homepage": "https://github.com/thebigredgeek/apollo-errors#readme", | ||
"dependencies": { | ||
"es6-error": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.17.0", | ||
"babel-eslint": "^7.0.0", | ||
"babel-preset-es2015": "^6.16.0", | ||
"babel-register": "^6.18.0", | ||
"chai": "^3.5.0", | ||
"eslint": "^3.8.1", | ||
"eslint-plugin-babel": "^3.3.0", | ||
"mocha": "^3.1.2", | ||
"rimraf": "^2.5.4" | ||
} | ||
} |
Oops, something went wrong.