Skip to content

Commit

Permalink
sample(@nestjs) update graphql and mongoose example
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Mar 29, 2018
1 parent b574bb3 commit 658391f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions packages/core/injector/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,16 @@ export class Module {
): string {
const { provide } = component;
const name = isFunction(provide) ? provide.name : provide;
const comp = {
const componentWithName = {
...component,
name,
};

if (this.isCustomClass(comp)) this.addCustomClass(comp, collection);
else if (this.isCustomValue(comp)) this.addCustomValue(comp, collection);
else if (this.isCustomFactory(comp))
this.addCustomFactory(comp, collection);
if (this.isCustomClass(componentWithName))
this.addCustomClass(componentWithName, collection);
else if (this.isCustomValue(componentWithName))
this.addCustomValue(componentWithName, collection);
else if (this.isCustomFactory(componentWithName))
this.addCustomFactory(componentWithName, collection);

return name;
}
Expand Down
2 changes: 2 additions & 0 deletions sample/06-mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "^5.0.0",
"@nestjs/core": "^5.0.0",
"@nestjs/mongoose": "^3.0.1",
"mongoose": "^5.0.1",
"reflect-metadata": "^0.1.10",
Expand Down
3 changes: 1 addition & 2 deletions sample/06-mongoose/src/cats/cats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Cat } from './interfaces/cat.interface';
import { CreateCatDto } from './dto/create-cat.dto';
import { CatSchema } from './schemas/cat.schema';

@Injectable()
export class CatsService {
constructor(@InjectModel(CatSchema) private readonly catModel: Model<Cat>) {}
constructor(@InjectModel('Cat') private readonly catModel: Model<Cat>) {}

async create(createCatDto: CreateCatDto): Promise<Cat> {
const createdCat = new this.catModel(createCatDto);
Expand Down
6 changes: 3 additions & 3 deletions sample/12-graphql-apollo/src/cats/cats.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Cat } from './interfaces/cat.interface';
import { CatsService } from './cats.service';
import { CatsGuard } from './cats.guard';

const pubsub = new PubSub();
const pubSub = new PubSub();

@Resolver('Cat')
export class CatsResolvers {
Expand All @@ -33,14 +33,14 @@ export class CatsResolvers {
@Mutation('createCat')
async create(obj, args: Cat, context, info): Promise<Cat> {
const createdCat = await this.catsService.create(args);
pubsub.publish('catCreated', { catCreated: createdCat });
pubSub.publish('catCreated', { catCreated: createdCat });
return createdCat;
}

@Subscription('catCreated')
catCreated() {
return {
subscribe: () => pubsub.asyncIterator('catCreated'),
subscribe: () => pubSub.asyncIterator('catCreated'),
};
}
}

0 comments on commit 658391f

Please sign in to comment.