@graphql-tools/load 7.1.2-alpha-a15676c3.0 → 7.1.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/es5/index.js CHANGED
@@ -68,16 +68,15 @@ function applyDefaultOptions(options) {
68
68
  }
69
69
 
70
70
  function loadFile(pointer, options) {
71
+ var _a;
71
72
  return tslib.__awaiter(this, void 0, void 0, function () {
72
- var cached, results;
73
+ var results;
73
74
  var _this = this;
74
- return tslib.__generator(this, function (_a) {
75
- switch (_a.label) {
75
+ return tslib.__generator(this, function (_b) {
76
+ switch (_b.label) {
76
77
  case 0:
77
- cached = useCache({ pointer: pointer, options: options });
78
- if (cached) {
79
- return [2 /*return*/, cached];
80
- }
78
+ results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
79
+ if (!!results) return [3 /*break*/, 2];
81
80
  results = [];
82
81
  return [4 /*yield*/, Promise.all(options.loaders.map(function (loader) { return tslib.__awaiter(_this, void 0, void 0, function () {
83
82
  var loaderResults, error_1;
@@ -101,50 +100,51 @@ function loadFile(pointer, options) {
101
100
  });
102
101
  }); }))];
103
102
  case 1:
104
- _a.sent();
105
- return [2 /*return*/, results];
103
+ _b.sent();
104
+ if (options.cache) {
105
+ options.cache[pointer] = results;
106
+ }
107
+ _b.label = 2;
108
+ case 2: return [2 /*return*/, results];
106
109
  }
107
110
  });
108
111
  });
109
112
  }
110
113
  function loadFileSync(pointer, options) {
111
114
  var e_1, _a;
112
- var cached = useCache({ pointer: pointer, options: options });
113
- if (cached) {
114
- return cached;
115
- }
116
- var results = [];
117
- try {
118
- for (var _b = tslib.__values(options.loaders), _c = _b.next(); !_c.done; _c = _b.next()) {
119
- var loader = _c.value;
120
- try {
121
- // We check for the existence so it is okay to force non null
122
- var loaderResults = loader.loadSync(pointer, options);
123
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(function (result) { return results.push(result); });
124
- }
125
- catch (error) {
126
- if (process.env['DEBUG']) {
127
- console.error("Failed to find any GraphQL type definitions in: " + pointer + " - " + error.message);
115
+ var _b;
116
+ var results = (_b = options.cache) === null || _b === void 0 ? void 0 : _b[pointer];
117
+ if (!results) {
118
+ results = [];
119
+ try {
120
+ for (var _c = tslib.__values(options.loaders), _d = _c.next(); !_d.done; _d = _c.next()) {
121
+ var loader = _d.value;
122
+ try {
123
+ // We check for the existence so it is okay to force non null
124
+ var loaderResults = loader.loadSync(pointer, options);
125
+ loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(function (result) { return results.push(result); });
126
+ }
127
+ catch (error) {
128
+ if (process.env['DEBUG']) {
129
+ console.error("Failed to find any GraphQL type definitions in: " + pointer + " - " + error.message);
130
+ }
131
+ throw error;
128
132
  }
129
- throw error;
130
133
  }
131
134
  }
132
- }
133
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
134
- finally {
135
- try {
136
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
135
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
136
+ finally {
137
+ try {
138
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
139
+ }
140
+ finally { if (e_1) throw e_1.error; }
141
+ }
142
+ if (options.cache) {
143
+ options.cache[pointer] = results;
137
144
  }
138
- finally { if (e_1) throw e_1.error; }
139
145
  }
140
146
  return results;
141
147
  }
142
- function useCache(_a) {
143
- var pointer = _a.pointer, options = _a.options;
144
- if (options['cache']) {
145
- return options['cache'][pointer];
146
- }
147
- }
148
148
 
149
149
  /**
150
150
  * Converts a string to 32bit integer
@@ -291,7 +291,6 @@ function collectSources(_a) {
291
291
  queue = useQueue({ concurrency: CONCURRENCY_LIMIT });
292
292
  _b = createHelpers({
293
293
  sources: sources,
294
- options: options,
295
294
  stack: [collectDocumentString, collectCustomLoader, collectFallback],
296
295
  }), addSource = _b.addSource, collect = _b.collect;
297
296
  for (pointer in pointerOptionMap) {
@@ -319,7 +318,6 @@ function collectSourcesSync(_a) {
319
318
  var queue = useSyncQueue();
320
319
  var _b = createHelpers({
321
320
  sources: sources,
322
- options: options,
323
321
  stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
324
322
  }), addSource = _b.addSource, collect = _b.collect;
325
323
  for (var pointer in pointerOptionMap) {
@@ -337,13 +335,10 @@ function collectSourcesSync(_a) {
337
335
  return sources;
338
336
  }
339
337
  function createHelpers(_a) {
340
- var sources = _a.sources, options = _a.options, stack = _a.stack;
338
+ var sources = _a.sources, stack = _a.stack;
341
339
  var addSource = function (_a) {
342
- var pointer = _a.pointer, source = _a.source, noCache = _a.noCache;
340
+ var source = _a.source;
343
341
  sources.push(source);
344
- if (!noCache && options.cache) {
345
- options.cache[pointer] = source;
346
- }
347
342
  };
348
343
  var collect = useStack.apply(void 0, tslib.__spreadArray([], tslib.__read(stack)));
349
344
  return {
package/es5/index.mjs CHANGED
@@ -62,16 +62,15 @@ function applyDefaultOptions(options) {
62
62
  }
63
63
 
64
64
  function loadFile(pointer, options) {
65
+ var _a;
65
66
  return __awaiter(this, void 0, void 0, function () {
66
- var cached, results;
67
+ var results;
67
68
  var _this = this;
68
- return __generator(this, function (_a) {
69
- switch (_a.label) {
69
+ return __generator(this, function (_b) {
70
+ switch (_b.label) {
70
71
  case 0:
71
- cached = useCache({ pointer: pointer, options: options });
72
- if (cached) {
73
- return [2 /*return*/, cached];
74
- }
72
+ results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
73
+ if (!!results) return [3 /*break*/, 2];
75
74
  results = [];
76
75
  return [4 /*yield*/, Promise.all(options.loaders.map(function (loader) { return __awaiter(_this, void 0, void 0, function () {
77
76
  var loaderResults, error_1;
@@ -95,50 +94,51 @@ function loadFile(pointer, options) {
95
94
  });
96
95
  }); }))];
97
96
  case 1:
98
- _a.sent();
99
- return [2 /*return*/, results];
97
+ _b.sent();
98
+ if (options.cache) {
99
+ options.cache[pointer] = results;
100
+ }
101
+ _b.label = 2;
102
+ case 2: return [2 /*return*/, results];
100
103
  }
101
104
  });
102
105
  });
