@graphql-codegen/cli 2.3.1 → 2.4.1-alpha-7b61b3baf.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 +56 -3
- package/index.js +56 -3
- package/index.mjs +56 -3
- package/package.json +2 -1
package/bin.js
CHANGED
|
@@ -35,6 +35,7 @@ const wrapAnsi = _interopDefault(require('wrap-ansi'));
|
|
|
35
35
|
const commonTags = require('common-tags');
|
|
36
36
|
const UpdateRenderer = _interopDefault(require('listr-update-renderer'));
|
|
37
37
|
const graphql = require('graphql');
|
|
38
|
+
const tslib = require('tslib');
|
|
38
39
|
const cosmiconfig = require('cosmiconfig');
|
|
39
40
|
const stringEnvInterpolation = require('string-env-interpolation');
|
|
40
41
|
const yargs = _interopDefault(require('yargs'));
|
|
@@ -52,6 +53,7 @@ const yaml = _interopDefault(require('yaml'));
|
|
|
52
53
|
const module$1 = require('module');
|
|
53
54
|
const fs = require('fs');
|
|
54
55
|
const fs__default = _interopDefault(fs);
|
|
56
|
+
const buddy = require('@theguild/buddy');
|
|
55
57
|
const Listr = _interopDefault(require('listr'));
|
|
56
58
|
const isGlob = _interopDefault(require('is-glob'));
|
|
57
59
|
const debounce = _interopDefault(require('debounce'));
|
|
@@ -759,6 +761,7 @@ class CodegenContext {
|
|
|
759
761
|
getPluginContext() {
|
|
760
762
|
return this._pluginContext;
|
|
761
763
|
}
|
|
764
|
+
// [ ] This will break watch mode - cache forever
|
|
762
765
|
async loadSchema(pointer) {
|
|
763
766
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
764
767
|
if (this._graphqlConfig) {
|
|
@@ -767,6 +770,7 @@ class CodegenContext {
|
|
|
767
770
|
}
|
|
768
771
|
return loadSchema(pointer, config);
|
|
769
772
|
}
|
|
773
|
+
// [ ] This will break watch mode - cache forever
|
|
770
774
|
async loadDocuments(pointer) {
|
|
771
775
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
772
776
|
if (this._graphqlConfig) {
|
|
@@ -777,9 +781,26 @@ class CodegenContext {
|
|
|
777
781
|
return loadDocuments(pointer, config);
|
|
778
782
|
}
|
|
779
783
|
}
|
|
784
|
+
tslib.__decorate([
|
|
785
|
+
buddy.cacheResult(cacheKeyFactory()),
|
|
786
|
+
tslib.__metadata("design:type", Function),
|
|
787
|
+
tslib.__metadata("design:paramtypes", [Object]),
|
|
788
|
+
tslib.__metadata("design:returntype", Promise)
|
|
789
|
+
], CodegenContext.prototype, "loadSchema", null);
|
|
790
|
+
tslib.__decorate([
|
|
791
|
+
buddy.cacheResult(cacheKeyFactory()),
|
|
792
|
+
tslib.__metadata("design:type", Function),
|
|
793
|
+
tslib.__metadata("design:paramtypes", [Array]),
|
|
794
|
+
tslib.__metadata("design:returntype", Promise)
|
|
795
|
+
], CodegenContext.prototype, "loadDocuments", null);
|
|
780
796
|
function ensureContext(input) {
|
|
781
797
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
782
798
|
}
|
|
799
|
+
function cacheKeyFactory() {
|
|
800
|
+
return function stringifyPointer(value) {
|
|
801
|
+
return JSON.stringify(value);
|
|
802
|
+
};
|
|
803
|
+
}
|
|
783
804
|
|
|
784
805
|
const makeDefaultLoader = (from) => {
|
|
785
806
|
if (fs__default.statSync(from).isDirectory()) {
|
|
@@ -790,6 +811,20 @@ const makeDefaultLoader = (from) => {
|
|
|
790
811
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
791
812
|
};
|
|
792
813
|
};
|
|
814
|
+
// TODO: Replace any with types
|
|
815
|
+
function createCache(loader) {
|
|
816
|
+
const cache = new Map();
|
|
817
|
+
return {
|
|
818
|
+
load(key) {
|
|
819
|
+
if (cache.has(key)) {
|
|
820
|
+
return cache.get(key);
|
|
821
|
+
}
|
|
822
|
+
const value = loader(key);
|
|
823
|
+
cache.set(key, value);
|
|
824
|
+
return value;
|
|
825
|
+
},
|
|
826
|
+
};
|
|
827
|
+
}
|
|
793
828
|
async function executeCodegen(input) {
|
|
794
829
|
function wrapTask(task, source) {
|
|
795
830
|
return async () => {
|
|
@@ -839,6 +874,20 @@ async function executeCodegen(input) {
|
|
|
839
874
|
let rootSchemas;
|
|
840
875
|
let rootDocuments;
|
|
841
876
|
const generates = {};
|
|
877
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
878
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
879
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
880
|
+
return {
|
|
881
|
+
outputSchemaAst: outputSchemaAst,
|
|
882
|
+
outputSchema: outputSchema,
|
|
883
|
+
};
|
|
884
|
+
});
|
|
885
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
886
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
887
|
+
return {
|
|
888
|
+
documents: documents,
|
|
889
|
+
};
|
|
890
|
+
});
|
|
842
891
|
async function normalize() {
|
|
843
892
|
/* Load Require extensions */
|
|
844
893
|
const requireExtensions = pluginHelpers.normalizeInstanceOrArray(config.require);
|
|
@@ -940,8 +989,10 @@ async function executeCodegen(input) {
|
|
|
940
989
|
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
941
990
|
}
|
|
942
991
|
}
|
|
943
|
-
|
|
944
|
-
|
|
992
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
993
|
+
const result = await schemaLoadingCache.load(hash);
|
|
994
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
995
|
+
outputSchema = result.outputSchema;
|
|
945
996
|
}, filename),
|
|
946
997
|
},
|
|
947
998
|
{
|
|
@@ -949,7 +1000,9 @@ async function executeCodegen(input) {
|
|
|
949
1000
|
task: wrapTask(async () => {
|
|
950
1001
|
debugLog(`[CLI] Loading Documents`);
|
|
951
1002
|
const allDocuments = [...rootDocuments, ...outputSpecificDocuments];
|
|
952
|
-
const
|
|
1003
|
+
const hash = JSON.stringify(allDocuments);
|
|
1004
|
+
const result = await documentsLoadingCache.load(hash);
|
|
1005
|
+
const documents = result.documents;
|
|
953
1006
|
if (documents.length > 0) {
|
|
954
1007
|
outputDocuments.push(...documents);
|
|
955
1008
|
}
|
package/index.js
CHANGED
|
@@ -35,6 +35,7 @@ const UpdateRenderer = _interopDefault(require('listr-update-renderer'));
|
|
|
35
35
|
const graphql = require('graphql');
|
|
36
36
|
const path = require('path');
|
|
37
37
|
const path__default = _interopDefault(path);
|
|
38
|
+
const tslib = require('tslib');
|
|
38
39
|
const cosmiconfig = require('cosmiconfig');
|
|
39
40
|
const stringEnvInterpolation = require('string-env-interpolation');
|
|
40
41
|
const yargs = _interopDefault(require('yargs'));
|
|
@@ -52,6 +53,7 @@ const yaml = _interopDefault(require('yaml'));
|
|
|
52
53
|
const module$1 = require('module');
|
|
53
54
|
const fs = require('fs');
|
|
54
55
|
const fs__default = _interopDefault(fs);
|
|
56
|
+
const buddy = require('@theguild/buddy');
|
|
55
57
|
const Listr = _interopDefault(require('listr'));
|
|
56
58
|
const child_process = require('child_process');
|
|
57
59
|
const isGlob = _interopDefault(require('is-glob'));
|
|
@@ -677,6 +679,7 @@ class CodegenContext {
|
|
|
677
679
|
getPluginContext() {
|
|
678
680
|
return this._pluginContext;
|
|
679
681
|
}
|
|
682
|
+
// [ ] This will break watch mode - cache forever
|
|
680
683
|
async loadSchema(pointer) {
|
|
681
684
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
682
685
|
if (this._graphqlConfig) {
|
|
@@ -685,6 +688,7 @@ class CodegenContext {
|
|
|
685
688
|
}
|
|
686
689
|
return loadSchema(pointer, config);
|
|
687
690
|
}
|
|
691
|
+
// [ ] This will break watch mode - cache forever
|
|
688
692
|
async loadDocuments(pointer) {
|
|
689
693
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
690
694
|
if (this._graphqlConfig) {
|
|
@@ -695,9 +699,26 @@ class CodegenContext {
|
|
|
695
699
|
return loadDocuments(pointer, config);
|
|
696
700
|
}
|
|
697
701
|
}
|
|
702
|
+
tslib.__decorate([
|
|
703
|
+
buddy.cacheResult(cacheKeyFactory()),
|
|
704
|
+
tslib.__metadata("design:type", Function),
|
|
705
|
+
tslib.__metadata("design:paramtypes", [Object]),
|
|
706
|
+
tslib.__metadata("design:returntype", Promise)
|
|
707
|
+
], CodegenContext.prototype, "loadSchema", null);
|
|
708
|
+
tslib.__decorate([
|
|
709
|
+
buddy.cacheResult(cacheKeyFactory()),
|
|
710
|
+
tslib.__metadata("design:type", Function),
|
|
711
|
+
tslib.__metadata("design:paramtypes", [Array]),
|
|
712
|
+
tslib.__metadata("design:returntype", Promise)
|
|
713
|
+
], CodegenContext.prototype, "loadDocuments", null);
|
|
698
714
|
function ensureContext(input) {
|
|
699
715
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
700
716
|
}
|
|
717
|
+
function cacheKeyFactory() {
|
|
718
|
+
return function stringifyPointer(value) {
|
|
719
|
+
return JSON.stringify(value);
|
|
720
|
+
};
|
|
721
|
+
}
|
|
701
722
|
|
|
702
723
|
const makeDefaultLoader = (from) => {
|
|
703
724
|
if (fs__default.statSync(from).isDirectory()) {
|
|
@@ -708,6 +729,20 @@ const makeDefaultLoader = (from) => {
|
|
|
708
729
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
709
730
|
};
|
|
710
731
|
};
|
|
732
|
+
// TODO: Replace any with types
|
|
733
|
+
function createCache(loader) {
|
|
734
|
+
const cache = new Map();
|
|
735
|
+
return {
|
|
736
|
+
load(key) {
|
|
737
|
+
if (cache.has(key)) {
|
|
738
|
+
return cache.get(key);
|
|
739
|
+
}
|
|
740
|
+
const value = loader(key);
|
|
741
|
+
cache.set(key, value);
|
|
742
|
+
return value;
|
|
743
|
+
},
|
|
744
|
+
};
|
|
745
|
+
}
|
|
711
746
|
async function executeCodegen(input) {
|
|
712
747
|
function wrapTask(task, source) {
|
|
713
748
|
return async () => {
|
|
@@ -757,6 +792,20 @@ async function executeCodegen(input) {
|
|
|
757
792
|
let rootSchemas;
|
|
758
793
|
let rootDocuments;
|
|
759
794
|
const generates = {};
|
|
795
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
796
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
797
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
798
|
+
return {
|
|
799
|
+
outputSchemaAst: outputSchemaAst,
|
|
800
|
+
outputSchema: outputSchema,
|
|
801
|
+
};
|
|
802
|
+
});
|
|
803
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
804
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
805
|
+
return {
|
|
806
|
+
documents: documents,
|
|
807
|
+
};
|
|
808
|
+
});
|
|
760
809
|
async function normalize() {
|
|
761
810
|
/* Load Require extensions */
|
|
762
811
|
const requireExtensions = pluginHelpers.normalizeInstanceOrArray(config.require);
|
|
@@ -858,8 +907,10 @@ async function executeCodegen(input) {
|
|
|
858
907
|
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
859
908
|
}
|
|
860
909
|
}
|
|
861
|
-
|
|
862
|
-
|
|
910
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
911
|
+
const result = await schemaLoadingCache.load(hash);
|
|
912
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
913
|
+
outputSchema = result.outputSchema;
|
|
863
914
|
}, filename),
|
|
864
915
|
},
|
|
865
916
|
{
|
|
@@ -867,7 +918,9 @@ async function executeCodegen(input) {
|
|
|
867
918
|
task: wrapTask(async () => {
|
|
868
919
|
debugLog(`[CLI] Loading Documents`);
|
|
869
920
|
const allDocuments = [...rootDocuments, ...outputSpecificDocuments];
|
|
870
|
-
const
|
|
921
|
+
const hash = JSON.stringify(allDocuments);
|
|
922
|
+
const result = await documentsLoadingCache.load(hash);
|
|
923
|
+
const documents = result.documents;
|
|
871
924
|
if (documents.length > 0) {
|
|
872
925
|
outputDocuments.push(...documents);
|
|
873
926
|
}
|
package/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { dummyLogger } from 'ts-log';
|
|
|
9
9
|
import UpdateRenderer from 'listr-update-renderer';
|
|
10
10
|
import { GraphQLError } from 'graphql';
|
|
11
11
|
import path, { resolve, extname, join, delimiter, sep, dirname, isAbsolute, relative } from 'path';
|
|
12
|
+
import { __decorate, __metadata } from 'tslib';
|
|
12
13
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
13
14
|
import { env } from 'string-env-interpolation';
|
|
14
15
|
import yargs from 'yargs';
|
|
@@ -25,6 +26,7 @@ import { UrlLoader } from '@graphql-tools/url-loader';
|
|
|
25
26
|
import yaml from 'yaml';
|
|
26
27
|
import { createRequire } from 'module';
|
|
27
28
|
import fs, { promises, readFileSync, writeFileSync, statSync, unlink } from 'fs';
|
|
29
|
+
import { cacheResult } from '@theguild/buddy';
|
|
28
30
|
import Listr from 'listr';
|
|
29
31
|
import { exec } from 'child_process';
|
|
30
32
|
import isGlob from 'is-glob';
|
|
@@ -650,6 +652,7 @@ class CodegenContext {
|
|
|
650
652
|
getPluginContext() {
|
|
651
653
|
return this._pluginContext;
|
|
652
654
|
}
|
|
655
|
+
// [ ] This will break watch mode - cache forever
|
|
653
656
|
async loadSchema(pointer) {
|
|
654
657
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
655
658
|
if (this._graphqlConfig) {
|
|
@@ -658,6 +661,7 @@ class CodegenContext {
|
|
|
658
661
|
}
|
|
659
662
|
return loadSchema(pointer, config);
|
|
660
663
|
}
|
|
664
|
+
// [ ] This will break watch mode - cache forever
|
|
661
665
|
async loadDocuments(pointer) {
|
|
662
666
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
663
667
|
if (this._graphqlConfig) {
|
|
@@ -668,9 +672,26 @@ class CodegenContext {
|
|
|
668
672
|
return loadDocuments(pointer, config);
|
|
669
673
|
}
|
|
670
674
|
}
|
|
675
|
+
__decorate([
|
|
676
|
+
cacheResult(cacheKeyFactory()),
|
|
677
|
+
__metadata("design:type", Function),
|
|
678
|
+
__metadata("design:paramtypes", [Object]),
|
|
679
|
+
__metadata("design:returntype", Promise)
|
|
680
|
+
], CodegenContext.prototype, "loadSchema", null);
|
|
681
|
+
__decorate([
|
|
682
|
+
cacheResult(cacheKeyFactory()),
|
|
683
|
+
__metadata("design:type", Function),
|
|
684
|
+
__metadata("design:paramtypes", [Array]),
|
|
685
|
+
__metadata("design:returntype", Promise)
|
|
686
|
+
], CodegenContext.prototype, "loadDocuments", null);
|
|
671
687
|
function ensureContext(input) {
|
|
672
688
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
673
689
|
}
|
|
690
|
+
function cacheKeyFactory() {
|
|
691
|
+
return function stringifyPointer(value) {
|
|
692
|
+
return JSON.stringify(value);
|
|
693
|
+
};
|
|
694
|
+
}
|
|
674
695
|
|
|
675
696
|
const makeDefaultLoader = (from) => {
|
|
676
697
|
if (fs.statSync(from).isDirectory()) {
|
|
@@ -681,6 +702,20 @@ const makeDefaultLoader = (from) => {
|
|
|
681
702
|
return import(relativeRequire.resolve(mod));
|
|
682
703
|
};
|
|
683
704
|
};
|
|
705
|
+
// TODO: Replace any with types
|
|
706
|
+
function createCache(loader) {
|
|
707
|
+
const cache = new Map();
|
|
708
|
+
return {
|
|
709
|
+
load(key) {
|
|
710
|
+
if (cache.has(key)) {
|
|
711
|
+
return cache.get(key);
|
|
712
|
+
}
|
|
713
|
+
const value = loader(key);
|
|
714
|
+
cache.set(key, value);
|
|
715
|
+
return value;
|
|
716
|
+
},
|
|
717
|
+
};
|
|
718
|
+
}
|
|
684
719
|
async function executeCodegen(input) {
|
|
685
720
|
function wrapTask(task, source) {
|
|
686
721
|
return async () => {
|
|
@@ -730,6 +765,20 @@ async function executeCodegen(input) {
|
|
|
730
765
|
let rootSchemas;
|
|
731
766
|
let rootDocuments;
|
|
732
767
|
const generates = {};
|
|
768
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
769
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
770
|
+
const outputSchema = getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
771
|
+
return {
|
|
772
|
+
outputSchemaAst: outputSchemaAst,
|
|
773
|
+
outputSchema: outputSchema,
|
|
774
|
+
};
|
|
775
|
+
});
|
|
776
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
777
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
778
|
+
return {
|
|
779
|
+
documents: documents,
|
|
780
|
+
};
|
|
781
|
+
});
|
|
733
782
|
async function normalize() {
|
|
734
783
|
/* Load Require extensions */
|
|
735
784
|
const requireExtensions = normalizeInstanceOrArray(config.require);
|
|
@@ -831,8 +880,10 @@ async function executeCodegen(input) {
|
|
|
831
880
|
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
832
881
|
}
|
|
833
882
|
}
|
|
834
|
-
|
|
835
|
-
|
|
883
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
884
|
+
const result = await schemaLoadingCache.load(hash);
|
|
885
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
886
|
+
outputSchema = result.outputSchema;
|
|
836
887
|
}, filename),
|
|
837
888
|
},
|
|
838
889
|
{
|
|
@@ -840,7 +891,9 @@ async function executeCodegen(input) {
|
|
|
840
891
|
task: wrapTask(async () => {
|
|
841
892
|
debugLog(`[CLI] Loading Documents`);
|
|
842
893
|
const allDocuments = [...rootDocuments, ...outputSpecificDocuments];
|
|
843
|
-
const
|
|
894
|
+
const hash = JSON.stringify(allDocuments);
|
|
895
|
+
const result = await documentsLoadingCache.load(hash);
|
|
896
|
+
const documents = result.documents;
|
|
844
897
|
if (documents.length > 0) {
|
|
845
898
|
outputDocuments.push(...documents);
|
|
846
899
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1-alpha-7b61b3baf.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
|
},
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@graphql-tools/prisma-loader": "^7.0.6",
|
|
18
18
|
"@graphql-tools/url-loader": "^7.0.11",
|
|
19
19
|
"@graphql-tools/utils": "^8.1.1",
|
|
20
|
+
"@theguild/buddy": "0.1.0",
|
|
20
21
|
"ansi-escapes": "^4.3.1",
|
|
21
22
|
"chalk": "^4.1.0",
|
|
22
23
|
"change-case-all": "1.0.14",
|