Showing
6 changed files
with
90 additions
and
1 deletions
1 | import { Module } from '@nestjs/common'; | 1 | import { Module } from '@nestjs/common'; |
2 | +import { GraphQLModule } from '@nestjs/graphql'; | ||
3 | +import { TypeOrmModule } from '@nestjs/typeorm'; | ||
4 | +import { join } from 'path'; | ||
2 | import { AppController } from './app.controller'; | 5 | import { AppController } from './app.controller'; |
3 | import { AppService } from './app.service'; | 6 | import { AppService } from './app.service'; |
7 | +import { MypageModule } from './mypage/mypage.module'; | ||
4 | 8 | ||
5 | @Module({ | 9 | @Module({ |
6 | - imports: [], | 10 | + imports: [ |
11 | + GraphQLModule.forRoot({ | ||
12 | + autoSchemaFile: join(process.cwd(), 'src/schema.gql'), | ||
13 | + sortSchema: true, | ||
14 | + }), | ||
15 | + TypeOrmModule.forRoot({ | ||
16 | + type: 'sqlite', | ||
17 | + database: ':memory:', | ||
18 | + entities: ['dist/**/*.entity{.ts,.js}'], | ||
19 | + synchronize: true, | ||
20 | + }), | ||
21 | + MypageModule, | ||
22 | + ], | ||
7 | controllers: [AppController], | 23 | controllers: [AppController], |
8 | providers: [AppService], | 24 | providers: [AppService], |
9 | }) | 25 | }) | ... | ... |
1 | +import { ValidationPipe } from '@nestjs/common'; | ||
1 | import { NestFactory } from '@nestjs/core'; | 2 | import { NestFactory } from '@nestjs/core'; |
2 | import { AppModule } from './app.module'; | 3 | import { AppModule } from './app.module'; |
3 | 4 | ||
4 | async function bootstrap() { | 5 | async function bootstrap() { |
5 | const app = await NestFactory.create(AppModule); | 6 | const app = await NestFactory.create(AppModule); |
7 | + | ||
8 | + app.useGlobalPipes(new ValidationPipe()); | ||
6 | await app.listen(3000); | 9 | await app.listen(3000); |
7 | } | 10 | } |
8 | bootstrap(); | 11 | bootstrap(); | ... | ... |
1 | +/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
2 | +import { ObjectType, Field, Int } from '@nestjs/graphql'; | ||
3 | +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; | ||
4 | + | ||
5 | +@Entity() | ||
6 | +@ObjectType() | ||
7 | +export class MyPage { | ||
8 | + @PrimaryGeneratedColumn() | ||
9 | + @Field((type) => Int) | ||
10 | + id: number; | ||
11 | + | ||
12 | + @Column() | ||
13 | + @Field() | ||
14 | + name: string; | ||
15 | + | ||
16 | + @Column({ nullable: true }) | ||
17 | + @Field({ nullable: true }) | ||
18 | + type?: string; | ||
19 | +} |
1 | +import { Module } from '@nestjs/common'; | ||
2 | +import { MypageService } from './mypage.service'; | ||
3 | +import { MypageResolver } from './mypage.resolver'; | ||
4 | +import { TypeOrmModule } from '@nestjs/typeorm'; | ||
5 | +import { MyPage } from './mypage.entity'; | ||
6 | + | ||
7 | +@Module({ | ||
8 | + imports: [TypeOrmModule.forFeature([MyPage])], | ||
9 | + providers: [MypageService, MypageResolver], | ||
10 | +}) | ||
11 | +export class MypageModule {} |
1 | +import { Test, TestingModule } from '@nestjs/testing'; | ||
2 | +import { MypageResolver } from './mypage.resolver'; | ||
3 | + | ||
4 | +describe('MypageResolver', () => { | ||
5 | + let resolver: MypageResolver; | ||
6 | + | ||
7 | + beforeEach(async () => { | ||
8 | + const module: TestingModule = await Test.createTestingModule({ | ||
9 | + providers: [MypageResolver], | ||
10 | + }).compile(); | ||
11 | + | ||
12 | + resolver = module.get<MypageResolver>(MypageResolver); | ||
13 | + }); | ||
14 | + | ||
15 | + it('should be defined', () => { | ||
16 | + expect(resolver).toBeDefined(); | ||
17 | + }); | ||
18 | +}); |
project/packages/api/src/schema.gql
0 → 100644
1 | +# ------------------------------------------------------ | ||
2 | +# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) | ||
3 | +# ------------------------------------------------------ | ||
4 | + | ||
5 | +input CreateMyInput { | ||
6 | + name: String! | ||
7 | + type: String | ||
8 | +} | ||
9 | + | ||
10 | +type Mutation { | ||
11 | + createMyPage(createMyInput: CreateMyInput!): MyPage! | ||
12 | +} | ||
13 | + | ||
14 | +type MyPage { | ||
15 | + id: Int! | ||
16 | + name: String! | ||
17 | + type: String | ||
18 | +} | ||
19 | + | ||
20 | +type Query { | ||
21 | + myPage: [MyPage!]! | ||
22 | +} |
-
Please register or login to post a comment