File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +11
-12
lines changed
Original file line number Diff line number Diff line change 1
1
import 'reflect-metadata' ;
2
- import { Express } from 'express' ;
3
2
import { join } from 'path' ;
4
3
import { BuildSchemaOptions , buildSchema } from 'type-graphql' ;
5
4
import { ApolloServer } from 'apollo-server-express' ;
6
5
7
- import { cors } from 'src/config' ;
8
6
import formatError from './formatError' ;
9
7
import ErrorHandlePlugin from './errorHandlePlugin' ;
10
8
11
9
export const path = '/graphql' ;
12
- const server = async ( app : Express ) => {
10
+ const server = async ( ) => {
13
11
const privatePath = join ( __dirname , '../../graphql/resolvers/**/*{.ts,.js}' ) ;
14
12
const apolloSchemeOptions : BuildSchemaOptions = {
15
13
resolvers : [ privatePath ] ,
16
14
validate : false ,
17
15
} ;
18
16
const apolloSchema = await buildSchema ( apolloSchemeOptions ) ;
19
- const apolloServer = new ApolloServer ( {
17
+ return new ApolloServer ( {
20
18
schema : apolloSchema ,
21
19
formatError,
22
20
plugins : [ ErrorHandlePlugin ] ,
23
21
playground : true ,
24
22
introspection : true ,
25
23
uploads : false ,
26
24
} ) ;
27
- apolloServer . applyMiddleware ( {
28
- cors,
29
- app,
30
- path,
31
- bodyParserConfig : true ,
32
- } ) ;
33
25
} ;
34
26
35
27
export default server ;
Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ import './i18n/index';
10
10
import './bugsnag' ;
11
11
import '../util/validatorjs/rules' ;
12
12
import handleErrors from './handleErrors' ;
13
- import apolloServer from './graphql/server' ;
13
+ import ApolloServer , { path } from './graphql/server' ;
14
14
import useControllersApi from './controllers' ;
15
+ import { cors } from 'src/config' ;
15
16
16
17
const getApp = async ( ) : Promise < Express > => {
17
18
dotenv . config ( ) ;
@@ -27,7 +28,13 @@ const getApp = async (): Promise<Express> => {
27
28
// use multi languages
28
29
app . use ( i18n . init ) ;
29
30
// Apollo graphQL
30
- await apolloServer ( app ) ;
31
+ const apolloServer = await ApolloServer ( ) ;
32
+ apolloServer . applyMiddleware ( {
33
+ cors,
34
+ app,
35
+ path,
36
+ bodyParserConfig : true ,
37
+ } ) ;
31
38
app . use ( graphqlUploadExpress ( { maxFileSize : 10000 , maxFiles : 10 } ) ) ;
32
39
// Api
33
40
useControllersApi ( app ) ;
You can’t perform that action at this time.
0 commit comments