Skip to content

Commit

Permalink
refactor(api): api graphql code-first approach
Browse files Browse the repository at this point in the history
### Description

- Remove `websocket`/`geteway` support
- Add `workspace:@chess-api` package
  • Loading branch information
Neosoulink committed Nov 4, 2024
1 parent 2948e91 commit 6075df7
Show file tree
Hide file tree
Showing 11 changed files with 1,328 additions and 1,374 deletions.
21 changes: 14 additions & 7 deletions apps/api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"plugins": ["@nestjs/graphql"]
}
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"plugins": [
{
"name": "@nestjs/graphql",
"options": {
"introspectComments": true
}
}
]
}
}
10 changes: 5 additions & 5 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
"@nestjs/core": "^10.4.1",
"@nestjs/graphql": "^12.2.0",
"@nestjs/platform-express": "^10.3.10",
"@nestjs/platform-ws": "^10.4.4",
"@nestjs/websockets": "^10.3.10",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"graphql": "^16.9.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"ws": "^8.18.0"
"ts-morph": "^24.0.0"
},
"devDependencies": {
"@chess-d/configs": "workspace:*",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.1.2",
"@nestjs/testing": "^10.4.4",
"@types/ws": "^8.5.12",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"tsconfig-paths": "^4.2.0"
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3"
}
}
43 changes: 37 additions & 6 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { Module } from "@nestjs/common";
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
import { join } from "path";
import { APP_PIPE } from "@nestjs/core";
import { Module, ValidationPipe } from "@nestjs/common";
import { DirectiveLocation, GraphQLDirective } from "graphql";
import { GraphQLModule } from "@nestjs/graphql";
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
import {
ApolloComplexityPlugin,
ApolloLoggingPlugin,
DateScalar,
upperDirectiveTransformer
} from "@chess-d/api";

import { ExperienceModule } from "./experience/experience.module";

Expand All @@ -12,11 +20,34 @@ import { ExperienceModule } from "./experience/experience.module";
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), "src/schema.gql"),
playground: false,
plugins: [ApolloServerPluginLandingPageLocalDefault()]
plugins: [ApolloServerPluginLandingPageLocalDefault()],
transformSchema: (schema) => upperDirectiveTransformer(schema, "upper"),
buildSchemaOptions: {
directives: [
new GraphQLDirective({
name: "upper",
locations: [DirectiveLocation.FIELD_DEFINITION]
})
]
}
}),
ExperienceModule
],
controllers: [],
providers: []
providers: [
{
provide: APP_PIPE,
useValue: new ValidationPipe({
transform: true,
forbidNonWhitelisted: true,
forbidUnknownValues: true,
transformOptions: {
enableImplicitConversion: true
}
})
},
DateScalar,
ApolloLoggingPlugin,
ApolloComplexityPlugin
]
})
export class AppModule {}
3 changes: 1 addition & 2 deletions apps/api/src/experience/experience.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Module } from "@nestjs/common";

import { ExperienceService } from "./services/experience.service";
import { ExperienceResolver } from "./resolvers/experience.resolver";
import { ExperienceGateway } from "./gateways/experience.gateway";

@Module({
providers: [ExperienceResolver, ExperienceService, ExperienceGateway]
providers: [ExperienceResolver, ExperienceService]
})
export class ExperienceModule {}
18 changes: 0 additions & 18 deletions apps/api/src/experience/gateways/experience.gateway.spec.ts

This file was deleted.

38 changes: 0 additions & 38 deletions apps/api/src/experience/gateways/experience.gateway.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { WsAdapter } from "@nestjs/platform-ws";

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useWebSocketAdapter(new WsAdapter(app));
await app.listen(3000);

console.log(`Running on: ${await app.getUrl()}`);
}
bootstrap();
5 changes: 5 additions & 0 deletions apps/api/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

directive @upper on FIELD_DEFINITION

"""Date custom scalar type"""
scalar Date

type Query {
log: String!
}
4 changes: 2 additions & 2 deletions apps/api/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
12 changes: 6 additions & 6 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "@chess-d/configs/typescript/nestjs.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist"
},
"exclude": ["*.config.cjs", "*.config.js", "*.config.ts"]
"extends": "@chess-d/configs/typescript/nestjs.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist"
},
"exclude": ["*.config.cjs", "*.config.js", "*.config.ts"]
}
Loading

0 comments on commit 6075df7

Please sign in to comment.