Skip to content

Commit 6a24cc8

Browse files
author
Shady Khalifa
committed
inline graphql require.
1 parent 7ec9c38 commit 6a24cc8

File tree

4 files changed

+24
-273
lines changed

4 files changed

+24
-273
lines changed

lib/decorators/user-roles.decorators.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.UserRoles = void 0;
44
const common_1 = require("@nestjs/common");
5-
const graphql_1 = require("@nestjs/graphql");
65
function userFactory(ctx) {
76
const contextType = ctx.getType();
87
if (contextType === 'http') {
@@ -19,8 +18,10 @@ function userFactory(ctx) {
1918
throw new Error('Websockets context is not implemented yet');
2019
}
2120
else if (ctx.getType() === 'graphql') {
21+
// inline require here, since we don't want to require the graphql module in the pacakge.
22+
const { GqlExecutionContext } = require('@nestjs/graphql');
2223
// do something that is only important in the context of GraphQL requests
23-
const gqlExecutionContext = graphql_1.GqlExecutionContext.create(ctx);
24+
const gqlExecutionContext = GqlExecutionContext.create(ctx);
2425
return gqlExecutionContext.getContext().req.user;
2526
}
2627
throw new Error('Invalid context');

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
"devDependencies": {
2929
"@nestjs/common": "^7.6.18",
3030
"@nestjs/core": "^7.6.18",
31-
"@nestjs/graphql": "^9.1.2",
3231
"@nestjs/testing": "^7.6.18",
3332
"@types/jest": "^27.0.0",
3433
"@types/node": "^10.1.2",
3534
"coveralls": "^3.0.1",
36-
"graphql": "15.0.0",
3735
"gulp": "^4.0.0",
3836
"gulp-sequence": "^1.0.0",
3937
"gulp-typescript": "^5.0.1",
@@ -53,6 +51,10 @@
5351
"accesscontrol": "^2.2.1"
5452
},
5553
"peerDependencies": {
56-
"@nestjs/graphql": "^9.1.2"
54+
"graphql": "15.0.0",
55+
"@apollo/gateway": "^0.45.1",
56+
"@nestjs/graphql": "^7.6.18",
57+
"apollo-server-core": "^3.6.1",
58+
"ts-morph": "^13.0.2"
5759
}
5860
}

src/decorators/user-roles.decorators.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2-
import { GqlContextType, GqlExecutionContext } from '@nestjs/graphql';
32
import { Role } from '..';
43

54
function userFactory<T>(ctx: ExecutionContext): T {
@@ -14,7 +13,9 @@ function userFactory<T>(ctx: ExecutionContext): T {
1413
} else if (contextType === 'ws') {
1514
// do something that is only important in the context of Websockets requests
1615
throw new Error('Websockets context is not implemented yet');
17-
} else if (ctx.getType<GqlContextType>() === 'graphql') {
16+
} else if (contextType === 'graphql') {
17+
// inline require here, since we don't want to require the graphql module in the pacakge.
18+
const { GqlExecutionContext } = require('@nestjs/graphql');
1819
// do something that is only important in the context of GraphQL requests
1920
const gqlExecutionContext = GqlExecutionContext.create(ctx);
2021
return gqlExecutionContext.getContext().req.user;

0 commit comments

Comments
 (0)