@@ -3,13 +3,14 @@ import * as GraphQLHTTP from 'express-graphql';
33import * as DataLoader from 'dataloader' ;
44import { GraphQLSchema , GraphQLObjectType } from 'graphql' ;
55import { Container as container , ObjectType } from 'typedi' ;
6+ import { Repository , getCustomRepository , getRepository } from 'typeorm' ;
67
78import { GraphQLContext , GraphQLContextDataLoader } from './GraphQLContext' ;
89import { MetadataArgsStorage } from './MetadataArgsStorage' ;
910import { importClassesFromDirectories } from './importClassesFromDirectories' ;
1011import { handlingErrors , getErrorCode , getErrorMessage } from './graphql-error-handling' ;
1112import { ensureInputOrder } from './dataloader' ;
12- import { Repository , getCustomRepository , getRepository } from 'typeorm ' ;
13+ import { getFromContainer } from './container ' ;
1314
1415// -------------------------------------------------------------------------
1516// Main exports
@@ -22,6 +23,7 @@ export * from './AbstractGraphQLHooks';
2223export * from './AbstractGraphQLQuery' ;
2324export * from './GraphQLContext' ;
2425export * from './graphql-error-handling' ;
26+ export * from './container' ;
2527
2628// -------------------------------------------------------------------------
2729// Main Functions
@@ -168,8 +170,8 @@ export function createSchema(options: GraphQLSchemaOptions): GraphQLSchema {
168170 }
169171
170172 const queries = { } ;
171- queryClasses . forEach ( queryClass => {
172- queries [ createQueryName ( queryClass . name ) ] = new queryClass ( ) ;
173+ getMetadataArgsStorage ( ) . queries . forEach ( queryMetdadata => {
174+ queries [ createQueryName ( queryMetdadata . name ) ] = getFromContainer ( queryMetdadata . target ) ;
173175 } ) ;
174176
175177 const RootQuery = new GraphQLObjectType ( {
@@ -186,8 +188,8 @@ export function createSchema(options: GraphQLSchemaOptions): GraphQLSchema {
186188 }
187189
188190 const mutations = { } ;
189- mutationClasses . forEach ( mutationClass => {
190- mutations [ createMutationName ( mutationClass . name ) ] = new mutationClass ( ) ;
191+ getMetadataArgsStorage ( ) . mutations . forEach ( mutationMetdadata => {
192+ mutations [ createMutationName ( mutationMetdadata . name ) ] = getFromContainer ( mutationMetdadata . target ) ;
191193 } ) ;
192194
193195 const RootMutation : GraphQLObjectType = new GraphQLObjectType ( {
0 commit comments