Skip to content

Commit

Permalink
example(@nestjs) update examples - auth, graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Aug 22, 2018
1 parent 36b94b3 commit deffcdc
Show file tree
Hide file tree
Showing 15 changed files with 3,551 additions and 2,541 deletions.
1,638 changes: 822 additions & 816 deletions sample/11-swagger/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions sample/11-swagger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
"start:prod": "node dist/main.js",
"test": "jest --config=jest.json",
"test:watch": "jest --watch --config=jest.json",
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
"test:coverage":
"jest --config=jest.json --coverage --coverageDirectory=coverage",
"e2e": "jest --config=e2e/jest-e2e.json --forceExit",
"e2e:watch": "jest --watch --config=e2e/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"@nestjs/microservices": "^5.1.0",
"@nestjs/swagger": "^2.0.0",
"@nestjs/swagger": "^2.4.2",
"@nestjs/testing": "^5.1.0",
"@nestjs/websockets": "^5.1.0",
"class-transformer": "^0.1.7",
Expand Down
1,850 changes: 1,767 additions & 83 deletions sample/12-graphql-apollo/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sample/12-graphql-apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"@nestjs/graphql": "^3.0.0",
"apollo-server-express": "^1.2.0",
"graphql": "^0.11.7",
"@nestjs/graphql": "^5.0.0",
"apollo-server-express": "^2.0.4",
"graphql": "^0.13.2",
"graphql-subscriptions": "^0.5.6",
"graphql-tools": "^2.11.0",
"reflect-metadata": "^0.1.12",
Expand Down
48 changes: 9 additions & 39 deletions sample/12-graphql-apollo/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
import {
Module,
MiddlewareConsumer,
NestModule,
RequestMethod,
} from '@nestjs/common';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import { GraphQLModule, GraphQLFactory } from '@nestjs/graphql';

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { CatsModule } from './cats/cats.module';
import { SubscriptionsModule } from './subscriptions/subscriptions.module';
import { SubscriptionsService } from './subscriptions/subscriptions.service';

@Module({
imports: [SubscriptionsModule.forRoot(), CatsModule, GraphQLModule],
imports: [
CatsModule,
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
}),
],
})
export class ApplicationModule implements NestModule {
constructor(
private readonly subscriptionsService: SubscriptionsService,
private readonly graphQLFactory: GraphQLFactory,
) {}

configure(consumer: MiddlewareConsumer) {
const schema = this.createSchema();
this.subscriptionsService.createSubscriptionServer(schema);

consumer
.apply(
graphiqlExpress({
endpointURL: '/graphql',
subscriptionsEndpoint: `ws://localhost:3001/subscriptions`,
}),
)
.forRoutes('/graphiql')
.apply(graphqlExpress(req => ({ schema, rootValue: req })))
.forRoutes('/graphql');
}

createSchema() {
const typeDefs = this.graphQLFactory.mergeTypesByPaths('./**/*.graphql');
return this.graphQLFactory.createSchema({ typeDefs });
}
}
export class ApplicationModule {}
15 changes: 4 additions & 11 deletions sample/12-graphql-apollo/src/cats/cats.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { Injectable, UseGuards } from '@nestjs/common';
import {
Query,
Mutation,
Resolver,
DelegateProperty,
Subscription,
} from '@nestjs/graphql';
import { UseGuards } from '@nestjs/common';
import { Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
import { PubSub } from 'graphql-subscriptions';

import { Cat } from './interfaces/cat.interface';
import { CatsService } from './cats.service';
import { CatsGuard } from './cats.guard';
import { CatsService } from './cats.service';
import { Cat } from './interfaces/cat.interface';

const pubSub = new PubSub();

Expand Down
22 changes: 22 additions & 0 deletions sample/12-graphql-apollo/src/common/scalars/date.scalar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Scalar } from '@nestjs/graphql/dist/decorators/resolvers.decorators';
import { Kind } from 'graphql';

@Scalar('Date')
export class DateScalar {
description = 'Date custom scalar type';

parseValue(value) {
return new Date(value); // value from the client
}

serialize(value) {
return value.getTime(); // value sent to the client
}

parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10); // ast value is always in string format
}
return null;
}
}

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions sample/12-graphql-apollo/src/subscriptions/subscriptions.module.ts

This file was deleted.

This file was deleted.

Loading

0 comments on commit deffcdc

Please sign in to comment.