Skip to content

Commit 466dc84

Browse files
Merge pull request nestjs#342 from leokraken/fix/graphqlexample
[Fix] Graphql example
2 parents 3bb2e24 + 5caef83 commit 466dc84

3 files changed

Lines changed: 8 additions & 25 deletions

File tree

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,13 @@ export class CatsResolvers {
1717
}
1818

1919
@Query('cat')
20-
async findOneById(id: number) {
21-
return await this.catsService.findOneById(id);
20+
async findOneById(obj, args, context, info): Promise<Cat> {
21+
const { id } = args;
22+
return await this.catsService.findOneById(+id);
2223
}
2324

2425
@Mutation('createCat')
25-
async create(cat: Cat) {
26-
await this.catsService.create(cat);
27-
}
28-
29-
@DelegateProperty('human')
30-
findHumansById() {
31-
return (mergeInfo: MergeInfo) => ({
32-
fragment: `fragment CatFragment on Cat { humanId }`,
33-
resolve(parent, args, context, info) {
34-
const humanId = parent.id;
35-
return mergeInfo.delegate(
36-
'query',
37-
'humanById',
38-
{
39-
id: humanId,
40-
},
41-
context,
42-
info,
43-
);
44-
},
45-
});
26+
async create(obj, args: Cat, context, info): Promise<Cat> {
27+
return await this.catsService.create(args);
4628
}
4729
}

examples/12-graphql-apollo/src/cats/cats.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { Cat } from './interfaces/cat.interface';
55
export class CatsService {
66
private readonly cats: Cat[] = [{ id: 1, name: 'Cat', age: 5 }];
77

8-
create(cat: Cat) {
8+
create(cat: Cat): Cat{
99
this.cats.push(cat);
10+
return cat;
1011
}
1112

1213
findAll(): Cat[] {

examples/12-graphql-apollo/src/cats/cats.types.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ type Cat {
1313
name: String
1414
age: Int
1515
humanId: Int
16-
}
16+
}

0 commit comments

Comments
 (0)