-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: GraphQL support * chore: Added GraphQL throw examples * fix: captureException mocks * chore: Added GraphQL warning error * docs(readme): remove context options, and fixed typo * chore: update dependencies * chore: Added withGraphQL options * fix: use getContext * docs(readme): apply prettier
- Loading branch information
Showing
40 changed files
with
2,548 additions
and
5,353 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,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], | ||
] | ||
`); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
test/test-project/src/app.controller.ts → example/src/app.controller.ts
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
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,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 {} |
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
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,7 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { GqlResolver } from './gql.resolver'; | ||
|
||
@Module({ | ||
providers: [GqlResolver], | ||
}) | ||
export class GqlModule {} |
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,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, | ||
} | ||
`)); | ||
}); |
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,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.
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 @@ | ||
# ----------------------------------------------- | ||
# !!! 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.
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
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,3 +1,3 @@ | ||
export * from './raven.interceptor' | ||
export * from './raven.interceptor'; | ||
export * from './raven.interfaces'; | ||
export * from './raven.module'; |
Oops, something went wrong.