type-graphql 2.0.0-rc.3 → 2.0.0-rc.4

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <!-- prettier-ignore-start -->
2
2
  <!-- markdownlint-disable-next-line MD041 -->
3
- ![logo](https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/logo.png)
3
+ ![logo](https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/logo.png)
4
4
  <!-- prettier-ignore-end -->
5
5
 
6
6
  # TypeGraphQL
@@ -139,9 +139,9 @@ If you prefer video tutorials, you can watch [Ben Awad](https://github.com/benaw
139
139
 
140
140
  ### Examples
141
141
 
142
- You can also check the [examples folder](https://github.com/MichalLytek/type-graphql/tree/v2.0.0-rc.3/examples) in this repository for more examples of usage: simple fields resolvers, DI Container support, TypeORM integration, automatic validation, etc.
142
+ You can also check the [examples folder](https://github.com/MichalLytek/type-graphql/tree/v2.0.0-rc.4/examples) in this repository for more examples of usage: simple fields resolvers, DI Container support, TypeORM integration, automatic validation, etc.
143
143
 
144
- The [Tests folder](https://github.com/MichalLytek/type-graphql/tree/v2.0.0-rc.3/tests) might also give you some tips on how to get various things done.
144
+ The [Tests folder](https://github.com/MichalLytek/type-graphql/tree/v2.0.0-rc.4/tests) might also give you some tips on how to get various things done.
145
145
 
146
146
  ## Security contact information
147
147
 
@@ -173,21 +173,21 @@ It doesn't have a large company that sits behind it - its ongoing development is
173
173
 
174
174
  <!-- markdownlint-disable MD033 -->
175
175
 
176
- | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/leofame.png" width="250" alt="Leofame" />](https://leofame.com/buy-instagram-followers) |
176
+ | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/leofame.png" width="250" alt="Leofame" />](https://leofame.com/buy-instagram-followers) |
177
177
  | :---------------------------------------------------------------------------------------------------------: |
178
178
  | [**Leofame**](https://leofame.com/buy-instagram-followers) |
179
179
 
180
180
  ### Bronze Sponsors 🥉
181
181
 
182
- | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/live-graphics-system.png" width="55" alt="live graphic systems" />](https://www.ligrsystems.com) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/felix.png" width="60" alt="Felix Technologies" />](https://github.com/joinlifex) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/instinctools.svg" width="100" alt="instinctools" />](https://instinctools.com/manufacturing) |
182
+ | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/live-graphics-system.png" width="55" alt="live graphic systems" />](https://www.ligrsystems.com) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/felix.png" width="60" alt="Felix Technologies" />](https://github.com/joinlifex) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/instinctools.svg" width="100" alt="instinctools" />](https://instinctools.com/manufacturing) |
183
183
  | :------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------: |
184
184
  | [**Live Graphic Systems**](https://www.ligrsystems.com) | [**Felix Technologies**](https://github.com/joinlifex/) | [**instinctools**](https://instinctools.com/manufacturing) |
185
185
 
186
- | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/betwinner.svg" width="100" alt="BetWinner" />](https://guidebook.betwinner.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/logo-buzzv.png" width="70" alt="BuzzVoice" />](https://buzzvoice.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/socialwick-logo.png" width="60" alt="SocialWick" />](https://www.socialwick.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/c19.png" width="40" alt="C19" />](https://www.c19.cl/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/nove_casino.svg" width="70" alt="Nove Casino" />](https://novecasino.net/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/play_fortune.png" width="80" alt="Play Fortune" />](https://play-fortune.pl/gry-online/jednoreki-bandyta/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/moonkasyno.png" width="60" alt="MoonKasyno" />](https://wechoosethemoon.org/kasyna-online/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/kasyno-online.png" width="50" alt="Kasyno Online" />](https://www.casinobillions.com/pl/) |
187
- | :--------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: |
188
- | [**BetWinner**](https://guidebook.betwinner.com/) | [**BuzzVoice**](https://buzzvoice.com/) | [**SocialWick**](https://www.socialwick.com/) | [**C19**](https://www.c19.cl/) | [**Nove Casino**](https://novecasino.net/) | [**Play Fortune**](https://play-fortune.pl/gry-online/jednoreki-bandyta/) | [**MoonKasyno**](https://wechoosethemoon.org/kasyna-online/) | [**Kasyno Online**](https://www.casinobillions.com/pl/) |
186
+ | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/betwinner.svg" width="100" alt="BetWinner" />](https://guidebook.betwinner.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/logo-buzzv.png" width="70" alt="BuzzVoice" />](https://buzzvoice.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/socialwick-logo.png" width="60" alt="SocialWick" />](https://www.socialwick.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/c19.png" width="40" alt="C19" />](https://www.c19.cl/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/nove_casino.svg" width="70" alt="Nove Casino" />](https://novecasino.net/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/play_fortune.png" width="80" alt="Play Fortune" />](https://play-fortune.pl/gry-online/jednoreki-bandyta/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/moonkasyno.png" width="60" alt="MoonKasyno" />](https://wechoosethemoon.org/kasyna-online/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/kasyno-online.png" width="50" alt="Kasyno Online" />](https://www.casinobillions.com/pl/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/fbpostlikes.webp" width="90" alt="FBPostLikes" />](https://www.fbpostlikes.com/) |
187
+ | :--------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
188
+ | [**BetWinner**](https://guidebook.betwinner.com/) | [**BuzzVoice**](https://buzzvoice.com/) | [**SocialWick**](https://www.socialwick.com/) | [**C19**](https://www.c19.cl/) | [**Nove Casino**](https://novecasino.net/) | [**Play Fortune**](https://play-fortune.pl/gry-online/jednoreki-bandyta/) | [**MoonKasyno**](https://wechoosethemoon.org/kasyna-online/) | [**Kasyno Online**](https://www.casinobillions.com/pl/) | [**FBPostLikes**](https://www.fbpostlikes.com/) |
189
189
 
190
- | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/sidesmedia.png" width="40" alt="SidesMedia" />](https://sidesmedia.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/social_followers.png" width="60" alt="Social Followers" />](https://www.socialfollowers.uk/buy-tiktok-followers/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/ig-comment.png" width="80" alt="IG Comment" />](https://igcomment.com/buy-instagram-comments/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/twicsy.svg" width="100" alt="Twicsy" />](https://twicsy.com/buy-instagram-followers) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/buzzoid.svg" width="90" alt="Buzzoid" />](https://buzzoid.com/buy-instagram-followers/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/v4u.png" width="80" alt="Views4You" />](https://views4you.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/payid_pookies.avif" width="50" alt="PayID Pokies" />](https://au.trustpilot.com/review/bestpayidpokies.net) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/fun88.png" width="40" alt="Fun88" />](https://global.fun88.com/) |
190
+ | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/sidesmedia.png" width="40" alt="SidesMedia" />](https://sidesmedia.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/social_followers.png" width="60" alt="Social Followers" />](https://www.socialfollowers.uk/buy-tiktok-followers/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/ig-comment.png" width="80" alt="IG Comment" />](https://igcomment.com/buy-instagram-comments/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/twicsy.svg" width="100" alt="Twicsy" />](https://twicsy.com/buy-instagram-followers) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/buzzoid.svg" width="90" alt="Buzzoid" />](https://buzzoid.com/buy-instagram-followers/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/v4u.png" width="80" alt="Views4You" />](https://views4you.com/) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/payid_pookies.avif" width="50" alt="PayID Pokies" />](https://au.trustpilot.com/review/bestpayidpokies.net) | [<img src="https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/fun88.png" width="40" alt="Fun88" />](https://global.fun88.com/) |
191
191
  | :------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
192
192
  | [**SidesMedia**](https://sidesmedia.com/) | [**Social Followers**](https://www.socialfollowers.uk/buy-tiktok-followers/) | [**IG Comment**](https://igcomment.com/buy-instagram-comments/) | [**Twicsy**](https://twicsy.com/buy-instagram-followers) | [**Buzzoid**](https://buzzoid.com/buy-instagram-followers/) | [**Views4You**](https://views4you.com/) | [**PayID Pokies**](https://au.trustpilot.com/review/bestpayidpokies.net) | [**Fun88**](https://global.fun88.com/) |
193
193
 
@@ -201,7 +201,7 @@ It doesn't have a large company that sits behind it - its ongoing development is
201
201
 
202
202
  ### GitHub Sponsors
203
203
 
204
- [![GitHub Sponsors](https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.3/images/github-sponsors.svg)](https://github.com/sponsors/TypeGraphQL)
204
+ [![GitHub Sponsors](https://raw.githubusercontent.com/MichalLytek/type-graphql/v2.0.0-rc.4/images/github-sponsors.svg)](https://github.com/sponsors/TypeGraphQL)
205
205
 
206
206
  ## Community
207
207
 
@@ -211,4 +211,4 @@ It doesn't have a large company that sits behind it - its ongoing development is
211
211
  ## Want to help?
212
212
 
213
213
  Want to file a bug, contribute some code, or improve the documentation? Great! Please read our
214
- guidelines for [CONTRIBUTING](https://github.com/MichalLytek/type-graphql/tree/v2.0.0-rc.3/CONTRIBUTING.md) and then check out one of our [help-wanted issues](https://github.com/MichalLytek/type-graphql/labels/Help%20Wanted%20%3Asos%3A).
214
+ guidelines for [CONTRIBUTING](https://github.com/MichalLytek/type-graphql/tree/v2.0.0-rc.4/CONTRIBUTING.md) and then check out one of our [help-wanted issues](https://github.com/MichalLytek/type-graphql/labels/Help%20Wanted%20%3Asos%3A).
@@ -111,6 +111,7 @@ class MetadataStorage {
111
111
  this.fieldExtensions.push(definition);
112
112
  }
113
113
  initCache() {
114
+ this.clearMapCaches();
114
115
  if (this.resolverClasses?.length) {
115
116
  this.resolverClasses.forEach(resolverClass => {
116
117
  if (!this.resolverClassesCache.has(resolverClass.target)) {
@@ -260,6 +261,38 @@ class MetadataStorage {
260
261
  this.argumentDirectives = [];
261
262
  this.classExtensions = [];
262
263
  this.fieldExtensions = [];
264
+ this.resolverClasses = [];
265
+ this.fields = [];
266
+ this.params = [];
267
+ this.clearMapCaches();
268
+ }
269
+ clone() {
270
+ const cloned = new MetadataStorage();
271
+ cloned.queries = [...this.queries];
272
+ cloned.mutations = [...this.mutations];
273
+ cloned.subscriptions = [...this.subscriptions];
274
+ cloned.fieldResolvers = [...this.fieldResolvers];
275
+ cloned.objectTypes = [...this.objectTypes];
276
+ cloned.inputTypes = [...this.inputTypes];
277
+ cloned.argumentTypes = [...this.argumentTypes];
278
+ cloned.interfaceTypes = [...this.interfaceTypes];
279
+ cloned.authorizedFields = [...this.authorizedFields];
280
+ cloned.authorizedResolver = [...this.authorizedResolver];
281
+ cloned.enums = [...this.enums];
282
+ cloned.unions = [...this.unions];
283
+ cloned.middlewares = [...this.middlewares];
284
+ cloned.resolverMiddlewares = [...this.resolverMiddlewares];
285
+ cloned.classDirectives = [...this.classDirectives];
286
+ cloned.fieldDirectives = [...this.fieldDirectives];
287
+ cloned.argumentDirectives = [...this.argumentDirectives];
288
+ cloned.classExtensions = [...this.classExtensions];
289
+ cloned.fieldExtensions = [...this.fieldExtensions];
290
+ cloned.resolverClasses = [...this.resolverClasses];
291
+ cloned.fields = [...this.fields];
292
+ cloned.params = [...this.params];
293
+ return cloned;
294
+ }
295
+ clearMapCaches() {
263
296
  this.fieldsCache = new Map();
264
297
  this.objectTypesCache = new Map();
265
298
  this.interfaceTypesCache = new Map();
@@ -271,9 +304,6 @@ class MetadataStorage {
271
304
  this.authorizedFieldsByTargetAndFieldCache = new Map();
272
305
  this.authorizedResolverByTargetCache = new Map();
273
306
  this.resolverClassesCache = new Map();
274
- this.resolverClasses = [];
275
- this.fields = [];
276
- this.params = [];
277
307
  }
278
308
  buildClassMetadata(definitions) {
279
309
  definitions.forEach(def => {
@@ -6,7 +6,6 @@ const graphql_1 = require("graphql");
6
6
  const errors_1 = require("../errors");
7
7
  const types_1 = require("../helpers/types");
8
8
  const getMetadataStorage_1 = require("../metadata/getMetadataStorage");
9
- const metadata_storage_1 = require("../metadata/metadata-storage");
10
9
  const create_1 = require("../resolvers/create");
11
10
  const graphql_version_1 = require("../utils/graphql-version");
12
11
  const build_context_1 = require("./build-context");
@@ -14,7 +13,7 @@ const definition_node_1 = require("./definition-node");
14
13
  const utils_1 = require("./utils");
15
14
  class SchemaGenerator {
16
15
  static generateFromMetadata(options) {
17
- this.metadataStorage = Object.assign(new metadata_storage_1.MetadataStorage(), (0, getMetadataStorage_1.getMetadataStorage)());
16
+ this.metadataStorage = (0, getMetadataStorage_1.getMetadataStorage)().clone();
18
17
  this.metadataStorage.build(options);
19
18
  this.checkForErrors(options);
20
19
  build_context_1.BuildContext.create(options);
@@ -32,6 +31,11 @@ class SchemaGenerator {
32
31
  });
33
32
  build_context_1.BuildContext.reset();
34
33
  this.usedInterfaceTypes = new Set();
34
+ this.objectTypesInfoMap = new Map();
35
+ this.inputTypesInfoMap = new Map();
36
+ this.interfaceTypesInfoMap = new Map();
37
+ this.enumTypesInfoMap = new Map();
38
+ this.unionTypesInfoMap = new Map();
35
39
  if (!options.skipCheck) {
36
40
  const { errors } = (0, graphql_1.graphqlSync)({ schema: finalSchema, source: (0, graphql_1.getIntrospectionQuery)() });
37
41
  if (errors) {
@@ -62,7 +66,7 @@ class SchemaGenerator {
62
66
  : defaultValueFromInitializer;
63
67
  }
64
68
  static buildTypesInfo(resolvers) {
65
- this.unionTypesInfo = this.metadataStorage.unions.map(unionMetadata => {
69
+ this.unionTypesInfoMap = new Map(this.metadataStorage.unions.map(unionMetadata => {
66
70
  const unionObjectTypesInfo = [];
67
71
  const typesThunk = () => {
68
72
  unionObjectTypesInfo.push(...unionMetadata
@@ -90,12 +94,11 @@ class SchemaGenerator {
90
94
  },
91
95
  }),
92
96
  };
93
- this.unionTypesInfoMap.set(unionMetadata.symbol, unionTypeInfo);
94
- return unionTypeInfo;
95
- });
96
- this.enumTypesInfo = this.metadataStorage.enums.map(enumMetadata => {
97
+ return [unionMetadata.symbol, unionTypeInfo];
98
+ }));
99
+ this.enumTypesInfoMap = new Map(this.metadataStorage.enums.map(enumMetadata => {
97
100
  const enumMap = (0, types_1.getEnumValuesMap)(enumMetadata.enumObj);
98
- return {
101
+ const enumTypeInfo = {
99
102
  enumObj: enumMetadata.enumObj,
100
103
  type: new graphql_1.GraphQLEnumType({
101
104
  name: enumMetadata.name,
@@ -111,8 +114,9 @@ class SchemaGenerator {
111
114
  }, {}),
112
115
  }),
113
116
  };
114
- });
115
- this.objectTypesInfo = this.metadataStorage.objectTypes.map(objectType => {
117
+ return [enumMetadata.enumObj, enumTypeInfo];
118
+ }));
119
+ this.objectTypesInfoMap = new Map(this.metadataStorage.objectTypes.map(objectType => {
116
120
  const objectSuperClass = Object.getPrototypeOf(objectType.target);
117
121
  const hasExtended = objectSuperClass.prototype !== undefined;
118
122
  const getSuperClassType = () => {
@@ -197,21 +201,20 @@ class SchemaGenerator {
197
201
  },
198
202
  }),
199
203
  };
200
- this.objectTypesInfoMap.set(objectType.target, objectTypeInfo);
201
- return objectTypeInfo;
202
- });
203
- this.interfaceTypesInfo = this.metadataStorage.interfaceTypes.map(interfaceType => {
204
+ return [objectType.target, objectTypeInfo];
205
+ }));
206
+ this.interfaceTypesInfoMap = new Map(this.metadataStorage.interfaceTypes.map(interfaceType => {
204
207
  const interfaceSuperClass = Object.getPrototypeOf(interfaceType.target);
205
208
  const hasExtended = interfaceSuperClass.prototype !== undefined;
206
209
  const getSuperClassType = () => {
207
- const superClassTypeInfo = this.interfaceTypesInfo.find(type => type.target === interfaceSuperClass);
210
+ const superClassTypeInfo = this.interfaceTypesInfoMap.get(interfaceSuperClass);
208
211
  return superClassTypeInfo ? superClassTypeInfo.type : undefined;
209
212
  };
210
213
  const implementingObjectTypesTargets = this.metadataStorage.objectTypes
211
214
  .filter(objectType => objectType.interfaceClasses &&
212
215
  objectType.interfaceClasses.includes(interfaceType.target))
213
216
  .map(objectType => objectType.target);
214
- const implementingObjectTypesInfo = this.objectTypesInfo.filter(objectTypesInfo => implementingObjectTypesTargets.includes(objectTypesInfo.target));
217
+ const implementingObjectTypesInfo = [...this.objectTypesInfoMap.values()].filter(objectTypesInfo => implementingObjectTypesTargets.includes(objectTypesInfo.target));
215
218
  const interfaceTypeInfo = {
216
219
  metadata: interfaceType,
217
220
  target: interfaceType.target,
@@ -281,10 +284,9 @@ class SchemaGenerator {
281
284
  },
282
285
  }),
283
286
  };
284
- this.interfaceTypesInfoMap.set(interfaceType.target, interfaceTypeInfo);
285
- return interfaceTypeInfo;
286
- });
287
- this.inputTypesInfo = this.metadataStorage.inputTypes.map(inputType => {
287
+ return [interfaceType.target, interfaceTypeInfo];
288
+ }));
289
+ this.inputTypesInfoMap = new Map(this.metadataStorage.inputTypes.map(inputType => {
288
290
  const objectSuperClass = Object.getPrototypeOf(inputType.target);
289
291
  const getSuperClassType = () => {
290
292
  const superClassTypeInfo = this.inputTypesInfoMap.get(objectSuperClass);
@@ -326,9 +328,8 @@ class SchemaGenerator {
326
328
  astNode: (0, definition_node_1.getInputObjectTypeDefinitionNode)(inputType.name, inputType.directives),
327
329
  }),
328
330
  };
329
- this.inputTypesInfoMap.set(inputType.target, inputTypeInfo);
330
- return inputTypeInfo;
331
- });
331
+ return [inputType.target, inputTypeInfo];
332
+ }));
332
333
  }
333
334
  static buildRootQueryType(resolvers) {
334
335
  const queriesHandlers = this.filterHandlersByResolvers(this.metadataStorage.queries, resolvers);
@@ -358,8 +359,8 @@ class SchemaGenerator {
358
359
  });
359
360
  }
360
361
  static buildOtherTypes(orphanedTypes) {
361
- const autoRegisteredObjectTypesInfo = this.objectTypesInfo.filter(typeInfo => typeInfo.metadata.interfaceClasses?.some(interfaceClass => {
362
- const implementedInterfaceInfo = this.interfaceTypesInfo.find(it => it.target === interfaceClass);
362
+ const autoRegisteredObjectTypesInfo = [...this.objectTypesInfoMap.values()].filter(typeInfo => typeInfo.metadata.interfaceClasses?.some(interfaceClass => {
363
+ const implementedInterfaceInfo = this.interfaceTypesInfoMap.get(interfaceClass);
363
364
  if (!implementedInterfaceInfo) {
364
365
  return false;
365
366
  }
@@ -372,9 +373,9 @@ class SchemaGenerator {
372
373
  return true;
373
374
  }));
374
375
  return [
375
- ...this.filterTypesInfoByOrphanedTypesAndExtractType(this.objectTypesInfo, orphanedTypes),
376
- ...this.filterTypesInfoByOrphanedTypesAndExtractType(this.interfaceTypesInfo, orphanedTypes),
377
- ...this.filterTypesInfoByOrphanedTypesAndExtractType(this.inputTypesInfo, orphanedTypes),
376
+ ...this.filterTypesInfoByOrphanedTypesAndExtractType([...this.objectTypesInfoMap.values()], orphanedTypes),
377
+ ...this.filterTypesInfoByOrphanedTypesAndExtractType([...this.interfaceTypesInfoMap.values()], orphanedTypes),
378
+ ...this.filterTypesInfoByOrphanedTypesAndExtractType([...this.inputTypesInfoMap.values()], orphanedTypes),
378
379
  ...autoRegisteredObjectTypesInfo.map(typeInfo => typeInfo.type),
379
380
  ];
380
381
  }
@@ -510,26 +511,26 @@ class SchemaGenerator {
510
511
  let gqlType;
511
512
  gqlType = (0, types_1.convertTypeIfScalar)(type);
512
513
  if (!gqlType) {
513
- const objectType = this.objectTypesInfo.find(it => it.target === type);
514
+ const objectType = this.objectTypesInfoMap.get(type);
514
515
  if (objectType) {
515
516
  gqlType = objectType.type;
516
517
  }
517
518
  }
518
519
  if (!gqlType) {
519
- const interfaceType = this.interfaceTypesInfo.find(it => it.target === type);
520
+ const interfaceType = this.interfaceTypesInfoMap.get(type);
520
521
  if (interfaceType) {
521
522
  this.usedInterfaceTypes.add(interfaceType.target);
522
523
  gqlType = interfaceType.type;
523
524
  }
524
525
  }
525
526
  if (!gqlType) {
526
- const enumType = this.enumTypesInfo.find(it => it.enumObj === type);
527
+ const enumType = this.enumTypesInfoMap.get(type);
527
528
  if (enumType) {
528
529
  gqlType = enumType.type;
529
530
  }
530
531
  }
531
532
  if (!gqlType) {
532
- const unionType = this.unionTypesInfo.find(it => it.unionSymbol === type);
533
+ const unionType = this.unionTypesInfoMap.get(type);
533
534
  if (unionType) {
534
535
  gqlType = unionType.type;
535
536
  }
@@ -544,13 +545,13 @@ class SchemaGenerator {
544
545
  let gqlType;
545
546
  gqlType = (0, types_1.convertTypeIfScalar)(type);
546
547
  if (!gqlType) {
547
- const inputType = this.inputTypesInfo.find(it => it.target === type);
548
+ const inputType = this.inputTypesInfoMap.get(type);
548
549
  if (inputType) {
549
550
  gqlType = inputType.type;
550
551
  }
551
552
  }
552
553
  if (!gqlType) {
553
- const enumType = this.enumTypesInfo.find(it => it.enumObj === type);
554
+ const enumType = this.enumTypesInfoMap.get(type);
554
555
  if (enumType) {
555
556
  gqlType = enumType.type;
556
557
  }
@@ -579,13 +580,9 @@ class SchemaGenerator {
579
580
  }
580
581
  }
581
582
  exports.SchemaGenerator = SchemaGenerator;
582
- SchemaGenerator.objectTypesInfo = [];
583
583
  SchemaGenerator.objectTypesInfoMap = new Map();
584
- SchemaGenerator.inputTypesInfo = [];
585
584
  SchemaGenerator.inputTypesInfoMap = new Map();
586
- SchemaGenerator.interfaceTypesInfo = [];
587
585
  SchemaGenerator.interfaceTypesInfoMap = new Map();
588
- SchemaGenerator.enumTypesInfo = [];
589
- SchemaGenerator.unionTypesInfo = [];
586
+ SchemaGenerator.enumTypesInfoMap = new Map();
590
587
  SchemaGenerator.unionTypesInfoMap = new Map();
591
588
  SchemaGenerator.usedInterfaceTypes = new Set();
@@ -108,6 +108,7 @@ export class MetadataStorage {
108
108
  this.fieldExtensions.push(definition);
109
109
  }
110
110
  initCache() {
111
+ this.clearMapCaches();
111
112
  if (this.resolverClasses?.length) {
112
113
  this.resolverClasses.forEach(resolverClass => {
113
114
  if (!this.resolverClassesCache.has(resolverClass.target)) {
@@ -257,6 +258,38 @@ export class MetadataStorage {
257
258
  this.argumentDirectives = [];
258
259
  this.classExtensions = [];
259
260
  this.fieldExtensions = [];
261
+ this.resolverClasses = [];
262
+ this.fields = [];
263
+ this.params = [];
264
+ this.clearMapCaches();
265
+ }
266
+ clone() {
267
+ const cloned = new MetadataStorage();
268
+ cloned.queries = [...this.queries];
269
+ cloned.mutations = [...this.mutations];
270
+ cloned.subscriptions = [...this.subscriptions];
271
+ cloned.fieldResolvers = [...this.fieldResolvers];
272
+ cloned.objectTypes = [...this.objectTypes];
273
+ cloned.inputTypes = [...this.inputTypes];
274
+ cloned.argumentTypes = [...this.argumentTypes];
275
+ cloned.interfaceTypes = [...this.interfaceTypes];
276
+ cloned.authorizedFields = [...this.authorizedFields];
277
+ cloned.authorizedResolver = [...this.authorizedResolver];
278
+ cloned.enums = [...this.enums];
279
+ cloned.unions = [...this.unions];
280
+ cloned.middlewares = [...this.middlewares];
281
+ cloned.resolverMiddlewares = [...this.resolverMiddlewares];
282
+ cloned.classDirectives = [...this.classDirectives];
283
+ cloned.fieldDirectives = [...this.fieldDirectives];
284
+ cloned.argumentDirectives = [...this.argumentDirectives];
285
+ cloned.classExtensions = [...this.classExtensions];
286
+ cloned.fieldExtensions = [...this.fieldExtensions];
287
+ cloned.resolverClasses = [...this.resolverClasses];
288
+ cloned.fields = [...this.fields];
289
+ cloned.params = [...this.params];
290
+ return cloned;
291
+ }
292
+ clearMapCaches() {
260
293
  this.fieldsCache = new Map();
261
294
  this.objectTypesCache = new Map();
262
295
  this.interfaceTypesCache = new Map();
@@ -268,9 +301,6 @@ export class MetadataStorage {
268
301
  this.authorizedFieldsByTargetAndFieldCache = new Map();
269
302
  this.authorizedResolverByTargetCache = new Map();
270
303
  this.resolverClassesCache = new Map();
271
- this.resolverClasses = [];
272
- this.fields = [];
273
- this.params = [];
274
304
  }
275
305
  buildClassMetadata(definitions) {
276
306
  definitions.forEach(def => {
@@ -3,7 +3,6 @@ import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLO
3
3
  import { CannotDetermineGraphQLTypeError, ConflictingDefaultValuesError, GeneratingSchemaError, InterfaceResolveTypeError, MissingPubSubError, MissingSubscriptionTopicsError, UnionResolveTypeError, } from "../errors/index.js";
4
4
  import { convertTypeIfScalar, getEnumValuesMap, wrapWithTypeOptions } from "../helpers/types.js";
5
5
  import { getMetadataStorage } from "../metadata/getMetadataStorage.js";
6
- import { MetadataStorage } from "../metadata/metadata-storage.js";
7
6
  import { createAdvancedFieldResolver, createBasicFieldResolver, createHandlerResolver, wrapResolverWithAuthChecker, } from "../resolvers/create.js";
8
7
  import { ensureInstalledCorrectGraphQLPackage } from "../utils/graphql-version.js";
9
8
  import { BuildContext } from "./build-context.js";
@@ -11,7 +10,7 @@ import { getFieldDefinitionNode, getInputObjectTypeDefinitionNode, getInputValue
11
10
  import { getFieldMetadataFromInputType, getFieldMetadataFromObjectType } from "./utils.js";
12
11
  export class SchemaGenerator {
13
12
  static generateFromMetadata(options) {
14
- this.metadataStorage = Object.assign(new MetadataStorage(), getMetadataStorage());
13
+ this.metadataStorage = getMetadataStorage().clone();
15
14
  this.metadataStorage.build(options);
16
15
  this.checkForErrors(options);
17
16
  BuildContext.create(options);
@@ -29,6 +28,11 @@ export class SchemaGenerator {
29
28
  });
30
29
  BuildContext.reset();
31
30
  this.usedInterfaceTypes = new Set();
31
+ this.objectTypesInfoMap = new Map();
32
+ this.inputTypesInfoMap = new Map();
33
+ this.interfaceTypesInfoMap = new Map();
34
+ this.enumTypesInfoMap = new Map();
35
+ this.unionTypesInfoMap = new Map();
32
36
  if (!options.skipCheck) {
33
37
  const { errors } = graphqlSync({ schema: finalSchema, source: getIntrospectionQuery() });
34
38
  if (errors) {
@@ -59,7 +63,7 @@ export class SchemaGenerator {
59
63
  : defaultValueFromInitializer;
60
64
  }
61
65
  static buildTypesInfo(resolvers) {
62
- this.unionTypesInfo = this.metadataStorage.unions.map(unionMetadata => {
66
+ this.unionTypesInfoMap = new Map(this.metadataStorage.unions.map(unionMetadata => {
63
67
  const unionObjectTypesInfo = [];
64
68
  const typesThunk = () => {
65
69
  unionObjectTypesInfo.push(...unionMetadata
@@ -87,12 +91,11 @@ export class SchemaGenerator {
87
91
  },
88
92
  }),
89
93
  };
90
- this.unionTypesInfoMap.set(unionMetadata.symbol, unionTypeInfo);
91
- return unionTypeInfo;
92
- });
93
- this.enumTypesInfo = this.metadataStorage.enums.map(enumMetadata => {
94
+ return [unionMetadata.symbol, unionTypeInfo];
95
+ }));
96
+ this.enumTypesInfoMap = new Map(this.metadataStorage.enums.map(enumMetadata => {
94
97
  const enumMap = getEnumValuesMap(enumMetadata.enumObj);
95
- return {
98
+ const enumTypeInfo = {
96
99
  enumObj: enumMetadata.enumObj,
97
100
  type: new GraphQLEnumType({
98
101
  name: enumMetadata.name,
@@ -108,8 +111,9 @@ export class SchemaGenerator {
108
111
  }, {}),
109
112
  }),
110
113
  };
111
- });
112
- this.objectTypesInfo = this.metadataStorage.objectTypes.map(objectType => {
114
+ return [enumMetadata.enumObj, enumTypeInfo];
115
+ }));
116
+ this.objectTypesInfoMap = new Map(this.metadataStorage.objectTypes.map(objectType => {
113
117
  const objectSuperClass = Object.getPrototypeOf(objectType.target);
114
118
  const hasExtended = objectSuperClass.prototype !== undefined;
115
119
  const getSuperClassType = () => {
@@ -194,21 +198,20 @@ export class SchemaGenerator {
194
198
  },
195
199
  }),
196
200
  };
197
- this.objectTypesInfoMap.set(objectType.target, objectTypeInfo);
198
- return objectTypeInfo;
199
- });
200
- this.interfaceTypesInfo = this.metadataStorage.interfaceTypes.map(interfaceType => {
201
+ return [objectType.target, objectTypeInfo];
202
+ }));
203
+ this.interfaceTypesInfoMap = new Map(this.metadataStorage.interfaceTypes.map(interfaceType => {
201
204
  const interfaceSuperClass = Object.getPrototypeOf(interfaceType.target);
202
205
  const hasExtended = interfaceSuperClass.prototype !== undefined;
203
206
  const getSuperClassType = () => {
204
- const superClassTypeInfo = this.interfaceTypesInfo.find(type => type.target === interfaceSuperClass);
207
+ const superClassTypeInfo = this.interfaceTypesInfoMap.get(interfaceSuperClass);
205
208
  return superClassTypeInfo ? superClassTypeInfo.type : undefined;
206
209
  };
207
210
  const implementingObjectTypesTargets = this.metadataStorage.objectTypes
208
211
  .filter(objectType => objectType.interfaceClasses &&
209
212
  objectType.interfaceClasses.includes(interfaceType.target))
210
213
  .map(objectType => objectType.target);
211
- const implementingObjectTypesInfo = this.objectTypesInfo.filter(objectTypesInfo => implementingObjectTypesTargets.includes(objectTypesInfo.target));
214
+ const implementingObjectTypesInfo = [...this.objectTypesInfoMap.values()].filter(objectTypesInfo => implementingObjectTypesTargets.includes(objectTypesInfo.target));
212
215
  const interfaceTypeInfo = {
213
216
  metadata: interfaceType,
214
217
  target: interfaceType.target,
@@ -278,10 +281,9 @@ export class SchemaGenerator {
278
281
  },
279
282
  }),
280
283
  };
281
- this.interfaceTypesInfoMap.set(interfaceType.target, interfaceTypeInfo);
282
- return interfaceTypeInfo;
283
- });
284
- this.inputTypesInfo = this.metadataStorage.inputTypes.map(inputType => {
284
+ return [interfaceType.target, interfaceTypeInfo];
285
+ }));
286
+ this.inputTypesInfoMap = new Map(this.metadataStorage.inputTypes.map(inputType => {
285
287
  const objectSuperClass = Object.getPrototypeOf(inputType.target);
286
288
  const getSuperClassType = () => {
287
289
  const superClassTypeInfo = this.inputTypesInfoMap.get(objectSuperClass);
@@ -323,9 +325,8 @@ export class SchemaGenerator {
323
325
  astNode: getInputObjectTypeDefinitionNode(inputType.name, inputType.directives),
324
326
  }),
325
327
  };
326
- this.inputTypesInfoMap.set(inputType.target, inputTypeInfo);
327
- return inputTypeInfo;
328
- });
328
+ return [inputType.target, inputTypeInfo];
329
+ }));
329
330
  }
330
331
  static buildRootQueryType(resolvers) {
331
332
  const queriesHandlers = this.filterHandlersByResolvers(this.metadataStorage.queries, resolvers);
@@ -355,8 +356,8 @@ export class SchemaGenerator {
355
356
  });
356
357
  }
357
358
  static buildOtherTypes(orphanedTypes) {
358
- const autoRegisteredObjectTypesInfo = this.objectTypesInfo.filter(typeInfo => typeInfo.metadata.interfaceClasses?.some(interfaceClass => {
359
- const implementedInterfaceInfo = this.interfaceTypesInfo.find(it => it.target === interfaceClass);
359
+ const autoRegisteredObjectTypesInfo = [...this.objectTypesInfoMap.values()].filter(typeInfo => typeInfo.metadata.interfaceClasses?.some(interfaceClass => {
360
+ const implementedInterfaceInfo = this.interfaceTypesInfoMap.get(interfaceClass);
360
361
  if (!implementedInterfaceInfo) {
361
362
  return false;
362
363
  }
@@ -369,9 +370,9 @@ export class SchemaGenerator {
369
370
  return true;
370
371
  }));
371
372
  return [
372
- ...this.filterTypesInfoByOrphanedTypesAndExtractType(this.objectTypesInfo, orphanedTypes),
373
- ...this.filterTypesInfoByOrphanedTypesAndExtractType(this.interfaceTypesInfo, orphanedTypes),
374
- ...this.filterTypesInfoByOrphanedTypesAndExtractType(this.inputTypesInfo, orphanedTypes),
373
+ ...this.filterTypesInfoByOrphanedTypesAndExtractType([...this.objectTypesInfoMap.values()], orphanedTypes),
374
+ ...this.filterTypesInfoByOrphanedTypesAndExtractType([...this.interfaceTypesInfoMap.values()], orphanedTypes),
375
+ ...this.filterTypesInfoByOrphanedTypesAndExtractType([...this.inputTypesInfoMap.values()], orphanedTypes),
375
376
  ...autoRegisteredObjectTypesInfo.map(typeInfo => typeInfo.type),
376
377
  ];
377
378
  }
@@ -507,26 +508,26 @@ export class SchemaGenerator {
507
508
  let gqlType;
508
509
  gqlType = convertTypeIfScalar(type);
509
510
  if (!gqlType) {
510
- const objectType = this.objectTypesInfo.find(it => it.target === type);
511
+ const objectType = this.objectTypesInfoMap.get(type);
511
512
  if (objectType) {
512
513
  gqlType = objectType.type;
513
514
  }
514
515
  }
515
516
  if (!gqlType) {
516
- const interfaceType = this.interfaceTypesInfo.find(it => it.target === type);
517
+ const interfaceType = this.interfaceTypesInfoMap.get(type);
517
518
  if (interfaceType) {
518
519
  this.usedInterfaceTypes.add(interfaceType.target);
519
520
  gqlType = interfaceType.type;
520
521
  }
521
522
  }
522
523
  if (!gqlType) {
523
- const enumType = this.enumTypesInfo.find(it => it.enumObj === type);
524
+ const enumType = this.enumTypesInfoMap.get(type);
524
525
  if (enumType) {
525
526
  gqlType = enumType.type;
526
527
  }
527
528
  }
528
529
  if (!gqlType) {
529
- const unionType = this.unionTypesInfo.find(it => it.unionSymbol === type);
530
+ const unionType = this.unionTypesInfoMap.get(type);
530
531
  if (unionType) {
531
532
  gqlType = unionType.type;
532
533
  }
@@ -541,13 +542,13 @@ export class SchemaGenerator {
541
542
  let gqlType;
542
543
  gqlType = convertTypeIfScalar(type);
543
544
  if (!gqlType) {
544
- const inputType = this.inputTypesInfo.find(it => it.target === type);
545
+ const inputType = this.inputTypesInfoMap.get(type);
545
546
  if (inputType) {
546
547
  gqlType = inputType.type;
547
548
  }
548
549
  }
549
550
  if (!gqlType) {
550
- const enumType = this.enumTypesInfo.find(it => it.enumObj === type);
551
+ const enumType = this.enumTypesInfoMap.get(type);
551
552
  if (enumType) {
552
553
  gqlType = enumType.type;
553
554
  }
@@ -575,13 +576,9 @@ export class SchemaGenerator {
575
576
  return typesInfo.filter(it => orphanedTypes.includes(it.target)).map(it => it.type);
576
577
  }
577
578
  }
578
- SchemaGenerator.objectTypesInfo = [];
579
579
  SchemaGenerator.objectTypesInfoMap = new Map();
580
- SchemaGenerator.inputTypesInfo = [];
581
580
  SchemaGenerator.inputTypesInfoMap = new Map();
582
- SchemaGenerator.interfaceTypesInfo = [];
583
581
  SchemaGenerator.interfaceTypesInfoMap = new Map();
584
- SchemaGenerator.enumTypesInfo = [];
585
- SchemaGenerator.unionTypesInfo = [];
582
+ SchemaGenerator.enumTypesInfoMap = new Map();
586
583
  SchemaGenerator.unionTypesInfoMap = new Map();
587
584
  SchemaGenerator.usedInterfaceTypes = new Set();
@@ -62,6 +62,8 @@ export declare class MetadataStorage {
62
62
  initCache(): void;
63
63
  build(options: SchemaGeneratorOptions): void;
64
64
  clear(): void;
65
+ clone(): MetadataStorage;
66
+ private clearMapCaches;
65
67
  private buildClassMetadata;
66
68
  private buildResolversMetadata;
67
69
  private buildFieldResolverMetadata;
@@ -19,14 +19,10 @@ export type SchemaGeneratorOptions = {
19
19
  directives?: GraphQLDirective[];
20
20
  } & BuildContextOptions;
21
21
  export declare abstract class SchemaGenerator {
22
- private static objectTypesInfo;
23
22
  private static objectTypesInfoMap;
24
- private static inputTypesInfo;
25
23
  private static inputTypesInfoMap;
26
- private static interfaceTypesInfo;
27
24
  private static interfaceTypesInfoMap;
28
- private static enumTypesInfo;
29
- private static unionTypesInfo;
25
+ private static enumTypesInfoMap;
30
26
  private static unionTypesInfoMap;
31
27
  private static usedInterfaceTypes;
32
28
  private static metadataStorage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-graphql",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.4",
4
4
  "private": false,
5
5
  "description": "Create GraphQL schema and resolvers with TypeScript, using classes and decorators!",
6
6
  "keywords": [