Showing
7 changed files
with
296 additions
and
5 deletions
1 | import { Module } from '@nestjs/common' | 1 | import { Module } from '@nestjs/common' |
2 | import { GraphQLModule } from '@nestjs/graphql' | 2 | import { GraphQLModule } from '@nestjs/graphql' |
3 | import { TypeOrmModule } from '@nestjs/typeorm' | 3 | import { TypeOrmModule } from '@nestjs/typeorm' |
4 | -import { join } from 'path' | 4 | +import * as path from 'path' |
5 | import { AppController } from './app.controller' | 5 | import { AppController } from './app.controller' |
6 | import { AppService } from './app.service' | 6 | import { AppService } from './app.service' |
7 | import { MypageModule } from './mypage/mypage.module' | 7 | import { MypageModule } from './mypage/mypage.module' |
... | @@ -13,7 +13,10 @@ import { LikeableModule } from './likeable/likeable.module' | ... | @@ -13,7 +13,10 @@ import { LikeableModule } from './likeable/likeable.module' |
13 | @Module({ | 13 | @Module({ |
14 | imports: [ | 14 | imports: [ |
15 | GraphQLModule.forRoot({ | 15 | GraphQLModule.forRoot({ |
16 | - autoSchemaFile: join(process.cwd(), 'src/schema.gql'), | 16 | + autoSchemaFile: path.join( |
17 | + __dirname, | ||
18 | + '../../shared/src/graphql/api/api.graphql', | ||
19 | + ), | ||
17 | sortSchema: true, | 20 | sortSchema: true, |
18 | }), | 21 | }), |
19 | TypeOrmModule.forRoot({ | 22 | TypeOrmModule.forRoot({ | ... | ... |
project/packages/shared/codegen.yml
0 → 100644
1 | +overwrite: true | ||
2 | +require: | ||
3 | + - ts-node/register | ||
4 | +generates: | ||
5 | + ./types/api-generated-types.ts: | ||
6 | + schema: "src/graphql/api/api.graphql" | ||
7 | + # documents: "src/graphql/api/**/*.graphql" | ||
8 | + plugins: | ||
9 | + - "typescript" | ||
10 | + # - 'fragment-matcher' | ||
11 | + - "typescript-operations" | ||
12 | + - "typescript-react-apollo" | ||
13 | + config: | ||
14 | + namingConvention: keep |
project/packages/shared/index.ts
0 → 100644
1 | +export * from "./types/api-generated-types"; |
... | @@ -4,10 +4,19 @@ | ... | @@ -4,10 +4,19 @@ |
4 | "scripts": { | 4 | "scripts": { |
5 | "dev": "next", | 5 | "dev": "next", |
6 | "build": "next build", | 6 | "build": "next build", |
7 | - "start": "next start" | 7 | + "start": "next start", |
8 | + "typegen" : "graphql-codegen --config codegen.yml" | ||
8 | }, | 9 | }, |
9 | "dependencies": { | 10 | "dependencies": { |
10 | - "lodash": "4.17.20" | 11 | + "lodash": "4.17.20", |
12 | + "typescript": "^4.2.4" | ||
11 | }, | 13 | }, |
12 | - "license": "MIT" | 14 | + "license": "MIT", |
15 | + "devDependencies": { | ||
16 | + "@graphql-codegen/cli": "^1.21.5", | ||
17 | + "@graphql-codegen/fragment-matcher": "^2.0.1", | ||
18 | + "@graphql-codegen/typescript": "^1.22.1", | ||
19 | + "@graphql-codegen/typescript-operations": "^1.18.0", | ||
20 | + "@graphql-codegen/typescript-react-apollo": "^2.2.5" | ||
21 | + } | ||
13 | } | 22 | } | ... | ... |
1 | +# ------------------------------------------------------ | ||
2 | +# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) | ||
3 | +# ------------------------------------------------------ | ||
4 | + | ||
5 | +type Comment { | ||
6 | + author: String! | ||
7 | + content: String! | ||
8 | + created_date: String! | ||
9 | + id: Int! | ||
10 | + parent: Int! | ||
11 | + post_id: Int! | ||
12 | + updated_date: String | ||
13 | +} | ||
14 | + | ||
15 | +input CreateCommentInput { | ||
16 | + content: String! | ||
17 | + parent: Float | ||
18 | + post_id: Int! | ||
19 | +} | ||
20 | + | ||
21 | +input CreateLikeableInput { | ||
22 | + like_dislike: Int! | ||
23 | + likeable_id: Int! | ||
24 | + likeable_type: String! | ||
25 | +} | ||
26 | + | ||
27 | +input CreateMyInput { | ||
28 | + name: String! | ||
29 | + type: String | ||
30 | +} | ||
31 | + | ||
32 | +input CreatePostInput { | ||
33 | + category: String! | ||
34 | + content: String! | ||
35 | + title: String! | ||
36 | +} | ||
37 | + | ||
38 | +input GetCommentInput { | ||
39 | + author: String | ||
40 | + parent: String | ||
41 | + post_id: Float | ||
42 | +} | ||
43 | + | ||
44 | +input GetLikeableInput { | ||
45 | + likeable_id: Float | ||
46 | + likeable_type: String! | ||
47 | + user_id: String | ||
48 | +} | ||
49 | + | ||
50 | +input GetPostInput { | ||
51 | + author: String | ||
52 | + category: String | ||
53 | + id: Float | ||
54 | +} | ||
55 | + | ||
56 | +type Likeable { | ||
57 | + created_date: String! | ||
58 | + id: Int! | ||
59 | + like_dislike: Int! | ||
60 | + likeable_id: Int! | ||
61 | + likeable_type: String! | ||
62 | + user_id: String! | ||
63 | +} | ||
64 | + | ||
65 | +type Mutation { | ||
66 | + createComment(input: CreateCommentInput!): Comment! | ||
67 | + createLikeable(input: CreateLikeableInput!): Likeable! | ||
68 | + createMyPage(createMyInput: CreateMyInput!): MyPage! | ||
69 | + createPost(input: CreatePostInput!): Post! | ||
70 | +} | ||
71 | + | ||
72 | +type MyPage { | ||
73 | + id: Int! | ||
74 | + name: String! | ||
75 | + type: String | ||
76 | +} | ||
77 | + | ||
78 | +type Post { | ||
79 | + author: String! | ||
80 | + category: String! | ||
81 | + content: String! | ||
82 | + created_date: String! | ||
83 | + id: Int! | ||
84 | + title: String! | ||
85 | + updated_date: String | ||
86 | +} | ||
87 | + | ||
88 | +type Query { | ||
89 | + getAllComments: [Comment!]! | ||
90 | + getAllLikes: [Likeable!]! | ||
91 | + getAllPosts: [Post!]! | ||
92 | + getComment(id: Float!): Comment! | ||
93 | + getLikeable(id: Float!): Likeable! | ||
94 | + getPost(id: Float!): Post! | ||
95 | + getSomeComments(input: GetCommentInput!): [Comment!]! | ||
96 | + getSomePosts(input: GetPostInput!): [Post!]! | ||
97 | + getTotalLikes(input: GetLikeableInput!): Float! | ||
98 | + myPage: [MyPage!]! | ||
99 | +} |
1 | +import { gql } from '@apollo/client'; | ||
2 | +export type Maybe<T> = T | null; | ||
3 | +export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | ||
4 | +export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> }; | ||
5 | +export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> }; | ||
6 | +/** All built-in and custom scalars, mapped to their actual values */ | ||
7 | +export type Scalars = { | ||
8 | + ID: string; | ||
9 | + String: string; | ||
10 | + Boolean: boolean; | ||
11 | + Int: number; | ||
12 | + Float: number; | ||
13 | +}; | ||
14 | + | ||
15 | +export type Comment = { | ||
16 | + __typename?: 'Comment'; | ||
17 | + author: Scalars['String']; | ||
18 | + content: Scalars['String']; | ||
19 | + created_date: Scalars['String']; | ||
20 | + id: Scalars['Int']; | ||
21 | + parent: Scalars['Int']; | ||
22 | + post_id: Scalars['Int']; | ||
23 | + updated_date?: Maybe<Scalars['String']>; | ||
24 | +}; | ||
25 | + | ||
26 | +export type CreateCommentInput = { | ||
27 | + content: Scalars['String']; | ||
28 | + parent?: Maybe<Scalars['Float']>; | ||
29 | + post_id: Scalars['Int']; | ||
30 | +}; | ||
31 | + | ||
32 | +export type CreateLikeableInput = { | ||
33 | + like_dislike: Scalars['Int']; | ||
34 | + likeable_id: Scalars['Int']; | ||
35 | + likeable_type: Scalars['String']; | ||
36 | +}; | ||
37 | + | ||
38 | +export type CreateMyInput = { | ||
39 | + name: Scalars['String']; | ||
40 | + type?: Maybe<Scalars['String']>; | ||
41 | +}; | ||
42 | + | ||
43 | +export type CreatePostInput = { | ||
44 | + category: Scalars['String']; | ||
45 | + content: Scalars['String']; | ||
46 | + title: Scalars['String']; | ||
47 | +}; | ||
48 | + | ||
49 | +export type GetCommentInput = { | ||
50 | + author?: Maybe<Scalars['String']>; | ||
51 | + parent?: Maybe<Scalars['String']>; | ||
52 | + post_id?: Maybe<Scalars['Float']>; | ||
53 | +}; | ||
54 | + | ||
55 | +export type GetLikeableInput = { | ||
56 | + likeable_id?: Maybe<Scalars['Float']>; | ||
57 | + likeable_type: Scalars['String']; | ||
58 | + user_id?: Maybe<Scalars['String']>; | ||
59 | +}; | ||
60 | + | ||
61 | +export type GetPostInput = { | ||
62 | + author?: Maybe<Scalars['String']>; | ||
63 | + category?: Maybe<Scalars['String']>; | ||
64 | + id?: Maybe<Scalars['Float']>; | ||
65 | +}; | ||
66 | + | ||
67 | +export type Likeable = { | ||
68 | + __typename?: 'Likeable'; | ||
69 | + created_date: Scalars['String']; | ||
70 | + id: Scalars['Int']; | ||
71 | + like_dislike: Scalars['Int']; | ||
72 | + likeable_id: Scalars['Int']; | ||
73 | + likeable_type: Scalars['String']; | ||
74 | + user_id: Scalars['String']; | ||
75 | +}; | ||
76 | + | ||
77 | +export type Mutation = { | ||
78 | + __typename?: 'Mutation'; | ||
79 | + createComment: Comment; | ||
80 | + createLikeable: Likeable; | ||
81 | + createMyPage: MyPage; | ||
82 | + createPost: Post; | ||
83 | +}; | ||
84 | + | ||
85 | + | ||
86 | +export type MutationcreateCommentArgs = { | ||
87 | + input: CreateCommentInput; | ||
88 | +}; | ||
89 | + | ||
90 | + | ||
91 | +export type MutationcreateLikeableArgs = { | ||
92 | + input: CreateLikeableInput; | ||
93 | +}; | ||
94 | + | ||
95 | + | ||
96 | +export type MutationcreateMyPageArgs = { | ||
97 | + createMyInput: CreateMyInput; | ||
98 | +}; | ||
99 | + | ||
100 | + | ||
101 | +export type MutationcreatePostArgs = { | ||
102 | + input: CreatePostInput; | ||
103 | +}; | ||
104 | + | ||
105 | +export type MyPage = { | ||
106 | + __typename?: 'MyPage'; | ||
107 | + id: Scalars['Int']; | ||
108 | + name: Scalars['String']; | ||
109 | + type?: Maybe<Scalars['String']>; | ||
110 | +}; | ||
111 | + | ||
112 | +export type Post = { | ||
113 | + __typename?: 'Post'; | ||
114 | + author: Scalars['String']; | ||
115 | + category: Scalars['String']; | ||
116 | + content: Scalars['String']; | ||
117 | + created_date: Scalars['String']; | ||
118 | + id: Scalars['Int']; | ||
119 | + title: Scalars['String']; | ||
120 | + updated_date?: Maybe<Scalars['String']>; | ||
121 | +}; | ||
122 | + | ||
123 | +export type Query = { | ||
124 | + __typename?: 'Query'; | ||
125 | + getAllComments: Array<Comment>; | ||
126 | + getAllLikes: Array<Likeable>; | ||
127 | + getAllPosts: Array<Post>; | ||
128 | + getComment: Comment; | ||
129 | + getLikeable: Likeable; | ||
130 | + getPost: Post; | ||
131 | + getSomeComments: Array<Comment>; | ||
132 | + getSomePosts: Array<Post>; | ||
133 | + getTotalLikes: Scalars['Float']; | ||
134 | + myPage: Array<MyPage>; | ||
135 | +}; | ||
136 | + | ||
137 | + | ||
138 | +export type QuerygetCommentArgs = { | ||
139 | + id: Scalars['Float']; | ||
140 | +}; | ||
141 | + | ||
142 | + | ||
143 | +export type QuerygetLikeableArgs = { | ||
144 | + id: Scalars['Float']; | ||
145 | +}; | ||
146 | + | ||
147 | + | ||
148 | +export type QuerygetPostArgs = { | ||
149 | + id: Scalars['Float']; | ||
150 | +}; | ||
151 | + | ||
152 | + | ||
153 | +export type QuerygetSomeCommentsArgs = { | ||
154 | + input: GetCommentInput; | ||
155 | +}; | ||
156 | + | ||
157 | + | ||
158 | +export type QuerygetSomePostsArgs = { | ||
159 | + input: GetPostInput; | ||
160 | +}; | ||
161 | + | ||
162 | + | ||
163 | +export type QuerygetTotalLikesArgs = { | ||
164 | + input: GetLikeableInput; | ||
165 | +}; |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment