Skip to content

Commit deffcdc

Browse files
example(@nestjs) update examples - auth, graphql
1 parent 36b94b3 commit deffcdc

15 files changed

Lines changed: 3551 additions & 2541 deletions

sample/11-swagger/package-lock.json

Lines changed: 822 additions & 816 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/11-swagger/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
"start:prod": "node dist/main.js",
1010
"test": "jest --config=jest.json",
1111
"test:watch": "jest --watch --config=jest.json",
12-
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
12+
"test:coverage":
13+
"jest --config=jest.json --coverage --coverageDirectory=coverage",
1314
"e2e": "jest --config=e2e/jest-e2e.json --forceExit",
1415
"e2e:watch": "jest --watch --config=e2e/jest-e2e.json"
1516
},
1617
"dependencies": {
1718
"@nestjs/common": "^5.1.0",
1819
"@nestjs/core": "^5.1.0",
1920
"@nestjs/microservices": "^5.1.0",
20-
"@nestjs/swagger": "^2.0.0",
21+
"@nestjs/swagger": "^2.4.2",
2122
"@nestjs/testing": "^5.1.0",
2223
"@nestjs/websockets": "^5.1.0",
2324
"class-transformer": "^0.1.7",

sample/12-graphql-apollo/package-lock.json

Lines changed: 1767 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/12-graphql-apollo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"dependencies": {
1212
"@nestjs/common": "^5.1.0",
1313
"@nestjs/core": "^5.1.0",
14-
"@nestjs/graphql": "^3.0.0",
15-
"apollo-server-express": "^1.2.0",
16-
"graphql": "^0.11.7",
14+
"@nestjs/graphql": "^5.0.0",
15+
"apollo-server-express": "^2.0.4",
16+
"graphql": "^0.13.2",
1717
"graphql-subscriptions": "^0.5.6",
1818
"graphql-tools": "^2.11.0",
1919
"reflect-metadata": "^0.1.12",
Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
1-
import {
2-
Module,
3-
MiddlewareConsumer,
4-
NestModule,
5-
RequestMethod,
6-
} from '@nestjs/common';
7-
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
8-
import { GraphQLModule, GraphQLFactory } from '@nestjs/graphql';
9-
1+
import { Module } from '@nestjs/common';
2+
import { GraphQLModule } from '@nestjs/graphql';
103
import { CatsModule } from './cats/cats.module';
11-
import { SubscriptionsModule } from './subscriptions/subscriptions.module';
12-
import { SubscriptionsService } from './subscriptions/subscriptions.service';
134

145
@Module({
15-
imports: [SubscriptionsModule.forRoot(), CatsModule, GraphQLModule],
6+
imports: [
7+
CatsModule,
8+
GraphQLModule.forRoot({
9+
typePaths: ['./**/*.graphql'],
10+
}),
11+
],
1612
})
17-
export class ApplicationModule implements NestModule {
18-
constructor(
19-
private readonly subscriptionsService: SubscriptionsService,
20-
private readonly graphQLFactory: GraphQLFactory,
21-
) {}
22-
23-
configure(consumer: MiddlewareConsumer) {
24-
const schema = this.createSchema();
25-
this.subscriptionsService.createSubscriptionServer(schema);
26-
27-
consumer
28-
.apply(
29-
graphiqlExpress({
30-
endpointURL: '/graphql',
31-
subscriptionsEndpoint: `ws://localhost:3001/subscriptions`,
32-
}),
33-
)
34-
.forRoutes('/graphiql')
35-
.apply(graphqlExpress(req => ({ schema, rootValue: req })))
36-
.forRoutes('/graphql');
37-
}
38-
39-
createSchema() {
40-
const typeDefs = this.graphQLFactory.mergeTypesByPaths('./**/*.graphql');
41-
return this.graphQLFactory.createSchema({ typeDefs });
42-
}
43-
}
13+
export class ApplicationModule {}

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import { Injectable, UseGuards } from '@nestjs/common';
2-
import {
3-
Query,
4-
Mutation,
5-
Resolver,
6-
DelegateProperty,
7-
Subscription,
8-
} from '@nestjs/graphql';
1+
import { UseGuards } from '@nestjs/common';
2+
import { Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
93
import { PubSub } from 'graphql-subscriptions';
10-
11-
import { Cat } from './interfaces/cat.interface';
12-
import { CatsService } from './cats.service';
134
import { CatsGuard } from './cats.guard';
5+
import { CatsService } from './cats.service';
6+
import { Cat } from './interfaces/cat.interface';
147

158
const pubSub = new PubSub();
169

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Scalar } from '@nestjs/graphql/dist/decorators/resolvers.decorators';
2+
import { Kind } from 'graphql';
3+
4+
@Scalar('Date')
5+
export class DateScalar {
6+
description = 'Date custom scalar type';
7+
8+
parseValue(value) {
9+
return new Date(value); // value from the client
10+
}
11+
12+
serialize(value) {
13+
return value.getTime(); // value sent to the client
14+
}
15+
16+
parseLiteral(ast) {
17+
if (ast.kind === Kind.INT) {
18+
return parseInt(ast.value, 10); // ast value is always in string format
19+
}
20+
return null;
21+
}
22+
}

sample/12-graphql-apollo/src/subscriptions/subscription.constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

sample/12-graphql-apollo/src/subscriptions/subscription.providers.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

sample/12-graphql-apollo/src/subscriptions/subscriptions.module.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)