forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example(@nestjs) update examples - auth, graphql
- Loading branch information
1 parent
36b94b3
commit deffcdc
Showing
15 changed files
with
3,551 additions
and
2,541 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
sample/12-graphql-apollo/src/common/scalars/date.scalar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
sample/12-graphql-apollo/src/subscriptions/subscription.constants.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
sample/12-graphql-apollo/src/subscriptions/subscription.providers.ts
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
sample/12-graphql-apollo/src/subscriptions/subscriptions.module.ts
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
sample/12-graphql-apollo/src/subscriptions/subscriptions.service.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.