Skip to content

Commit 658391f

Browse files
sample(@nestjs) update graphql and mongoose example
1 parent b574bb3 commit 658391f

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

packages/core/injector/module.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,16 @@ export class Module {
200200
): string {
201201
const { provide } = component;
202202
const name = isFunction(provide) ? provide.name : provide;
203-
const comp = {
203+
const componentWithName = {
204204
...component,
205205
name,
206206
};
207-
208-
if (this.isCustomClass(comp)) this.addCustomClass(comp, collection);
209-
else if (this.isCustomValue(comp)) this.addCustomValue(comp, collection);
210-
else if (this.isCustomFactory(comp))
211-
this.addCustomFactory(comp, collection);
207+
if (this.isCustomClass(componentWithName))
208+
this.addCustomClass(componentWithName, collection);
209+
else if (this.isCustomValue(componentWithName))
210+
this.addCustomValue(componentWithName, collection);
211+
else if (this.isCustomFactory(componentWithName))
212+
this.addCustomFactory(componentWithName, collection);
212213

213214
return name;
214215
}

sample/06-mongoose/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"start:prod": "node dist/main.js"
1010
},
1111
"dependencies": {
12+
"@nestjs/common": "^5.0.0",
13+
"@nestjs/core": "^5.0.0",
1214
"@nestjs/mongoose": "^3.0.1",
1315
"mongoose": "^5.0.1",
1416
"reflect-metadata": "^0.1.10",

sample/06-mongoose/src/cats/cats.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { Injectable } from '@nestjs/common';
33
import { InjectModel } from '@nestjs/mongoose';
44
import { Cat } from './interfaces/cat.interface';
55
import { CreateCatDto } from './dto/create-cat.dto';
6-
import { CatSchema } from './schemas/cat.schema';
76

87
@Injectable()
98
export class CatsService {
10-
constructor(@InjectModel(CatSchema) private readonly catModel: Model<Cat>) {}
9+
constructor(@InjectModel('Cat') private readonly catModel: Model<Cat>) {}
1110

1211
async create(createCatDto: CreateCatDto): Promise<Cat> {
1312
const createdCat = new this.catModel(createCatDto);

sample/12-graphql-apollo/src/cats/cats.resolvers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Cat } from './interfaces/cat.interface';
1212
import { CatsService } from './cats.service';
1313
import { CatsGuard } from './cats.guard';
1414

15-
const pubsub = new PubSub();
15+
const pubSub = new PubSub();
1616

1717
@Resolver('Cat')
1818
export class CatsResolvers {
@@ -33,14 +33,14 @@ export class CatsResolvers {
3333
@Mutation('createCat')
3434
async create(obj, args: Cat, context, info): Promise<Cat> {
3535
const createdCat = await this.catsService.create(args);
36-
pubsub.publish('catCreated', { catCreated: createdCat });
36+
pubSub.publish('catCreated', { catCreated: createdCat });
3737
return createdCat;
3838
}
3939

4040
@Subscription('catCreated')
4141
catCreated() {
4242
return {
43-
subscribe: () => pubsub.asyncIterator('catCreated'),
43+
subscribe: () => pubSub.asyncIterator('catCreated'),
4444
};
4545
}
4646
}

0 commit comments

Comments
 (0)