Skip to content

Commit

Permalink
fix(graphql-binding): adds error utility (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Jun 10, 2019
1 parent 9b709b3 commit 905c74a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 13 deletions.
8 changes: 6 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
"protocol": "inspector"
},
{
"name": "TS-Node",
"name": "ts-node",
"type": "node",
"request": "launch",
"args": ["${relativeFile}"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector"
"protocol": "inspector",
"env": {
"TS_NODE_IGNORE": "false",
"DEBUG": "*"
}
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"express": "^4.16.4",
"faker": "^4.1.0",
"graphql": "^14.0.2",
"graphql-binding": "^2.4.0",
"graphql-binding": "^2.5.1",
"graphql-iso-date": "^3.6.1",
"graphql-tools": "^4.0.3",
"graphql-type-json": "^0.3.0",
Expand Down
8 changes: 5 additions & 3 deletions src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ export class Server<C extends BaseContext> {

const contextGetter =
this.appOptions.context ||
(() => {
(async () => {
return {};
});

debug('start:ApolloServerAllocation:start');
this.graphQLServer = new ApolloServer({
context: async (options: { req: Request }) => {
const consumerCtx = await contextGetter(options.req);
const consumerCtx = contextGetter(options.req);
return {
connection: this.connection,
dataLoader: {
Expand Down Expand Up @@ -231,7 +231,9 @@ export class Server<C extends BaseContext> {

// Open playground in the browser
if (this.shouldOpenPlayground()) {
open(url, { wait: false });
// Assigning to variable and logging to appease linter
const process = open(url, { wait: false });
debug('process', process);
}

debug('start:end');
Expand Down
26 changes: 26 additions & 0 deletions src/gql/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,30 @@ export async function generateBindingFile(inputSchemaPath: string, outputBinding
debug('generateBindingFile:end');
}

export function getBindingError(err: any) {
const error = getOriginalError(err);
if (
error &&
error.extensions &&
error.extensions.exception &&
error.extensions.exception.validationErrors
) {
error.extensions.exception.validationErrors.forEach((item: any) => {
error.validationErrors = error.validationErrors || {};
error.validationErrors[item.property] = item.constraints;
});
}
return error;
}

export function getOriginalError(error: any): any {
if (error.originalError) {
return getOriginalError(error.originalError);
}
if (error.errors) {
return error.errors.map(getOriginalError)[0];
}
return error;
}

export { Binding };
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './core';
export * from './decorators';
export * from './gql';
export * from './middleware';
export * from './schema';
export * from './tgql';
Expand Down
2 changes: 1 addition & 1 deletion src/tgql/BaseResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeepPartial, Repository } from 'typeorm';
import { Repository } from 'typeorm';

import { BaseModel, BaseService, WhereInput } from '../core';

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"types": ["jest", "isomorphic-fetch", "node"]
Expand Down
23 changes: 17 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3159,14 +3159,14 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==

graphql-binding@^2.4.0:
version "2.4.1"
resolved "https://registry.npmjs.org/graphql-binding/-/graphql-binding-2.4.1.tgz#5880b78670b5910b3589a6fa76441e9a7d8c289c"
integrity sha512-UHSVM2bfB4gGtwRcUXwejo2R825Rm8vnJGA6+IB+NquObXBdw6YvDSTIwgavsNM6I6qRlyl0CUaAf/r15YYqwQ==
graphql-binding@^2.5.1:
version "2.5.1"
resolved "https://registry.npmjs.org/graphql-binding/-/graphql-binding-2.5.1.tgz#cacd8d579c4098541dadb9325255c09e476ab65c"
integrity sha512-9Lejxa7h/WcNZYyTvFQG12QUK8pkgbeEbEnMw3o/DsRhlIB8hrh+a+mbJgHpZ+dcUzSBGyTByiLAI3OLg7B//g==
dependencies:
graphql "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
graphql-import "^0.7.1"
graphql-tools "4.0.3"
graphql-tools "4.0.4"
iterall "1.2.2"
object-path-immutable "^3.0.0"
resolve-cwd "^2.0.0"
Expand Down Expand Up @@ -3219,7 +3219,18 @@ graphql-tag@^2.9.2:
resolved "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.10.0.tgz#87da024be863e357551b2b8700e496ee2d4353ae"
integrity sha512-9FD6cw976TLLf9WYIUPCaaTpniawIjHWZSwIRZSjrfufJamcXbVVYfN2TWvJYbw0Xf2JjYbl1/f2+wDnBVw3/w==

[email protected], graphql-tools@^4.0.0, graphql-tools@^4.0.3:
[email protected]:
version "4.0.4"
resolved "https://registry.npmjs.org/graphql-tools/-/graphql-tools-4.0.4.tgz#ca08a63454221fdde825fe45fbd315eb2a6d566b"
integrity sha512-chF12etTIGVVGy3fCTJ1ivJX2KB7OSG4c6UOJQuqOHCmBQwTyNgCDuejZKvpYxNZiEx7bwIjrodDgDe9RIkjlw==
dependencies:
apollo-link "^1.2.3"
apollo-utilities "^1.0.1"
deprecated-decorator "^0.1.6"
iterall "^1.1.3"
uuid "^3.1.0"

graphql-tools@^4.0.0, graphql-tools@^4.0.3:
version "4.0.3"
resolved "https://registry.npmjs.org/graphql-tools/-/graphql-tools-4.0.3.tgz#23b5cb52c519212b1b2e4630a361464396ad264b"
integrity sha512-NNZM0WSnVLX1zIMUxu7SjzLZ4prCp15N5L2T2ro02OVyydZ0fuCnZYRnx/yK9xjGWbZA0Q58yEO//Bv/psJWrg==
Expand Down

0 comments on commit 905c74a

Please sign in to comment.