장재혁

Merge branch 'nest-graphql' into 'master'

Add Nest graphql settings

Add Nest graphql settings for inital testing

See merge request !1
node_modules
.history
\ No newline at end of file
......
......@@ -2,6 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
......@@ -20,5 +21,6 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
};
......
......@@ -23,10 +23,19 @@
"dependencies": {
"@nestjs/common": "^7.6.15",
"@nestjs/core": "^7.6.15",
"@nestjs/graphql": "^7.10.3",
"@nestjs/platform-express": "^7.6.15",
"@nestjs/typeorm": "^7.1.5",
"apollo-server-express": "^2.23.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"graphql": "^15.5.0",
"graphql-tools": "^7.0.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.6"
"rxjs": "^6.6.6",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.32"
},
"devDependencies": {
"@nestjs/cli": "^7.6.0",
......
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { TypeOrmModule } from '@nestjs/typeorm';
import { join } from 'path';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MypageModule } from './mypage/mypage.module';
@Module({
imports: [],
imports: [
GraphQLModule.forRoot({
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
sortSchema: true,
}),
TypeOrmModule.forRoot({
type: 'sqlite',
database: ':memory:',
entities: ['dist/**/*.entity{.ts,.js}'],
synchronize: true,
}),
MypageModule,
],
controllers: [AppController],
providers: [AppService],
})
......
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
bootstrap();
......
import { Field, InputType } from '@nestjs/graphql';
import { IsAlpha } from 'class-validator';
import { Entity } from 'typeorm';
@Entity()
@InputType()
export class CreateMyInput {
@IsAlpha()
@Field()
name: string;
@Field({ nullable: true })
type?: string;
}
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ObjectType, Field, Int } from '@nestjs/graphql';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
@ObjectType()
export class MyPage {
@PrimaryGeneratedColumn()
@Field((type) => Int)
id: number;
@Column()
@Field()
name: string;
@Column({ nullable: true })
@Field({ nullable: true })
type?: string;
}
import { Module } from '@nestjs/common';
import { MypageService } from './mypage.service';
import { MypageResolver } from './mypage.resolver';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MyPage } from './mypage.entity';
@Module({
imports: [TypeOrmModule.forFeature([MyPage])],
providers: [MypageService, MypageResolver],
})
export class MypageModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { MypageResolver } from './mypage.resolver';
describe('MypageResolver', () => {
let resolver: MypageResolver;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MypageResolver],
}).compile();
resolver = module.get<MypageResolver>(MypageResolver);
});
it('should be defined', () => {
expect(resolver).toBeDefined();
});
});
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import { MypageService } from './mypage.service';
import { MyPage } from './mypage.entity';
import { CreateMyInput } from './dto/create-mypage.input';
@Resolver((of) => MyPage)
export class MypageResolver {
constructor(private myPageService: MypageService) {}
@Query((returns) => [MyPage])
myPage(): Promise<MyPage[]> {
return this.myPageService.findAll();
}
@Mutation((returns) => MyPage)
createMyPage(
@Args('createMyInput') createMyPage: CreateMyInput,
): Promise<MyPage> {
return this.myPageService.createMy(createMyPage);
}
}
import { Test, TestingModule } from '@nestjs/testing';
import { MypageService } from './mypage.service';
describe('MypageService', () => {
let service: MypageService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MypageService],
}).compile();
service = module.get<MypageService>(MypageService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateMyInput } from './dto/create-mypage.input';
import { MyPage } from './mypage.entity';
@Injectable()
export class MypageService {
constructor(
@InjectRepository(MyPage) private myPageRepository: Repository<MyPage>,
) {}
async createMy(createMyInput: CreateMyInput): Promise<MyPage> {
const newPage = this.myPageRepository.create(createMyInput);
return this.myPageRepository.save(newPage);
}
async findAll(): Promise<MyPage[]> {
return this.myPageRepository.find();
}
}
# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------
input CreateMyInput {
name: String!
type: String
}
type Mutation {
createMyPage(createMyInput: CreateMyInput!): MyPage!
}
type MyPage {
id: Int!
name: String!
type: String
}
type Query {
myPage: [MyPage!]!
}
This diff could not be displayed because it is too large.