Skip to content

Commit bbadef0

Browse files
committed
fix: update dependencies for NestJs 8 compatibility
1 parent dd75b81 commit bbadef0

File tree

8 files changed

+3246
-4959
lines changed

8 files changed

+3246
-4959
lines changed

example/__tests__/app.e2e-spec.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Test, TestingModule } from "@nestjs/testing";
22
import { INestApplication } from "@nestjs/common";
33
import { GraphQLModule } from "@nestjs/graphql";
4-
import { createTestClient } from "apollo-server-testing";
54
import gql from "graphql-tag";
65
import { AppModule } from "./../src/app.module";
7-
import { Factory } from 'typeorm-factory'
6+
import { Factory } from "typeorm-factory";
87
import { Account } from "../src/account/account.entity";
98

109
describe("AppModule", () => {
1110
let app: INestApplication;
12-
let apolloClient: ReturnType<typeof createTestClient>;
11+
let server: GraphQLModule["apolloServer"];
1312

1413
beforeAll(async () => {
1514
const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -19,22 +18,20 @@ describe("AppModule", () => {
1918
app = moduleFixture.createNestApplication();
2019
await app.init();
2120

22-
const module: GraphQLModule = moduleFixture.get<GraphQLModule>(
23-
GraphQLModule
24-
);
25-
// apolloServer is protected, we need to cast module to any to get it
26-
apolloClient = createTestClient((module as any).apolloServer);
21+
const module: GraphQLModule =
22+
moduleFixture.get<GraphQLModule>(GraphQLModule);
23+
24+
server = module.apolloServer;
2725
});
2826

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

3129
it("defined", () => expect(app).toBeDefined());
3230

3331
it("/graphql(POST) getAccounts", async () => {
34-
const f = new Factory(Account).attr('name', 'name')
35-
const account = await f.create()
36-
const { query } = apolloClient;
37-
const result = await query({
32+
const f = new Factory(Account).attr("name", "name");
33+
const account = await f.create();
34+
const result = await server.executeOperation({
3835
query: gql`
3936
query q($ids: [ID!]!) {
4037
getAccounts(ids: $ids) {
@@ -46,6 +43,6 @@ describe("AppModule", () => {
4643
ids: [account.id],
4744
},
4845
});
49-
expect(result.errors).toBeUndefined()
46+
expect(result.errors).toBeUndefined();
5047
});
5148
});

example/src/account/account.loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DataLoader = require("dataloader");
1+
import DataLoader from "dataloader";
22
import { Injectable } from "@nestjs/common";
33
import { NestDataLoader } from "../../..";
44
import { AccountService } from "./account.service";

example/src/account/account.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class AccountResolver {
99
@Query(() => [Account])
1010
public getAccounts(
1111
@Args({ name: "ids", type: () => [ID] }) ids: string[],
12-
@Loader(AccountLoader.name)
12+
@Loader(AccountLoader)
1313
accountLoader: DataLoader<Account["id"], Account>
1414
): Promise<(Account | Error)[]> {
1515
return accountLoader.loadMany(ids);

example/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"experimentalDecorators": true,
88
"target": "es6",
99
"sourceMap": true,
10-
"outDir": "./dist"
10+
"outDir": "./dist",
11+
"skipLibCheck": true
1112
},
1213
"include": ["src"],
1314
"exclude": ["node_modules", "*.spec.ts"]

index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import {
88
} from '@nestjs/common';
99
import { APP_INTERCEPTOR, ModuleRef, ContextIdFactory } from '@nestjs/core';
1010
import { GqlExecutionContext } from '@nestjs/graphql';
11-
import * as DataLoader from 'dataloader';
12-
import { Observable } from 'rxjs';
13-
import { idText } from 'typescript';
11+
import DataLoader from "dataloader";
1412

1513
/**
16-
* This interface will be used to generate the initial data loader.      
14+
* This interface will be used to generate the initial data loader.      
1715
* The concrete implementation should be added as a provider to your module.
1816
*/
1917
export interface NestDataLoader<ID, Type> {
@@ -48,8 +46,8 @@ export class DataLoaderInterceptor implements NestInterceptor {
4846
contextId: ContextIdFactory.create(),
4947
getLoader: (type: string) : Promise<NestDataLoader<any, any>> => {
5048
if (ctx[type] === undefined) {
51-
try {
52-
ctx[type] = (async () => {
49+
try {
50+
ctx[type] = (async () => {
5351
return (await this.moduleRef.resolve<NestDataLoader<any, any>>(type, ctx[NEST_LOADER_CONTEXT_KEY].contextId, { strict: false }))
5452
.generateDataLoader();
5553
})();

package.json

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,37 @@
2020
"graphql"
2121
],
2222
"peerDependencies": {
23-
"@nestjs/common": "^7.0.0",
24-
"@nestjs/core": "^7.0.0",
25-
"@nestjs/graphql": "^7.0.0",
26-
"graphql": "^14.1.1",
23+
"@apollo/gateway": "^0.41.0",
24+
"@nestjs/common": "^8.0.6",
25+
"@nestjs/core": "^8.0.6",
26+
"@nestjs/graphql": "^9.0.4",
27+
"graphql": "^15.5.3",
2728
"reflect-metadata": "^0.1.12"
2829
},
2930
"dependencies": {
30-
"dataloader": "^2.0.0",
31-
"rxjs": "^6.5.4"
31+
"dataloader": "^2.0.0"
3232
},
3333
"devDependencies": {
34-
"@nestjs/cli": "^7.1.2",
35-
"@nestjs/common": "^7.0.5",
36-
"@nestjs/core": "^7.0.5",
37-
"@nestjs/graphql": "^7.0.15",
38-
"@nestjs/platform-express": "^7.0.7",
39-
"@nestjs/testing": "^7.0.7",
40-
"@nestjs/typeorm": "^7.0.0",
41-
"@types/jest": "^25.2.1",
42-
"apollo-server-express": "^2.9.16",
43-
"apollo-server-testing": "^2.11.0",
44-
"graphql": "^14.1.1",
45-
"jest": "^25.2.7",
34+
"@apollo/gateway": "^0.41.0",
35+
"@nestjs/cli": "^8.1.1",
36+
"@nestjs/common": "^8.0.6",
37+
"@nestjs/core": "^8.0.6",
38+
"@nestjs/graphql": "^9.0.4",
39+
"@nestjs/platform-express": "^8.0.6",
40+
"@nestjs/testing": "^8.0.6",
41+
"@nestjs/typeorm": "^8.0.2",
42+
"@types/jest": "^27.0.1",
43+
"apollo-server-express": "^3.3.0",
44+
"graphql": "^15.5.3",
45+
"jest": "^27.2.0",
4646
"reflect-metadata": "^0.1.12",
47-
"sqlite3": "^4.1.1",
48-
"ts-jest": "^25.3.1",
47+
"rxjs": "^7.3.0",
48+
"sqlite3": "^5.0.2",
49+
"ts-jest": "^27.0.5",
50+
"ts-morph": "^12.0.0",
4951
"typeorm": "^0.2.24",
5052
"typeorm-factory": "^0.0.14",
51-
"typescript": "^3.7.4"
53+
"typescript": "^4.4.3"
5254
},
5355
"types": "index.d.ts",
5456
"jest": {

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"outDir": "./dist",
1111
"baseUrl": "./",
1212
"esModuleInterop": true,
13+
"noUnusedLocals": true
1314
},
1415
"exclude": ["node_modules", "dist", "example"]
1516
}

0 commit comments

Comments
 (0)