Skip to content

Commit 2a75bd6

Browse files
committed
Some refactor
Signed-off-by: Arda TANRIKULU <[email protected]>
1 parent 6784f1e commit 2a75bd6

15 files changed

+384
-44
lines changed

.npmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
save_exact=true
1+
save-exact=true

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
"license": "MIT",
99
"scripts": {
1010
"generate": "gql-gen --template graphql-codegen-typescript-mongodb-template --out ./src/generated-models.ts -r ts-node/register/transpile-only -r tsconfig-paths/register --schema \"./src/schema.ts\"",
11-
"dev": "nodemon --exec yarn start",
12-
"prestart": "yarn generate",
13-
"start": "ts-node -r tsconfig-paths/register src/index.ts",
11+
"generate:watch": "nodemon --exec yarn generate -e graphql",
12+
"start:server": "ts-node -r tsconfig-paths/register src/index.ts",
13+
"start:server:watch": "nodemon --exec yarn start:server -e ts",
14+
"dev": "concurrently \"yarn generate:watch\" \"yarn start:server:watch\"",
15+
"start": "yarn generate && yarn start:server",
1416
"build": "tsc"
1517
},
1618
"dependencies": {
@@ -26,6 +28,7 @@
2628
"typescript": "3.1.3"
2729
},
2830
"devDependencies": {
31+
"concurrently": "4.0.1",
2932
"@types/graphql": "14.0.3",
3033
"graphql-code-generator": "0.13.0",
3134
"graphql-codegen-typescript-mongodb-template": "0.13.0",

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'reflect-metadata';
2-
import { appModule } from './modules/app';
2+
import { AppModule } from './modules/app';
33
import { ApolloServer } from 'apollo-server';
44

55
const chats = [
@@ -40,7 +40,7 @@ const messages = [
4040
},
4141
];
4242

43-
const { schema, context } = appModule.forRoot({
43+
const { schema, context } = AppModule.forRoot({
4444
chats,
4545
messages,
4646
});

src/modules/app.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { GraphQLModule } from "@graphql-modules/core";
22

3-
import { commonModule } from "./common";
3+
import { CommonModule } from "./common";
4+
import { ChatsModule } from "./chats";
5+
import { MessagesModule } from "./messages";
46

5-
import { chatsModule } from "./chats";
6-
7-
import { messagesModule } from "./messages";
8-
9-
export const appModule = new GraphQLModule({
7+
export const AppModule = new GraphQLModule({
108
imports: ({ chats, messages}) => [
11-
commonModule.forRoot({
9+
CommonModule.forRoot({
1210
chats,
1311
messages,
1412
}),
15-
chatsModule,
16-
messagesModule,
13+
ChatsModule,
14+
MessagesModule,
1715
],
1816
});

src/modules/chats/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { GraphQLModule } from '@graphql-modules/core';
22
import { loadResolversFiles, loadSchemaFiles } from '@graphql-modules/sonar';
33
import { mergeGraphQLSchemas, mergeResolvers } from '@graphql-modules/epoxy';
4-
import { messagesModule } from "@modules/messages";
5-
import { commonModule } from "@modules/common";
4+
import { MessagesModule } from "@modules/messages";
5+
import { CommonModule } from "@modules/common";
66
import { ChatsProvider } from "@modules/chats/providers/chats.provider";
77

8-
export const chatsModule = new GraphQLModule({
8+
export const ChatsModule = new GraphQLModule({
99
imports: () => [
10-
commonModule.forChild(),
11-
messagesModule,
10+
CommonModule.forChild(),
11+
MessagesModule,
1212
],
1313
providers: [
1414
ChatsProvider,

src/modules/chats/resolvers/chats.resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { MessageDbObject } from "@models";
55
export default {
66
Chat: {
77
messages: (chat: any, args, { injector }: ModuleContext): MessageDbObject[] =>
8-
injector.get<MessagesProvider>(MessagesProvider).getMessages(chat.id),
8+
injector.get(MessagesProvider).getMessages(chat.id),
99
},
1010
};

src/modules/chats/resolvers/mutation.resolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ChatDbObject, CreateChatMutationArgs, DeleteChatMutationArgs } from "@m
55
export default {
66
Mutation: {
77
createChat: (root, {title, description}: CreateChatMutationArgs, { injector }: ModuleContext): ChatDbObject =>
8-
injector.get<ChatsProvider>(ChatsProvider).createChat({title, description}),
8+
injector.get(ChatsProvider).createChat({title, description}),
99
deleteChat: (root, {id}: DeleteChatMutationArgs, { injector }: ModuleContext): number =>
10-
injector.get<ChatsProvider>(ChatsProvider).deleteChat(id),
10+
injector.get(ChatsProvider).deleteChat(id),
1111
},
1212
};

src/modules/chats/resolvers/query.resolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ChatDbObject } from "@models";
55
export default {
66
Query: {
77
chats: (root, args, { injector }: ModuleContext): ChatDbObject[] =>
8-
injector.get<ChatsProvider>(ChatsProvider).getChats(),
8+
injector.get(ChatsProvider).getChats(),
99
chat: (root, {id}: any, { injector }: ModuleContext): ChatDbObject =>
10-
injector.get<ChatsProvider>(ChatsProvider).getChat(id),
10+
injector.get(ChatsProvider).getChat(id),
1111
},
1212
};

src/modules/common/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface CommonModuleConfig {
1212
messages: MessageDbObject[];
1313
}
1414

15-
export const commonModule = new GraphQLModule<CommonModuleConfig>({
15+
export const CommonModule = new GraphQLModule<CommonModuleConfig>({
1616
providers: ({chats, messages}) => [
1717
{ provide: CHATS, useValue: chats },
1818
{ provide: MESSAGES, useValue: messages },

src/modules/messages/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { GraphQLModule } from '@graphql-modules/core';
22
import { loadResolversFiles, loadSchemaFiles } from '@graphql-modules/sonar';
33
import { mergeGraphQLSchemas, mergeResolvers } from '@graphql-modules/epoxy';
44
import { MessagesProvider } from "@modules/messages/providers/messages.provider";
5-
import { commonModule } from "@modules/common";
6-
import { chatsModule } from "@modules/chats";
5+
import { CommonModule } from "@modules/common";
6+
import { ChatsModule } from "@modules/chats";
77

8-
export const messagesModule = new GraphQLModule({
8+
export const MessagesModule = new GraphQLModule({
99
imports: () => [
10-
commonModule.forChild(),
11-
chatsModule,
10+
CommonModule.forChild(),
11+
ChatsModule,
1212
],
1313
providers: [
1414
MessagesProvider,

src/modules/messages/resolvers/messages.resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { ChatDbObject } from "@models";
55
export default {
66
Message: {
77
chat: (message: any, args, { injector }: ModuleContext): ChatDbObject =>
8-
injector.get<ChatsProvider>(ChatsProvider).getChat(message.chatId),
8+
injector.get(ChatsProvider).getChat(message.chatId),
99
},
1010
};

src/modules/messages/resolvers/mutation.resolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { CreateMessageMutationArgs, DeleteMessageMutationArgs, MessageDbObject }
55
export default {
66
Mutation: {
77
createMessage: (root, {content, chatId}: CreateMessageMutationArgs, { injector }: ModuleContext): MessageDbObject =>
8-
injector.get<MessagesProvider>(MessagesProvider).createMessage(content, chatId),
8+
injector.get(MessagesProvider).createMessage(content, chatId),
99
deleteMessage: (root, {id}: DeleteMessageMutationArgs, { injector }: ModuleContext): number =>
10-
injector.get<MessagesProvider>(MessagesProvider).deleteMessage(id),
10+
injector.get(MessagesProvider).deleteMessage(id),
1111
},
1212
};

src/modules/messages/resolvers/query.resolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { MessageDbObject } from "@models";
55
export default {
66
Query: {
77
messages: (root, {chatId}: any, { injector }: ModuleContext): MessageDbObject[] =>
8-
injector.get<MessagesProvider>(MessagesProvider).getMessages(chatId),
8+
injector.get(MessagesProvider).getMessages(chatId),
99
message: (root, {id}: any, { injector }: ModuleContext): MessageDbObject =>
10-
injector.get<MessagesProvider>(MessagesProvider).getMessage(id),
10+
injector.get(MessagesProvider).getMessage(id),
1111
},
1212
};

src/schema.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'reflect-metadata';
22
import { makeExecutableSchema } from 'graphql-tools';
3-
import { appModule } from '@modules/app';
3+
import { AppModule } from '@modules/app';
44

5-
const { typeDefs } = appModule;
5+
// Ask for typeDefs without all schema with business logi
6+
const { typeDefs } = AppModule;
67
export default makeExecutableSchema({
78
typeDefs
89
});

0 commit comments

Comments
 (0)