@graphql-codegen/cli 2.4.0-alpha-6cdbcf02e.0 → 2.4.1-alpha-06d103feb.0
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/bin.js +43 -23
- package/index.js +43 -23
- package/index.mjs +43 -23
- package/package.json +3 -3
package/bin.js
CHANGED
|
@@ -505,34 +505,19 @@ async function loadSchema(schemaPointers, config) {
|
|
|
505
505
|
|
|
506
506
|
${e.message || e}
|
|
507
507
|
${e.stack || ''}
|
|
508
|
-
|
|
508
|
+
|
|
509
509
|
GraphQL Code Generator supports:
|
|
510
510
|
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
511
511
|
- Introspection JSON File
|
|
512
512
|
- URL of GraphQL endpoint
|
|
513
513
|
- Multiple files with type definitions (glob expression)
|
|
514
514
|
- String in config file
|
|
515
|
-
|
|
515
|
+
|
|
516
516
|
Try to use one of above options and run codegen again.
|
|
517
|
-
|
|
517
|
+
|
|
518
518
|
`);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
|
-
const adjustRequirePointers = (documentPointers) => {
|
|
522
|
-
const adjustSinglePointer = (pointer) => {
|
|
523
|
-
if (typeof pointer === 'object' && 'require' in pointer) {
|
|
524
|
-
const config = 'config' in pointer ? pointer.config : {};
|
|
525
|
-
return { [pointer['require']]: config };
|
|
526
|
-
}
|
|
527
|
-
return pointer;
|
|
528
|
-
};
|
|
529
|
-
if (Array.isArray(documentPointers)) {
|
|
530
|
-
return documentPointers.map(adjustSinglePointer);
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
return adjustSinglePointer(documentPointers);
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
521
|
async function loadDocuments(documentPointers, config) {
|
|
537
522
|
const loaders = [
|
|
538
523
|
new codeFileLoader.CodeFileLoader({
|
|
@@ -552,7 +537,7 @@ async function loadDocuments(documentPointers, config) {
|
|
|
552
537
|
}
|
|
553
538
|
ignore.push(path.join(process.cwd(), generatePath));
|
|
554
539
|
}
|
|
555
|
-
const loadedFromToolkit = await load.loadDocuments(
|
|
540
|
+
const loadedFromToolkit = await load.loadDocuments(documentPointers, {
|
|
556
541
|
...defaultDocumentsLoadOptions,
|
|
557
542
|
ignore,
|
|
558
543
|
loaders,
|
|
@@ -805,6 +790,20 @@ const makeDefaultLoader = (from) => {
|
|
|
805
790
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
806
791
|
};
|
|
807
792
|
};
|
|
793
|
+
// TODO: Replace any with types
|
|
794
|
+
function createCache(loader) {
|
|
795
|
+
const cache = new Map();
|
|
796
|
+
return {
|
|
797
|
+
load(key) {
|
|
798
|
+
if (cache.has(key)) {
|
|
799
|
+
return cache.get(key);
|
|
800
|
+
}
|
|
801
|
+
const value = loader(key);
|
|
802
|
+
cache.set(key, value);
|
|
803
|
+
return value;
|
|
804
|
+
},
|
|
805
|
+
};
|
|
806
|
+
}
|
|
808
807
|
async function executeCodegen(input) {
|
|
809
808
|
function wrapTask(task, source) {
|
|
810
809
|
return async () => {
|
|
@@ -854,6 +853,20 @@ async function executeCodegen(input) {
|
|
|
854
853
|
let rootSchemas;
|
|
855
854
|
let rootDocuments;
|
|
856
855
|
const generates = {};
|
|
856
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
857
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
858
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
859
|
+
return {
|
|
860
|
+
outputSchemaAst: outputSchemaAst,
|
|
861
|
+
outputSchema: outputSchema,
|
|
862
|
+
};
|
|
863
|
+
});
|
|
864
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
865
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
866
|
+
return {
|
|
867
|
+
documents: documents,
|
|
868
|
+
};
|
|
869
|
+
});
|
|
857
870
|
async function normalize() {
|
|
858
871
|
/* Load Require extensions */
|
|
859
872
|
const requireExtensions = pluginHelpers.normalizeInstanceOrArray(config.require);
|
|
@@ -955,16 +968,23 @@ async function executeCodegen(input) {
|
|
|
955
968
|
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
956
969
|
}
|
|
957
970
|
}
|
|
958
|
-
|
|
959
|
-
|
|
971
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
972
|
+
const result = await schemaLoadingCache.load(hash);
|
|
973
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
974
|
+
outputSchema = result.outputSchema;
|
|
960
975
|
}, filename),
|
|
961
976
|
},
|
|
962
977
|
{
|
|
963
978
|
title: 'Load GraphQL documents',
|
|
964
979
|
task: wrapTask(async () => {
|
|
965
980
|
debugLog(`[CLI] Loading Documents`);
|
|
966
|
-
|
|
967
|
-
const
|
|
981
|
+
// get different cache for shared docs and output specific docs
|
|
982
|
+
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
983
|
+
const hash = JSON.stringify(docs);
|
|
984
|
+
return documentsLoadingCache.load(hash);
|
|
985
|
+
}));
|
|
986
|
+
const documents = [];
|
|
987
|
+
results.forEach(source => documents.push(...source.documents));
|
|
968
988
|
if (documents.length > 0) {
|
|
969
989
|
outputDocuments.push(...documents);
|
|
970
990
|
}
|
package/index.js
CHANGED
|
@@ -423,34 +423,19 @@ async function loadSchema(schemaPointers, config) {
|
|
|
423
423
|
|
|
424
424
|
${e.message || e}
|
|
425
425
|
${e.stack || ''}
|
|
426
|
-
|
|
426
|
+
|
|
427
427
|
GraphQL Code Generator supports:
|
|
428
428
|
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
429
429
|
- Introspection JSON File
|
|
430
430
|
- URL of GraphQL endpoint
|
|
431
431
|
- Multiple files with type definitions (glob expression)
|
|
432
432
|
- String in config file
|
|
433
|
-
|
|
433
|
+
|
|
434
434
|
Try to use one of above options and run codegen again.
|
|
435
|
-
|
|
435
|
+
|
|
436
436
|
`);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
const adjustRequirePointers = (documentPointers) => {
|
|
440
|
-
const adjustSinglePointer = (pointer) => {
|
|
441
|
-
if (typeof pointer === 'object' && 'require' in pointer) {
|
|
442
|
-
const config = 'config' in pointer ? pointer.config : {};
|
|
443
|
-
return { [pointer['require']]: config };
|
|
444
|
-
}
|
|
445
|
-
return pointer;
|
|
446
|
-
};
|
|
447
|
-
if (Array.isArray(documentPointers)) {
|
|
448
|
-
return documentPointers.map(adjustSinglePointer);
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
return adjustSinglePointer(documentPointers);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
439
|
async function loadDocuments(documentPointers, config) {
|
|
455
440
|
const loaders = [
|
|
456
441
|
new codeFileLoader.CodeFileLoader({
|
|
@@ -470,7 +455,7 @@ async function loadDocuments(documentPointers, config) {
|
|
|
470
455
|
}
|
|
471
456
|
ignore.push(path.join(process.cwd(), generatePath));
|
|
472
457
|
}
|
|
473
|
-
const loadedFromToolkit = await load.loadDocuments(
|
|
458
|
+
const loadedFromToolkit = await load.loadDocuments(documentPointers, {
|
|
474
459
|
...defaultDocumentsLoadOptions,
|
|
475
460
|
ignore,
|
|
476
461
|
loaders,
|
|
@@ -723,6 +708,20 @@ const makeDefaultLoader = (from) => {
|
|
|
723
708
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
724
709
|
};
|
|
725
710
|
};
|
|
711
|
+
// TODO: Replace any with types
|
|
712
|
+
function createCache(loader) {
|
|
713
|
+
const cache = new Map();
|
|
714
|
+
return {
|
|
715
|
+
load(key) {
|
|
716
|
+
if (cache.has(key)) {
|
|
717
|
+
return cache.get(key);
|
|
718
|
+
}
|
|
719
|
+
const value = loader(key);
|
|
720
|
+
cache.set(key, value);
|
|
721
|
+
return value;
|
|
722
|
+
},
|
|
723
|
+
};
|
|
724
|
+
}
|
|
726
725
|
async function executeCodegen(input) {
|
|
727
726
|
function wrapTask(task, source) {
|
|
728
727
|
return async () => {
|
|
@@ -772,6 +771,20 @@ async function executeCodegen(input) {
|
|
|
772
771
|
let rootSchemas;
|
|
773
772
|
let rootDocuments;
|
|
774
773
|
const generates = {};
|
|
774
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
775
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
776
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
777
|
+
return {
|
|
778
|
+
outputSchemaAst: outputSchemaAst,
|
|
779
|
+
outputSchema: outputSchema,
|
|
780
|
+
};
|
|
781
|
+
});
|
|
782
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
783
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
784
|
+
return {
|
|
785
|
+
documents: documents,
|
|
786
|
+
};
|
|
787
|
+
});
|
|
775
788
|
async function normalize() {
|
|
776
789
|
/* Load Require extensions */
|
|
777
790
|
const requireExtensions = pluginHelpers.normalizeInstanceOrArray(config.require);
|
|
@@ -873,16 +886,23 @@ async function executeCodegen(input) {
|
|
|
873
886
|
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
874
887
|
}
|
|
875
888
|
}
|
|
876
|
-
|
|
877
|
-
|
|
889
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
890
|
+
const result = await schemaLoadingCache.load(hash);
|
|
891
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
892
|
+
outputSchema = result.outputSchema;
|
|
878
893
|
}, filename),
|
|
879
894
|
},
|
|
880
895
|
{
|
|
881
896
|
title: 'Load GraphQL documents',
|
|
882
897
|
task: wrapTask(async () => {
|
|
883
898
|
debugLog(`[CLI] Loading Documents`);
|
|
884
|
-
|
|
885
|
-
const
|
|
899
|
+
// get different cache for shared docs and output specific docs
|
|
900
|
+
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
901
|
+
const hash = JSON.stringify(docs);
|
|
902
|
+
return documentsLoadingCache.load(hash);
|
|
903
|
+
}));
|
|
904
|
+
const documents = [];
|
|
905
|
+
results.forEach(source => documents.push(...source.documents));
|
|
886
906
|
if (documents.length > 0) {
|
|
887
907
|
outputDocuments.push(...documents);
|
|
888
908
|
}
|
package/index.mjs
CHANGED
|
@@ -396,34 +396,19 @@ async function loadSchema(schemaPointers, config) {
|
|
|
396
396
|
|
|
397
397
|
${e.message || e}
|
|
398
398
|
${e.stack || ''}
|
|
399
|
-
|
|
399
|
+
|
|
400
400
|
GraphQL Code Generator supports:
|
|
401
401
|
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
402
402
|
- Introspection JSON File
|
|
403
403
|
- URL of GraphQL endpoint
|
|
404
404
|
- Multiple files with type definitions (glob expression)
|
|
405
405
|
- String in config file
|
|
406
|
-
|
|
406
|
+
|
|
407
407
|
Try to use one of above options and run codegen again.
|
|
408
|
-
|
|
408
|
+
|
|
409
409
|
`);
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
const adjustRequirePointers = (documentPointers) => {
|
|
413
|
-
const adjustSinglePointer = (pointer) => {
|
|
414
|
-
if (typeof pointer === 'object' && 'require' in pointer) {
|
|
415
|
-
const config = 'config' in pointer ? pointer.config : {};
|
|
416
|
-
return { [pointer['require']]: config };
|
|
417
|
-
}
|
|
418
|
-
return pointer;
|
|
419
|
-
};
|
|
420
|
-
if (Array.isArray(documentPointers)) {
|
|
421
|
-
return documentPointers.map(adjustSinglePointer);
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
return adjustSinglePointer(documentPointers);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
412
|
async function loadDocuments(documentPointers, config) {
|
|
428
413
|
const loaders = [
|
|
429
414
|
new CodeFileLoader({
|
|
@@ -443,7 +428,7 @@ async function loadDocuments(documentPointers, config) {
|
|
|
443
428
|
}
|
|
444
429
|
ignore.push(join(process.cwd(), generatePath));
|
|
445
430
|
}
|
|
446
|
-
const loadedFromToolkit = await loadDocuments$1(
|
|
431
|
+
const loadedFromToolkit = await loadDocuments$1(documentPointers, {
|
|
447
432
|
...defaultDocumentsLoadOptions,
|
|
448
433
|
ignore,
|
|
449
434
|
loaders,
|
|
@@ -696,6 +681,20 @@ const makeDefaultLoader = (from) => {
|
|
|
696
681
|
return import(relativeRequire.resolve(mod));
|
|
697
682
|
};
|
|
698
683
|
};
|
|
684
|
+
// TODO: Replace any with types
|
|
685
|
+
function createCache(loader) {
|
|
686
|
+
const cache = new Map();
|
|
687
|
+
return {
|
|
688
|
+
load(key) {
|
|
689
|
+
if (cache.has(key)) {
|
|
690
|
+
return cache.get(key);
|
|
691
|
+
}
|
|
692
|
+
const value = loader(key);
|
|
693
|
+
cache.set(key, value);
|
|
694
|
+
return value;
|
|
695
|
+
},
|
|
696
|
+
};
|
|
697
|
+
}
|
|
699
698
|
async function executeCodegen(input) {
|
|
700
699
|
function wrapTask(task, source) {
|
|
701
700
|
return async () => {
|
|
@@ -745,6 +744,20 @@ async function executeCodegen(input) {
|
|
|
745
744
|
let rootSchemas;
|
|
746
745
|
let rootDocuments;
|
|
747
746
|
const generates = {};
|
|
747
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
748
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
749
|
+
const outputSchema = getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
750
|
+
return {
|
|
751
|
+
outputSchemaAst: outputSchemaAst,
|
|
752
|
+
outputSchema: outputSchema,
|
|
753
|
+
};
|
|
754
|
+
});
|
|
755
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
756
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
757
|
+
return {
|
|
758
|
+
documents: documents,
|
|
759
|
+
};
|
|
760
|
+
});
|
|
748
761
|
async function normalize() {
|
|
749
762
|
/* Load Require extensions */
|
|
750
763
|
const requireExtensions = normalizeInstanceOrArray(config.require);
|
|
@@ -846,16 +859,23 @@ async function executeCodegen(input) {
|
|
|
846
859
|
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
847
860
|
}
|
|
848
861
|
}
|
|
849
|
-
|
|
850
|
-
|
|
862
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
863
|
+
const result = await schemaLoadingCache.load(hash);
|
|
864
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
865
|
+
outputSchema = result.outputSchema;
|
|
851
866
|
}, filename),
|
|
852
867
|
},
|
|
853
868
|
{
|
|
854
869
|
title: 'Load GraphQL documents',
|
|
855
870
|
task: wrapTask(async () => {
|
|
856
871
|
debugLog(`[CLI] Loading Documents`);
|
|
857
|
-
|
|
858
|
-
const
|
|
872
|
+
// get different cache for shared docs and output specific docs
|
|
873
|
+
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
874
|
+
const hash = JSON.stringify(docs);
|
|
875
|
+
return documentsLoadingCache.load(hash);
|
|
876
|
+
}));
|
|
877
|
+
const documents = [];
|
|
878
|
+
results.forEach(source => documents.push(...source.documents));
|
|
859
879
|
if (documents.length > 0) {
|
|
860
880
|
outputDocuments.push(...documents);
|
|
861
881
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1-alpha-06d103feb.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@graphql-codegen/core": "2.4.
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.3.
|
|
8
|
+
"@graphql-codegen/core": "2.4.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.3.2",
|
|
10
10
|
"@graphql-tools/apollo-engine-loader": "^7.0.5",
|
|
11
11
|
"@graphql-tools/code-file-loader": "^7.0.6",
|
|
12
12
|
"@graphql-tools/git-loader": "^7.0.5",
|