장재혁

Add graphql typegen

import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'
import { TypeOrmModule } from '@nestjs/typeorm'
import { join } from 'path'
import * as path from 'path'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { MypageModule } from './mypage/mypage.module'
......@@ -13,7 +13,10 @@ import { LikeableModule } from './likeable/likeable.module'
@Module({
imports: [
GraphQLModule.forRoot({
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
autoSchemaFile: path.join(
__dirname,
'../../shared/src/graphql/api/api.graphql',
),
sortSchema: true,
}),
TypeOrmModule.forRoot({
......
overwrite: true
require:
- ts-node/register
generates:
./types/api-generated-types.ts:
schema: "src/graphql/api/api.graphql"
# documents: "src/graphql/api/**/*.graphql"
plugins:
- "typescript"
# - 'fragment-matcher'
- "typescript-operations"
- "typescript-react-apollo"
config:
namingConvention: keep
export * from "./types/api-generated-types";
......@@ -4,10 +4,19 @@
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
"start": "next start",
"typegen" : "graphql-codegen --config codegen.yml"
},
"dependencies": {
"lodash": "4.17.20"
"lodash": "4.17.20",
"typescript": "^4.2.4"
},
"license": "MIT"
"license": "MIT",
"devDependencies": {
"@graphql-codegen/cli": "^1.21.5",
"@graphql-codegen/fragment-matcher": "^2.0.1",
"@graphql-codegen/typescript": "^1.22.1",
"@graphql-codegen/typescript-operations": "^1.18.0",
"@graphql-codegen/typescript-react-apollo": "^2.2.5"
}
}
......
# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------
type Comment {
author: String!
content: String!
created_date: String!
id: Int!
parent: Int!
post_id: Int!
updated_date: String
}
input CreateCommentInput {
content: String!
parent: Float
post_id: Int!
}
input CreateLikeableInput {
like_dislike: Int!
likeable_id: Int!
likeable_type: String!
}
input CreateMyInput {
name: String!
type: String
}
input CreatePostInput {
category: String!
content: String!
title: String!
}
input GetCommentInput {
author: String
parent: String
post_id: Float
}
input GetLikeableInput {
likeable_id: Float
likeable_type: String!
user_id: String
}
input GetPostInput {
author: String
category: String
id: Float
}
type Likeable {
created_date: String!
id: Int!
like_dislike: Int!
likeable_id: Int!
likeable_type: String!
user_id: String!
}
type Mutation {
createComment(input: CreateCommentInput!): Comment!
createLikeable(input: CreateLikeableInput!): Likeable!
createMyPage(createMyInput: CreateMyInput!): MyPage!
createPost(input: CreatePostInput!): Post!
}
type MyPage {
id: Int!
name: String!
type: String
}
type Post {
author: String!
category: String!
content: String!
created_date: String!
id: Int!
title: String!
updated_date: String
}
type Query {
getAllComments: [Comment!]!
getAllLikes: [Likeable!]!
getAllPosts: [Post!]!
getComment(id: Float!): Comment!
getLikeable(id: Float!): Likeable!
getPost(id: Float!): Post!
getSomeComments(input: GetCommentInput!): [Comment!]!
getSomePosts(input: GetPostInput!): [Post!]!
getTotalLikes(input: GetLikeableInput!): Float!
myPage: [MyPage!]!
}
import { gql } from '@apollo/client';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
};
export type Comment = {
__typename?: 'Comment';
author: Scalars['String'];
content: Scalars['String'];
created_date: Scalars['String'];
id: Scalars['Int'];
parent: Scalars['Int'];
post_id: Scalars['Int'];
updated_date?: Maybe<Scalars['String']>;
};
export type CreateCommentInput = {
content: Scalars['String'];
parent?: Maybe<Scalars['Float']>;
post_id: Scalars['Int'];
};
export type CreateLikeableInput = {
like_dislike: Scalars['Int'];
likeable_id: Scalars['Int'];
likeable_type: Scalars['String'];
};
export type CreateMyInput = {
name: Scalars['String'];
type?: Maybe<Scalars['String']>;
};
export type CreatePostInput = {
category: Scalars['String'];
content: Scalars['String'];
title: Scalars['String'];
};
export type GetCommentInput = {
author?: Maybe<Scalars['String']>;
parent?: Maybe<Scalars['String']>;
post_id?: Maybe<Scalars['Float']>;
};
export type GetLikeableInput = {
likeable_id?: Maybe<Scalars['Float']>;
likeable_type: Scalars['String'];
user_id?: Maybe<Scalars['String']>;
};
export type GetPostInput = {
author?: Maybe<Scalars['String']>;
category?: Maybe<Scalars['String']>;
id?: Maybe<Scalars['Float']>;
};
export type Likeable = {
__typename?: 'Likeable';
created_date: Scalars['String'];
id: Scalars['Int'];
like_dislike: Scalars['Int'];
likeable_id: Scalars['Int'];
likeable_type: Scalars['String'];
user_id: Scalars['String'];
};
export type Mutation = {
__typename?: 'Mutation';
createComment: Comment;
createLikeable: Likeable;
createMyPage: MyPage;
createPost: Post;
};
export type MutationcreateCommentArgs = {
input: CreateCommentInput;
};
export type MutationcreateLikeableArgs = {
input: CreateLikeableInput;
};
export type MutationcreateMyPageArgs = {
createMyInput: CreateMyInput;
};
export type MutationcreatePostArgs = {
input: CreatePostInput;
};
export type MyPage = {
__typename?: 'MyPage';
id: Scalars['Int'];
name: Scalars['String'];
type?: Maybe<Scalars['String']>;
};
export type Post = {
__typename?: 'Post';
author: Scalars['String'];
category: Scalars['String'];
content: Scalars['String'];
created_date: Scalars['String'];
id: Scalars['Int'];
title: Scalars['String'];
updated_date?: Maybe<Scalars['String']>;
};
export type Query = {
__typename?: 'Query';
getAllComments: Array<Comment>;
getAllLikes: Array<Likeable>;
getAllPosts: Array<Post>;
getComment: Comment;
getLikeable: Likeable;
getPost: Post;
getSomeComments: Array<Comment>;
getSomePosts: Array<Post>;
getTotalLikes: Scalars['Float'];
myPage: Array<MyPage>;
};
export type QuerygetCommentArgs = {
id: Scalars['Float'];
};
export type QuerygetLikeableArgs = {
id: Scalars['Float'];
};
export type QuerygetPostArgs = {
id: Scalars['Float'];
};
export type QuerygetSomeCommentsArgs = {
input: GetCommentInput;
};
export type QuerygetSomePostsArgs = {
input: GetPostInput;
};
export type QuerygetTotalLikesArgs = {
input: GetLikeableInput;
};
This diff is collapsed. Click to expand it.