Skip to content

Commit

Permalink
Merge bff2abe into 98c90ef
Browse files Browse the repository at this point in the history
  • Loading branch information
9renpoto committed Mar 10, 2020
2 parents 98c90ef + bff2abe commit 605b56c
Show file tree
Hide file tree
Showing 40 changed files with 2,544 additions and 5,349 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ cache:
directories:
- node_modules

after_success: npm run coverage
before_script: npm run lint
after_success: npm run coverage
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ this should be done in your `main.ts` file where you initialize the NestJS appli
```ts
@Module({
imports: [...RavenModule]
imports: [RavenModule],
})
export class ApplicationModule implements NestModule {}
```
Expand Down Expand Up @@ -126,11 +126,13 @@ Other additional data can be added for each interceptor.
> app.controller.ts
```ts
import { Severity } from '@sentry/node';

@UseInterceptors(new RavenInterceptor({
tags: {
type: 'fileUpload',
},
level: 'warning',
level: Severity.Warning,
}))
@Get('/some/route')
public async someRoute()
Expand All @@ -142,17 +144,12 @@ Other additional data can be added for each interceptor.

> **Note:** Websockets ignore Global interceptors.
When using with websockets, you should provide context, as we cannot autmaticly detarmin if
we are capturing http or websocket exception.

It will add `ws_client` and `ws_data` extras.

> app.gateway.ts
```ts
@UseInterceptors(new RavenInterceptor({
context: 'Ws'
}))
@UseInterceptors(new RavenInterceptor())
@SubscribeMessage('message_name')
public someMessage(client, data: string): string {
...
Expand All @@ -161,20 +158,13 @@ It will add `ws_client` and `ws_data` extras.

#### GraphQL

> **Warning**: This is an ALPHA level of support. There are bugs, not intended for production.
When using with graphql, you should provide context, as we cannot automatically determine if
we are capturing http or graphql exception.

It will add `fieldname` and `args` extras.
It will add `fieldName` and `args` extras.

> app.gateway.ts
```ts
@Mutation()
@UseInterceptors(new RavenInterceptor({
context: 'GraphQL'
}))
@UseInterceptors(new RavenInterceptor())
async upvotePost(@Args('postId') postId: number) {
...
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
75 changes: 75 additions & 0 deletions example/__tests__/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { createTestClient } from 'apollo-server-testing';
import gql from 'graphql-tag';
import { AppModule } from './../src/app.module';

describe('AppModule', () => {
let app: INestApplication;
let apolloClient: ReturnType<typeof createTestClient>;

beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();

const module: GraphQLModule = moduleFixture.get<GraphQLModule>(
GraphQLModule,
);
// apolloServer is protected, we need to cast module to any to get it
apolloClient = createTestClient((module as any).apolloServer);
});

afterAll(() => app.close());

it('defined', () => expect(app).toBeDefined());

it('/ (GET)', () =>
request(app.getHttpServer())
.get('/')
.expect(500));

it('/graphql (GET)', () =>
request(app.getHttpServer())
.get('/graphql')
.expect(400));

it('/graphql(POST) forbiddenError warning', async () => {
const { query } = apolloClient;
const result = await query({
query: gql`
query {
authenticationError
}
`,
variables: {},
});
expect(result.errors).toMatchInlineSnapshot(`
Array [
[GraphQLError: AuthenticationError],
]
`);
});

it('/graphql(POST) forbiddenError', async () => {
const { query } = apolloClient;
const result = await query({
query: gql`
query {
forbiddenError
}
`,
variables: {},
});
expect(result.errors).toMatchInlineSnapshot(`
Array [
[GraphQLError: forbidden],
]
`);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, Get, UseInterceptors } from '@nestjs/common';
import { AppService } from './app.service';
import { RavenInterceptor } from 'nest-raven';
import { RavenInterceptor } from '../../lib';

@Controller()
@UseInterceptors(new RavenInterceptor())
Expand Down
29 changes: 29 additions & 0 deletions example/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { GraphQLModule } from '@nestjs/graphql';
import { RavenInterceptor } from '../../lib';
import { GqlModule } from './gql/gql.module';

@Module({
imports: [
GraphQLModule.forRoot({
autoSchemaFile: 'example/src/schema.gql',
debug: true,
playground: true,
}),
GqlModule,
],
controllers: [AppController],
providers: [
AppService,
{
provide: APP_INTERCEPTOR,
useValue: new RavenInterceptor({
withGraphQL: true,
}),
},
],
})
export class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common';
export class AppService {
getHello(): string {
throw new InternalServerErrorException('This is not good?');
return 'Hello World!';
}
}
7 changes: 7 additions & 0 deletions example/src/gql/gql.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { GqlResolver } from './gql.resolver';

@Module({
providers: [GqlResolver],
})
export class GqlModule {}
35 changes: 35 additions & 0 deletions example/src/gql/gql.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Test, TestingModule } from '@nestjs/testing';
import { GqlResolver } from './gql.resolver';

describe('GqlResolver', () => {
let resolver: GqlResolver;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [GqlResolver],
}).compile();

resolver = module.get<GqlResolver>(GqlResolver);
});

it('should be defined', () => expect(resolver).toBeDefined());

it('apollo-server-errors (AuthenticationError)', () =>
expect(
resolver.authenticationError(),
).rejects.toThrowErrorMatchingInlineSnapshot(`"AuthenticationError"`));

it('apollo-server-errors (Forbidden)', () =>
expect(
resolver.forbiddenError(),
).rejects.toThrowErrorMatchingInlineSnapshot(`"forbidden"`));

it('@nestjs/common (Forbidden)', () =>
expect(resolver.forbiddenException()).rejects
.toThrowErrorMatchingInlineSnapshot(`
Object {
"error": "Forbidden",
"statusCode": 403,
}
`));
});
24 changes: 24 additions & 0 deletions example/src/gql/gql.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Resolver, Query } from '@nestjs/graphql';
import { ForbiddenError, AuthenticationError } from 'apollo-server-errors';
import { ForbiddenException, UseInterceptors } from '@nestjs/common';
import { Severity } from '@sentry/node';
import { RavenInterceptor } from '../../../lib';

@Resolver('Gql')
export class GqlResolver {
@Query(() => Boolean)
async forbiddenError() {
throw new ForbiddenError('forbidden');
}

@Query(() => Boolean)
async forbiddenException() {
throw new ForbiddenException();
}

@UseInterceptors(new RavenInterceptor({ level: Severity.Warning }))
@Query(() => Boolean)
async authenticationError() {
throw new AuthenticationError('AuthenticationError');
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions example/src/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!! DO NOT MODIFY THIS FILE BY YOURSELF !!!
# -----------------------------------------------

type Query {
forbiddenError: Boolean!
forbiddenException: Boolean!
authenticationError: Boolean!
}
File renamed without changes.
1 change: 0 additions & 1 deletion test/test-project/tsconfig.json → example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
},
"exclude": ["node_modules"]
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './raven.interceptor'
export * from './raven.interceptor';
export * from './raven.interfaces';
export * from './raven.module';

0 comments on commit 605b56c

Please sign in to comment.