@tsed/typegraphql 7.0.0-beta.8 → 7.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/TypeGraphQLModule.js +3 -0
- package/lib/cjs/TypeGraphQLModule.js.map +1 -1
- package/lib/cjs/services/TypeGraphQLService.js +4 -1
- package/lib/cjs/services/TypeGraphQLService.js.map +1 -1
- package/lib/esm/TypeGraphQLModule.js +3 -0
- package/lib/esm/TypeGraphQLModule.js.map +1 -1
- package/lib/esm/services/TypeGraphQLService.js +4 -1
- package/lib/esm/services/TypeGraphQLService.js.map +1 -1
- package/package.json +11 -8
- package/readme.md +3 -2
- package/.mocharc.js +0 -5
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "typegraphql"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
statements: 100,
|
|
9
|
+
branches: 70.58,
|
|
10
|
+
functions: 100,
|
|
11
|
+
lines: 100
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -8,6 +8,9 @@ const TypeGraphQLService_1 = require("./services/TypeGraphQLService");
|
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
let TypeGraphQLModule = class TypeGraphQLModule {
|
|
11
|
+
service;
|
|
12
|
+
injector;
|
|
13
|
+
configuration;
|
|
11
14
|
get settings() {
|
|
12
15
|
return this.configuration.get("graphql") || this.configuration.get("typegraphql");
|
|
13
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../../src/TypeGraphQLModule.ts"],"names":[],"mappings":";;;;AAAA,iCAA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AAC,IAAI,CAAC,IAAI,GAAG,oCAAoC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC,CAAC;QAEF,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACpD,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBAEvB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AA1CC;IADC,IAAA,WAAM,GAAE;sCACU,uCAAkB;kDAAC;AAGtC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;mDAAC;AAGpC;IADC,IAAA,kBAAa,GAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,IAAA,WAAM,GAAE;GACI,iBAAiB,CA4C7B;AA5CY,8CAAiB","sourcesContent":["import {Configuration, Inject, InjectorService, Module} from \"@tsed/di\";\nimport {TypeGraphQLSettings} from \"./interfaces/interfaces\";\nimport {TypeGraphQLService} from \"./services/TypeGraphQLService\";\n\n/**\n * @ignore\n */\n@Module()\nexport class TypeGraphQLModule {\n @Inject()\n protected service: TypeGraphQLService;\n\n @Inject()\n protected injector: InjectorService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: TypeGraphQLSettings} | undefined {\n return this.configuration.get(\"graphql\") || this.configuration.get(\"typegraphql\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const host = this.configuration.getBestHost();\n\n const displayLog = (key: string, path: string) => {\n const url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n\n this.injector.logger.info(`[${key}] GraphQL server is available on ${url}/${path.replace(/^\\//, \"\")}`);\n };\n\n const {settings} = this;\n\n if (settings) {\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n\n displayLog(key, path);\n });\n }\n }\n}\n"]}
|
|
@@ -10,6 +10,9 @@ const type_graphql_1 = require("type-graphql");
|
|
|
10
10
|
const constants_1 = require("../constants/constants");
|
|
11
11
|
const getKey = (id) => `typegraphql-${id}`;
|
|
12
12
|
let TypeGraphQLService = class TypeGraphQLService {
|
|
13
|
+
injector;
|
|
14
|
+
apolloService;
|
|
15
|
+
logger;
|
|
13
16
|
/**
|
|
14
17
|
* Get an instance of ApolloServer from his id
|
|
15
18
|
* @returns ApolloServer
|
|
@@ -83,7 +86,7 @@ let TypeGraphQLService = class TypeGraphQLService {
|
|
|
83
86
|
return providers.reduce((map, provider) => {
|
|
84
87
|
// set the first letter of the class lowercase to follow proper conventions during access
|
|
85
88
|
// i.e. this.context.dataSources.userService
|
|
86
|
-
const sourceName = `${provider.name[0].toLowerCase()}${provider.name.
|
|
89
|
+
const sourceName = `${provider.name[0].toLowerCase()}${provider.name.slice(1)}`;
|
|
87
90
|
map[sourceName] = this.injector.invoke(provider.provide);
|
|
88
91
|
return map;
|
|
89
92
|
}, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AAEzD,iCAAuE;AACvE,yCAAoC;AAGpC,kEAA4C;AAC5C,+CAA6D;AAE7D,sDAAwG;AAGxG,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC;AAGnD,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;
|
|
1
|
+
{"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","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,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAEzD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAED;;;;OAIG;IACO,iBAAiB,CAAC,WAAiC,EAAE,mBAAyC;QACtG,OAAO,GAAG,EAAE;YACV,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAEtC,OAAO;gBACL,GAAG,OAAO;gBACV,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtD,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAES,sBAAsB;QAC9B,uBAAuB;QACvB,aAAa;QACb,IAAI,WAAW,CAAC,YAAY,EAAE;YAC5B,mDAAmD;YACnD,aAAa;YACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SAChD;IACH,CAAC;CACF,CAAA;AA5HC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;oDAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACgB,sBAAa;yDAAC;AAGvC;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;kDAAC;AARd,kBAAkB;IAD9B,IAAA,eAAU,GAAE;GACA,kBAAkB,CA8H9B;AA9HY,gDAAkB","sourcesContent":["import {ApolloServer, ApolloService} from \"@tsed/apollo\";\nimport {Type} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {DataSource} from \"apollo-datasource\";\nimport {GraphQLSchema} from \"graphql\";\nimport * as TypeGraphql from \"type-graphql\";\nimport {buildSchema, BuildSchemaOptions} from \"type-graphql\";\nimport {ApolloServerBase} from \"apollo-server-core\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants/constants\";\nimport {TypeGraphQLSettings} from \"../interfaces/interfaces\";\n\nconst getKey = (id: string) => `typegraphql-${id}`;\n\n@Injectable()\nexport class TypeGraphQLService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected apolloService: ApolloService;\n\n @Inject()\n protected logger: Logger;\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServerBase | undefined {\n return this.apolloService.get(getKey(id));\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.apolloService.has(getKey(id));\n }\n\n /**\n *\n * @returns {Promise<ApolloServer>}\n */\n async createServer(id: string, settings: TypeGraphQLSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {dataSources, resolvers: initialResolvers = [], buildSchemaOptions = {}, serverConfig = {}, ...serverOptions} = settings;\n\n this.configureTypeGraphQLDI();\n\n const resolvers: any = [...this.getResolvers(), ...(initialResolvers as any[])];\n const schema = await this.createSchema({\n container: this.injector,\n ...buildSchemaOptions,\n resolvers\n });\n\n return await this.apolloService.createServer(getKey(id), {\n ...serverOptions,\n ...serverConfig,\n resolvers,\n dataSources: this.createDataSources(dataSources, serverConfig.dataSources),\n schema\n });\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Create a new type-graphql Schema and bind it with Ts.ED injector.\n * @param buildSchemaOptions\n */\n async createSchema(buildSchemaOptions: BuildSchemaOptions) {\n return buildSchema(buildSchemaOptions);\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.apolloService.getSchema(getKey(id));\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getResolvers(): Type<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);\n }\n\n protected getDataSources(): Record<string, DataSource> {\n const providers = this.injector.getProviders(PROVIDER_TYPE_DATASOURCE_SERVICE);\n\n return providers.reduce<Record<string, DataSource>>((map, provider) => {\n // set the first letter of the class lowercase to follow proper conventions during access\n // i.e. this.context.dataSources.userService\n const sourceName = `${provider.name[0].toLowerCase()}${provider.name.slice(1)}`;\n map[sourceName] = this.injector.invoke(provider.provide);\n\n return map;\n }, {});\n }\n\n /**\n * create a new dataSources function to use with apollo server config\n * @param dataSources\n * @param serverConfigSources\n */\n protected createDataSources(dataSources: Function | undefined, serverConfigSources: Function | undefined) {\n return () => {\n const sources = this.getDataSources();\n\n return {\n ...sources,\n ...(dataSources ? dataSources() : {}),\n ...(serverConfigSources ? serverConfigSources() : {})\n };\n };\n }\n\n protected configureTypeGraphQLDI() {\n // istanbul ignore next\n // @ts-ignore\n if (TypeGraphql.useContainer) {\n // support old version of type-graphql under @v0.17\n // @ts-ignore\n TypeGraphql.useContainer(this.injectorService);\n }\n }\n}\n"]}
|
|
@@ -5,6 +5,9 @@ import { TypeGraphQLService } from "./services/TypeGraphQLService.js";
|
|
|
5
5
|
* @ignore
|
|
6
6
|
*/
|
|
7
7
|
let TypeGraphQLModule = class TypeGraphQLModule {
|
|
8
|
+
service;
|
|
9
|
+
injector;
|
|
10
|
+
configuration;
|
|
8
11
|
get settings() {
|
|
9
12
|
return this.configuration.get("graphql") || this.configuration.get("typegraphql");
|
|
10
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../../src/TypeGraphQLModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAExE,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAEj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IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAEnG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,oCAAoC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC,CAAC;QAEF,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACpD,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBAEvB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AA1CC;IADC,MAAM,EAAE;8BACU,kBAAkB;kDAAC;AAGtC;IADC,MAAM,EAAE;8BACW,eAAe;mDAAC;AAGpC;IADC,aAAa,EAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,MAAM,EAAE;GACI,iBAAiB,CA4C7B;SA5CY,iBAAiB","sourcesContent":["import {Configuration, Inject, InjectorService, Module} from \"@tsed/di\";\nimport {TypeGraphQLSettings} from \"./interfaces/interfaces\";\nimport {TypeGraphQLService} from \"./services/TypeGraphQLService\";\n\n/**\n * @ignore\n */\n@Module()\nexport class TypeGraphQLModule {\n @Inject()\n protected service: TypeGraphQLService;\n\n @Inject()\n protected injector: InjectorService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: TypeGraphQLSettings} | undefined {\n return this.configuration.get(\"graphql\") || this.configuration.get(\"typegraphql\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const host = this.configuration.getBestHost();\n\n const displayLog = (key: string, path: string) => {\n const url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n\n this.injector.logger.info(`[${key}] GraphQL server is available on ${url}/${path.replace(/^\\//, \"\")}`);\n };\n\n const {settings} = this;\n\n if (settings) {\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n\n displayLog(key, path);\n });\n }\n }\n}\n"]}
|
|
@@ -7,6 +7,9 @@ import { buildSchema } from "type-graphql";
|
|
|
7
7
|
import { PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants/constants.js";
|
|
8
8
|
const getKey = (id) => `typegraphql-${id}`;
|
|
9
9
|
let TypeGraphQLService = class TypeGraphQLService {
|
|
10
|
+
injector;
|
|
11
|
+
apolloService;
|
|
12
|
+
logger;
|
|
10
13
|
/**
|
|
11
14
|
* Get an instance of ApolloServer from his id
|
|
12
15
|
* @returns ApolloServer
|
|
@@ -80,7 +83,7 @@ let TypeGraphQLService = class TypeGraphQLService {
|
|
|
80
83
|
return providers.reduce((map, provider) => {
|
|
81
84
|
// set the first letter of the class lowercase to follow proper conventions during access
|
|
82
85
|
// i.e. this.context.dataSources.userService
|
|
83
|
-
const sourceName = `${provider.name[0].toLowerCase()}${provider.name.
|
|
86
|
+
const sourceName = `${provider.name[0].toLowerCase()}${provider.name.slice(1)}`;
|
|
84
87
|
map[sourceName] = this.injector.invoke(provider.provide);
|
|
85
88
|
return map;
|
|
86
89
|
}, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAe,aAAa,EAAC,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AACvE,OAAO,EAAC,MAAM,EAAC,MAAM,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AAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SAChD;IACH,CAAC;CACF,CAAA;AA5HC;IADC,MAAM,EAAE;8BACW,eAAe;oDAAC;AAGpC;IADC,MAAM,EAAE;8BACgB,aAAa;yDAAC;AAGvC;IADC,MAAM,EAAE;8BACS,MAAM;kDAAC;AARd,kBAAkB;IAD9B,UAAU,EAAE;GACA,kBAAkB,CA8H9B;SA9HY,kBAAkB","sourcesContent":["import {ApolloServer, ApolloService} from \"@tsed/apollo\";\nimport {Type} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {DataSource} from \"apollo-datasource\";\nimport {GraphQLSchema} from \"graphql\";\nimport * as TypeGraphql from \"type-graphql\";\nimport {buildSchema, BuildSchemaOptions} from \"type-graphql\";\nimport {ApolloServerBase} from \"apollo-server-core\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants/constants\";\nimport {TypeGraphQLSettings} from \"../interfaces/interfaces\";\n\nconst getKey = (id: string) => `typegraphql-${id}`;\n\n@Injectable()\nexport class TypeGraphQLService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected apolloService: ApolloService;\n\n @Inject()\n protected logger: Logger;\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServerBase | undefined {\n return this.apolloService.get(getKey(id));\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.apolloService.has(getKey(id));\n }\n\n /**\n *\n * @returns {Promise<ApolloServer>}\n */\n async createServer(id: string, settings: TypeGraphQLSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {dataSources, resolvers: initialResolvers = [], buildSchemaOptions = {}, serverConfig = {}, ...serverOptions} = settings;\n\n this.configureTypeGraphQLDI();\n\n const resolvers: any = [...this.getResolvers(), ...(initialResolvers as any[])];\n const schema = await this.createSchema({\n container: this.injector,\n ...buildSchemaOptions,\n resolvers\n });\n\n return await this.apolloService.createServer(getKey(id), {\n ...serverOptions,\n ...serverConfig,\n resolvers,\n dataSources: this.createDataSources(dataSources, serverConfig.dataSources),\n schema\n });\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Create a new type-graphql Schema and bind it with Ts.ED injector.\n * @param buildSchemaOptions\n */\n async createSchema(buildSchemaOptions: BuildSchemaOptions) {\n return buildSchema(buildSchemaOptions);\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.apolloService.getSchema(getKey(id));\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getResolvers(): Type<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);\n }\n\n protected getDataSources(): Record<string, DataSource> {\n const providers = this.injector.getProviders(PROVIDER_TYPE_DATASOURCE_SERVICE);\n\n return providers.reduce<Record<string, DataSource>>((map, provider) => {\n // set the first letter of the class lowercase to follow proper conventions during access\n // i.e. this.context.dataSources.userService\n const sourceName = `${provider.name[0].toLowerCase()}${provider.name.slice(1)}`;\n map[sourceName] = this.injector.invoke(provider.provide);\n\n return map;\n }, {});\n }\n\n /**\n * create a new dataSources function to use with apollo server config\n * @param dataSources\n * @param serverConfigSources\n */\n protected createDataSources(dataSources: Function | undefined, serverConfigSources: Function | undefined) {\n return () => {\n const sources = this.getDataSources();\n\n return {\n ...sources,\n ...(dataSources ? dataSources() : {}),\n ...(serverConfigSources ? serverConfigSources() : {})\n };\n };\n }\n\n protected configureTypeGraphQLDI() {\n // istanbul ignore next\n // @ts-ignore\n if (TypeGraphql.useContainer) {\n // support old version of type-graphql under @v0.17\n // @ts-ignore\n TypeGraphql.useContainer(this.injectorService);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/typegraphql",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-rc.2",
|
|
4
4
|
"description": "TypeGraphQL package for Ts.ED framework, based on Apollo-server-core and Type-graphql",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
21
21
|
"start:express": "ts-node -r tsconfig-paths/register test/app/index.express.ts",
|
|
22
22
|
"start:koa": "ts-node -r tsconfig-paths/register test/app/index.koa.ts",
|
|
23
|
-
"test": "cross-env NODE_ENV=test
|
|
23
|
+
"test": "cross-env NODE_ENV=test jest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tsed/apollo": "7.0.0-
|
|
27
|
-
"tslib": "2.
|
|
26
|
+
"@tsed/apollo": "7.0.0-rc.2",
|
|
27
|
+
"tslib": "2.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@tsed/common": "7.0.0-
|
|
31
|
-
"@tsed/core": "7.0.0-
|
|
30
|
+
"@tsed/common": "7.0.0-rc.2",
|
|
31
|
+
"@tsed/core": "7.0.0-rc.2",
|
|
32
32
|
"@types/graphql": "^14.5.0",
|
|
33
33
|
"class-validator": "~0.13.1",
|
|
34
34
|
"graphql-passport": "0.6.3",
|
|
@@ -45,7 +45,10 @@
|
|
|
45
45
|
"bugs": {
|
|
46
46
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
47
47
|
},
|
|
48
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
48
|
+
"homepage": "https://github.com/tsedio/tsed/tree/rc/packages/graphql/typegraphql",
|
|
49
49
|
"author": "Romain Lenzotti",
|
|
50
|
-
"license": "MIT"
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"tag": "rc"
|
|
53
|
+
}
|
|
51
54
|
}
|
package/readme.md
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
13
13
|
[](https://github.com/semantic-release/semantic-release)
|
|
14
14
|
[](https://github.com/prettier/prettier)
|
|
15
|
-
[](https://github.com/sponsors/romakita)
|
|
16
|
+
[](https://opencollective.com/tsed)
|
|
16
17
|
|
|
17
18
|
</div>
|
|
18
19
|
|
|
@@ -191,7 +192,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
191
192
|
|
|
192
193
|
The MIT License (MIT)
|
|
193
194
|
|
|
194
|
-
Copyright (c) 2016 -
|
|
195
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
195
196
|
|
|
196
197
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
197
198
|
|