103
106
  }
104
107
  function loadFileSync(pointer, options) {
105
108
  var e_1, _a;
106
- var cached = useCache({ pointer: pointer, options: options });
107
- if (cached) {
108
- return cached;
109
- }
110
- var results = [];
111
- try {
112
- for (var _b = __values(options.loaders), _c = _b.next(); !_c.done; _c = _b.next()) {
113
- var loader = _c.value;
114
- try {
115
- // We check for the existence so it is okay to force non null
116
- var loaderResults = loader.loadSync(pointer, options);
117
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(function (result) { return results.push(result); });
118
- }
119
- catch (error) {
120
- if (env['DEBUG']) {
121
- console.error("Failed to find any GraphQL type definitions in: " + pointer + " - " + error.message);
109
+ var _b;
110
+ var results = (_b = options.cache) === null || _b === void 0 ? void 0 : _b[pointer];
111
+ if (!results) {
112
+ results = [];
113
+ try {
114
+ for (var _c = __values(options.loaders), _d = _c.next(); !_d.done; _d = _c.next()) {
115
+ var loader = _d.value;
116
+ try {
117
+ // We check for the existence so it is okay to force non null
118
+ var loaderResults = loader.loadSync(pointer, options);
119
+ loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(function (result) { return results.push(result); });
120
+ }
121
+ catch (error) {
122
+ if (env['DEBUG']) {
123
+ console.error("Failed to find any GraphQL type definitions in: " + pointer + " - " + error.message);
124
+ }
125
+ throw error;
122
126
  }
123
- throw error;
124
127
  }
125
128
  }
126
- }
127
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
128
- finally {
129
- try {
130
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
129
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
130
+ finally {
131
+ try {
132
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
133
+ }
134
+ finally { if (e_1) throw e_1.error; }
135
+ }
136
+ if (options.cache) {
137
+ options.cache[pointer] = results;
131
138
  }
132
- finally { if (e_1) throw e_1.error; }
133
139
  }
134
140
  return results;
135
141
  }
136
- function useCache(_a) {
137
- var pointer = _a.pointer, options = _a.options;
138
- if (options['cache']) {
139
- return options['cache'][pointer];
140
- }
141
- }
142
142
 
143
143
  /**
144
144
  * Converts a string to 32bit integer
@@ -285,7 +285,6 @@ function collectSources(_a) {
285
285
  queue = useQueue({ concurrency: CONCURRENCY_LIMIT });
286
286
  _b = createHelpers({
287
287
  sources: sources,
288
- options: options,
289
288
  stack: [collectDocumentString, collectCustomLoader, collectFallback],
290
289
  }), addSource = _b.addSource, collect = _b.collect;
291
290
  for (pointer in pointerOptionMap) {
@@ -313,7 +312,6 @@ function collectSourcesSync(_a) {
313
312
  var queue = useSyncQueue();
314
313
  var _b = createHelpers({
315
314
  sources: sources,
316
- options: options,
317
315
  stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
318
316
  }), addSource = _b.addSource, collect = _b.collect;
319
317
  for (var pointer in pointerOptionMap) {
@@ -331,13 +329,10 @@ function collectSourcesSync(_a) {
331
329
  return sources;
332
330
  }
333
331
  function createHelpers(_a) {
334
- var sources = _a.sources, options = _a.options, stack = _a.stack;
332
+ var sources = _a.sources, stack = _a.stack;
335
333
  var addSource = function (_a) {
336
- var pointer = _a.pointer, source = _a.source, noCache = _a.noCache;
334
+ var source = _a.source;
337
335
  sources.push(source);
338
- if (!noCache && options.cache) {
339
- options.cache[pointer] = source;
340
- }
341
336
  };
342
337
  var collect = useStack.apply(void 0, __spreadArray([], __read(stack)));
343
338
  return {
@@ -3,7 +3,7 @@ export declare type LoadTypedefsOptions<ExtraConfig = {
3
3
  [key: string]: any;
4
4
  }> = BaseLoaderOptions & ExtraConfig & {
5
5
  cache?: {
6
- [key: string]: Source;
6
+ [key: string]: Source[];
7
7
  };
8
8
  loaders: Loader[];
9
9
  filterKinds?: string[];
package/es5/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-tools/load/es5",
3
- "version": "7.1.2-alpha-a15676c3.0",
3
+ "version": "7.1.4",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/merge": "7.0.0-alpha-a15676c3.0",
10
+ "@graphql-tools/merge": "^7.0.0",
11
11
  "@graphql-tools/utils": "8.0.2",
12
12
  "import-from": "4.0.0",
13
13
  "p-limit": "3.1.0",
package/index.js CHANGED
@@ -45,51 +45,52 @@ function applyDefaultOptions(options) {
45
45
  }
46
46
 
47
47
  async function loadFile(pointer, options) {
48
- const cached = useCache({ pointer, options });
49
- if (cached) {
50
- return cached;
51
- }
52
- const results = [];
53
- await Promise.all(options.loaders.map(async (loader) => {
54
- try {
55
- const loaderResults = await loader.load(pointer, options);
56
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
57
- }
58
- catch (error) {
59
- if (process.env['DEBUG']) {
60
- console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
48
+ var _a;
49
+ let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
50
+ if (!results) {
51
+ results = [];
52
+ await Promise.all(options.loaders.map(async (loader) => {
53
+ try {
54
+ const loaderResults = await loader.load(pointer, options);
55
+ loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
56
+ }
57
+ catch (error) {
58
+ if (process.env['DEBUG']) {
59
+ console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
60
+ }
61
+ throw error;
61
62
  }
62
- throw error;
63
+ }));
64
+ if (options.cache) {
65
+ options.cache[pointer] = results;
63
66
  }
64
- }));
67
+ }
65
68
  return results;
66
69
  }
67
70
  function loadFileSync(pointer, options) {
68
- const cached = useCache({ pointer, options });
69
- if (cached) {
70
- return cached;
71
- }
72
- const results = [];
73
- for (const loader of options.loaders) {
74
- try {
75
- // We check for the existence so it is okay to force non null
76
- const loaderResults = loader.loadSync(pointer, options);
77
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
78
- }
79
- catch (error) {
80
- if (process.env['DEBUG']) {
81
- console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
71
+ var _a;
72
+ let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
73
+ if (!results) {
74
+ results = [];
75
+ for (const loader of options.loaders) {
76
+ try {
77
+ // We check for the existence so it is okay to force non null
78
+ const loaderResults = loader.loadSync(pointer, options);
79
+ loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
80
+ }
81
+ catch (error) {
82
+ if (process.env['DEBUG']) {
83
+ console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
84
+ }
85
+ throw error;
82
86
  }
83
- throw error;
87
+ }
88
+ if (options.cache) {
89
+ options.cache[pointer] = results;
84
90
  }
85
91
  }
86
92
  return results;
87
93
  }
88
- function useCache({ pointer, options }) {
89
- if (options['cache']) {
90
- return options['cache'][pointer];
91
- }
92
- }
93
94
 
94
95
  /**
95
96
  * Converts a string to 32bit integer
@@ -200,7 +201,6 @@ async function collectSources({ pointerOptionMap, options, }) {
200
201
  const queue = useQueue({ concurrency: CONCURRENCY_LIMIT });
201
202
  const { addSource, collect } = createHelpers({
202
203
  sources,
203
- options,
204
204
  stack: [collectDocumentString, collectCustomLoader, collectFallback],
205
205
  });
206
206
  for (const pointer in pointerOptionMap) {
@@ -222,7 +222,6 @@ function collectSourcesSync({ pointerOptionMap, options, }) {
222
222
  const queue = useSyncQueue();
223
223
  const { addSource, collect } = createHelpers({
224
224
  sources,
225
- options,
226
225
  stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
227
226
  });
228
227
  for (const pointer in pointerOptionMap) {
@@ -239,12 +238,9 @@ function collectSourcesSync({ pointerOptionMap, options, }) {
239
238
  queue.runAll();
240
239
  return sources;
241
240
  }
242
- function createHelpers({ sources, options, stack, }) {
243
- const addSource = ({ pointer, source, noCache, }) => {
241
+ function createHelpers({ sources, stack }) {
242
+ const addSource = ({ source }) => {
244
243
  sources.push(source);
245
- if (!noCache && options.cache) {
246
- options.cache[pointer] = source;
247
- }
248
244
  };
249
245
  const collect = useStack(...stack);
250
246
  return {
package/index.mjs CHANGED
@@ -39,51 +39,52 @@ function applyDefaultOptions(options) {
39
39
  }
40
40
 
41
41
  async function loadFile(pointer, options) {
42
- const cached = useCache({ pointer, options });
43
- if (cached) {
44
- return cached;
45
- }
46
- const results = [];
47
- await Promise.all(options.loaders.map(async (loader) => {
48
- try {
49
- const loaderResults = await loader.load(pointer, options);
50
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
51
- }
52
- catch (error) {
53
- if (env['DEBUG']) {
54
- console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
42
+ var _a;
43
+ let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
44
+ if (!results) {
45
+ results = [];
46
+ await Promise.all(options.loaders.map(async (loader) => {
47
+ try {
48
+ const loaderResults = await loader.load(pointer, options);
49
+ loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
50
+ }
51
+ catch (error) {
52
+ if (env['DEBUG']) {
53
+ console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
54
+ }
55
+ throw error;
55
56
  }
56
- throw error;
57
+ }));
58
+ if (options.cache) {
59
+ options.cache[pointer] = results;
57
60
  }
58
- }));
61
+ }
59
62
  return results;
60
63
  }
61
64
  function loadFileSync(pointer, options) {
62
- const cached = useCache({ pointer, options });
63
- if (cached) {
64
- return cached;
65
- }
66
- const results = [];
67
- for (const loader of options.loaders) {
68
- try {
69
- // We check for the existence so it is okay to force non null
70
- const loaderResults = loader.loadSync(pointer, options);
71
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
72
- }
73
- catch (error) {
74
- if (env['DEBUG']) {
75
- console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
65
+ var _a;
66
+ let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
67
+ if (!results) {
68
+ results = [];
69
+ for (const loader of options.loaders) {
70
+ try {
71
+ // We check for the existence so it is okay to force non null
72
+ const loaderResults = loader.loadSync(pointer, options);
73
+ loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
74
+ }
75
+ catch (error) {
76
+ if (env['DEBUG']) {
77
+ console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
78
+ }
79
+ throw error;
76
80
  }
77
- throw error;
81
+ }
82
+ if (options.cache) {
83
+ options.cache[pointer] = results;
78
84
  }
79
85
  }
80
86
  return results;
81
87
  }
82
- function useCache({ pointer, options }) {
83
- if (options['cache']) {
84
- return options['cache'][pointer];
85
- }
86
- }
87
88
 
88
89
  /**
89
90
  * Converts a string to 32bit integer
@@ -194,7 +195,6 @@ async function collectSources({ pointerOptionMap, options, }) {
194
195
  const queue = useQueue({ concurrency: CONCURRENCY_LIMIT });
195
196
  const { addSource, collect } = createHelpers({
196
197
  sources,
197
- options,
198
198
  stack: [collectDocumentString, collectCustomLoader, collectFallback],
199
199
  });
200
200
  for (const pointer in pointerOptionMap) {
@@ -216,7 +216,6 @@ function collectSourcesSync({ pointerOptionMap, options, }) {
216
216
  const queue = useSyncQueue();
217
217
  const { addSource, collect } = createHelpers({
218
218
  sources,
219
- options,
220
219
  stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
221
220
  });
222
221
  for (const pointer in pointerOptionMap) {
@@ -233,12 +232,9 @@ function collectSourcesSync({ pointerOptionMap, options, }) {
233
232
  queue.runAll();
234
233
  return sources;
235
234
  }
236
- function createHelpers({ sources, options, stack, }) {
237
- const addSource = ({ pointer, source, noCache, }) => {
235
+ function createHelpers({ sources, stack }) {
236
+ const addSource = ({ source }) => {
238
237
  sources.push(source);
239
- if (!noCache && options.cache) {
240
- options.cache[pointer] = source;
241
- }
242
238
  };
243
239
  const collect = useStack(...stack);
244
240
  return {
@@ -3,7 +3,7 @@ export declare type LoadTypedefsOptions<ExtraConfig = {
3
3
  [key: string]: any;
4
4
  }> = BaseLoaderOptions & ExtraConfig & {
5
5
  cache?: {
6
- [key: string]: Source;
6
+ [key: string]: Source[];
7
7
  };
8
8
  loaders: Loader[];
9
9
  filterKinds?: string[];
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-tools/load",
3
- "version": "7.1.2-alpha-a15676c3.0",
3
+ "version": "7.1.4",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/merge": "7.0.0-alpha-a15676c3.0",
10
+ "@graphql-tools/merge": "^7.0.0",
11
11
  "@graphql-tools/utils": "8.0.2",
12
12
  "import-from": "4.0.0",
13
13
  "p-limit": "3.1.0",