@graphql-codegen/cli 2.6.0-alpha-967b742ba.0 → 2.6.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 +34 -64
- package/index.js +34 -64
- package/index.mjs +36 -66
- package/package.json +3 -3
package/bin.js
CHANGED
|
@@ -53,12 +53,12 @@ const yaml = _interopDefault(require('yaml'));
|
|
|
53
53
|
const module$1 = require('module');
|
|
54
54
|
const fs = require('fs');
|
|
55
55
|
const fs__default = _interopDefault(fs);
|
|
56
|
-
const crypto = require('crypto');
|
|
57
56
|
const os = require('os');
|
|
58
57
|
const Listr = _interopDefault(require('listr'));
|
|
59
58
|
const isGlob = _interopDefault(require('is-glob'));
|
|
60
59
|
const debounce = _interopDefault(require('debounce'));
|
|
61
60
|
const mkdirp = _interopDefault(require('mkdirp'));
|
|
61
|
+
const crypto = require('crypto');
|
|
62
62
|
const inquirer = _interopDefault(require('inquirer'));
|
|
63
63
|
const detectIndent = _interopDefault(require('detect-indent'));
|
|
64
64
|
const getLatestVersion = _interopDefault(require('latest-version'));
|
|
@@ -779,52 +779,23 @@ class CodegenContext {
|
|
|
779
779
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
780
780
|
if (this._graphqlConfig) {
|
|
781
781
|
// TODO: SchemaWithLoader won't work here
|
|
782
|
-
return
|
|
782
|
+
return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
|
|
783
783
|
}
|
|
784
|
-
return
|
|
784
|
+
return loadSchema(pointer, config);
|
|
785
785
|
}
|
|
786
786
|
async loadDocuments(pointer) {
|
|
787
787
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
788
788
|
if (this._graphqlConfig) {
|
|
789
789
|
// TODO: pointer won't work here
|
|
790
|
-
|
|
790
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
791
|
+
return documents;
|
|
791
792
|
}
|
|
792
|
-
return
|
|
793
|
+
return loadDocuments(pointer, config);
|
|
793
794
|
}
|
|
794
795
|
}
|
|
795
796
|
function ensureContext(input) {
|
|
796
797
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
797
798
|
}
|
|
798
|
-
function hashContent(content) {
|
|
799
|
-
return crypto.createHash('sha256').update(content).digest('hex');
|
|
800
|
-
}
|
|
801
|
-
function hashSchema(schema) {
|
|
802
|
-
return hashContent(utils.printSchemaWithDirectives(schema, {
|
|
803
|
-
assumeValid: true,
|
|
804
|
-
}));
|
|
805
|
-
}
|
|
806
|
-
function addHashToSchema(schemaPromise) {
|
|
807
|
-
return schemaPromise.then(schema => {
|
|
808
|
-
// It's consumed later on. The general purpose is to use it for caching.
|
|
809
|
-
schema.extensions['hash'] = hashSchema(schema);
|
|
810
|
-
return schema;
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
function hashDocument(doc) {
|
|
814
|
-
if (doc.rawSDL) {
|
|
815
|
-
return hashContent(doc.rawSDL);
|
|
816
|
-
}
|
|
817
|
-
if (doc.document) {
|
|
818
|
-
return hashContent(graphql.print(doc.document));
|
|
819
|
-
}
|
|
820
|
-
return null;
|
|
821
|
-
}
|
|
822
|
-
function addHashToDocumentFiles(documentFilesPromise) {
|
|
823
|
-
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
824
|
-
doc.hash = hashDocument(doc);
|
|
825
|
-
return doc;
|
|
826
|
-
}));
|
|
827
|
-
}
|
|
828
799
|
|
|
829
800
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
830
801
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -862,17 +833,18 @@ const makeDefaultLoader = (from) => {
|
|
|
862
833
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
863
834
|
};
|
|
864
835
|
};
|
|
865
|
-
|
|
836
|
+
// TODO: Replace any with types
|
|
837
|
+
function createCache(loader) {
|
|
866
838
|
const cache = new Map();
|
|
867
|
-
return
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
839
|
+
return {
|
|
840
|
+
load(key) {
|
|
841
|
+
if (cache.has(key)) {
|
|
842
|
+
return cache.get(key);
|
|
843
|
+
}
|
|
844
|
+
const value = loader(key);
|
|
845
|
+
cache.set(key, value);
|
|
846
|
+
return value;
|
|
847
|
+
},
|
|
876
848
|
};
|
|
877
849
|
}
|
|
878
850
|
async function executeCodegen(input) {
|
|
@@ -911,7 +883,20 @@ async function executeCodegen(input) {
|
|
|
911
883
|
let rootSchemas;
|
|
912
884
|
let rootDocuments;
|
|
913
885
|
const generates = {};
|
|
914
|
-
const
|
|
886
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
887
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
888
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
889
|
+
return {
|
|
890
|
+
outputSchemaAst: outputSchemaAst,
|
|
891
|
+
outputSchema: outputSchema,
|
|
892
|
+
};
|
|
893
|
+
});
|
|
894
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
895
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
896
|
+
return {
|
|
897
|
+
documents: documents,
|
|
898
|
+
};
|
|
899
|
+
});
|
|
915
900
|
function wrapTask(task, source, taskName) {
|
|
916
901
|
return () => {
|
|
917
902
|
return context.profiler.run(async () => {
|
|
@@ -1029,14 +1014,7 @@ async function executeCodegen(input) {
|
|
|
1029
1014
|
}
|
|
1030
1015
|
}
|
|
1031
1016
|
const hash = JSON.stringify(schemaPointerMap);
|
|
1032
|
-
const result = await
|
|
1033
|
-
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
1034
|
-
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
1035
|
-
return {
|
|
1036
|
-
outputSchemaAst: outputSchemaAst,
|
|
1037
|
-
outputSchema: outputSchema,
|
|
1038
|
-
};
|
|
1039
|
-
});
|
|
1017
|
+
const result = await schemaLoadingCache.load(hash);
|
|
1040
1018
|
outputSchemaAst = await result.outputSchemaAst;
|
|
1041
1019
|
outputSchema = result.outputSchema;
|
|
1042
1020
|
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
@@ -1048,12 +1026,7 @@ async function executeCodegen(input) {
|
|
|
1048
1026
|
// get different cache for shared docs and output specific docs
|
|
1049
1027
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
1050
1028
|
const hash = JSON.stringify(docs);
|
|
1051
|
-
return
|
|
1052
|
-
const documents = await context.loadDocuments(docs);
|
|
1053
|
-
return {
|
|
1054
|
-
documents: documents,
|
|
1055
|
-
};
|
|
1056
|
-
});
|
|
1029
|
+
return documentsLoadingCache.load(hash);
|
|
1057
1030
|
}));
|
|
1058
1031
|
const documents = [];
|
|
1059
1032
|
results.forEach(source => documents.push(...source.documents));
|
|
@@ -1117,10 +1090,7 @@ async function executeCodegen(input) {
|
|
|
1117
1090
|
];
|
|
1118
1091
|
}
|
|
1119
1092
|
const process = async (outputArgs) => {
|
|
1120
|
-
const output = await core.codegen(
|
|
1121
|
-
...outputArgs,
|
|
1122
|
-
cache,
|
|
1123
|
-
});
|
|
1093
|
+
const output = await core.codegen(outputArgs);
|
|
1124
1094
|
result.push({
|
|
1125
1095
|
filename: outputArgs.filename,
|
|
1126
1096
|
content: output,
|
package/index.js
CHANGED
|
@@ -53,13 +53,13 @@ const yaml = _interopDefault(require('yaml'));
|
|
|
53
53
|
const module$1 = require('module');
|
|
54
54
|
const fs = require('fs');
|
|
55
55
|
const fs__default = _interopDefault(fs);
|
|
56
|
-
const crypto = require('crypto');
|
|
57
56
|
const os = require('os');
|
|
58
57
|
const Listr = _interopDefault(require('listr'));
|
|
59
58
|
const child_process = require('child_process');
|
|
60
59
|
const isGlob = _interopDefault(require('is-glob'));
|
|
61
60
|
const debounce = _interopDefault(require('debounce'));
|
|
62
61
|
const mkdirp = _interopDefault(require('mkdirp'));
|
|
62
|
+
const crypto = require('crypto');
|
|
63
63
|
const inquirer = _interopDefault(require('inquirer'));
|
|
64
64
|
const detectIndent = _interopDefault(require('detect-indent'));
|
|
65
65
|
const getLatestVersion = _interopDefault(require('latest-version'));
|
|
@@ -697,52 +697,23 @@ class CodegenContext {
|
|
|
697
697
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
698
698
|
if (this._graphqlConfig) {
|
|
699
699
|
// TODO: SchemaWithLoader won't work here
|
|
700
|
-
return
|
|
700
|
+
return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
|
|
701
701
|
}
|
|
702
|
-
return
|
|
702
|
+
return loadSchema(pointer, config);
|
|
703
703
|
}
|
|
704
704
|
async loadDocuments(pointer) {
|
|
705
705
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
706
706
|
if (this._graphqlConfig) {
|
|
707
707
|
// TODO: pointer won't work here
|
|
708
|
-
|
|
708
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
709
|
+
return documents;
|
|
709
710
|
}
|
|
710
|
-
return
|
|
711
|
+
return loadDocuments(pointer, config);
|
|
711
712
|
}
|
|
712
713
|
}
|
|
713
714
|
function ensureContext(input) {
|
|
714
715
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
715
716
|
}
|
|
716
|
-
function hashContent(content) {
|
|
717
|
-
return crypto.createHash('sha256').update(content).digest('hex');
|
|
718
|
-
}
|
|
719
|
-
function hashSchema(schema) {
|
|
720
|
-
return hashContent(utils.printSchemaWithDirectives(schema, {
|
|
721
|
-
assumeValid: true,
|
|
722
|
-
}));
|
|
723
|
-
}
|
|
724
|
-
function addHashToSchema(schemaPromise) {
|
|
725
|
-
return schemaPromise.then(schema => {
|
|
726
|
-
// It's consumed later on. The general purpose is to use it for caching.
|
|
727
|
-
schema.extensions['hash'] = hashSchema(schema);
|
|
728
|
-
return schema;
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
function hashDocument(doc) {
|
|
732
|
-
if (doc.rawSDL) {
|
|
733
|
-
return hashContent(doc.rawSDL);
|
|
734
|
-
}
|
|
735
|
-
if (doc.document) {
|
|
736
|
-
return hashContent(graphql.print(doc.document));
|
|
737
|
-
}
|
|
738
|
-
return null;
|
|
739
|
-
}
|
|
740
|
-
function addHashToDocumentFiles(documentFilesPromise) {
|
|
741
|
-
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
742
|
-
doc.hash = hashDocument(doc);
|
|
743
|
-
return doc;
|
|
744
|
-
}));
|
|
745
|
-
}
|
|
746
717
|
|
|
747
718
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
748
719
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -780,17 +751,18 @@ const makeDefaultLoader = (from) => {
|
|
|
780
751
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
781
752
|
};
|
|
782
753
|
};
|
|
783
|
-
|
|
754
|
+
// TODO: Replace any with types
|
|
755
|
+
function createCache(loader) {
|
|
784
756
|
const cache = new Map();
|
|
785
|
-
return
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
757
|
+
return {
|
|
758
|
+
load(key) {
|
|
759
|
+
if (cache.has(key)) {
|
|
760
|
+
return cache.get(key);
|
|
761
|
+
}
|
|
762
|
+
const value = loader(key);
|
|
763
|
+
cache.set(key, value);
|
|
764
|
+
return value;
|
|
765
|
+
},
|
|
794
766
|
};
|
|
795
767
|
}
|
|
796
768
|
async function executeCodegen(input) {
|
|
@@ -829,7 +801,20 @@ async function executeCodegen(input) {
|
|
|
829
801
|
let rootSchemas;
|
|
830
802
|
let rootDocuments;
|
|
831
803
|
const generates = {};
|
|
832
|
-
const
|
|
804
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
805
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
806
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
807
|
+
return {
|
|
808
|
+
outputSchemaAst: outputSchemaAst,
|
|
809
|
+
outputSchema: outputSchema,
|
|
810
|
+
};
|
|
811
|
+
});
|
|
812
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
813
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
814
|
+
return {
|
|
815
|
+
documents: documents,
|
|
816
|
+
};
|
|
817
|
+
});
|
|
833
818
|
function wrapTask(task, source, taskName) {
|
|
834
819
|
return () => {
|
|
835
820
|
return context.profiler.run(async () => {
|
|
@@ -947,14 +932,7 @@ async function executeCodegen(input) {
|
|
|
947
932
|
}
|
|
948
933
|
}
|
|
949
934
|
const hash = JSON.stringify(schemaPointerMap);
|
|
950
|
-
const result = await
|
|
951
|
-
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
952
|
-
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
953
|
-
return {
|
|
954
|
-
outputSchemaAst: outputSchemaAst,
|
|
955
|
-
outputSchema: outputSchema,
|
|
956
|
-
};
|
|
957
|
-
});
|
|
935
|
+
const result = await schemaLoadingCache.load(hash);
|
|
958
936
|
outputSchemaAst = await result.outputSchemaAst;
|
|
959
937
|
outputSchema = result.outputSchema;
|
|
960
938
|
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
@@ -966,12 +944,7 @@ async function executeCodegen(input) {
|
|
|
966
944
|
// get different cache for shared docs and output specific docs
|
|
967
945
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
968
946
|
const hash = JSON.stringify(docs);
|
|
969
|
-
return
|
|
970
|
-
const documents = await context.loadDocuments(docs);
|
|
971
|
-
return {
|
|
972
|
-
documents: documents,
|
|
973
|
-
};
|
|
974
|
-
});
|
|
947
|
+
return documentsLoadingCache.load(hash);
|
|
975
948
|
}));
|
|
976
949
|
const documents = [];
|
|
977
950
|
results.forEach(source => documents.push(...source.documents));
|
|
@@ -1035,10 +1008,7 @@ async function executeCodegen(input) {
|
|
|
1035
1008
|
];
|
|
1036
1009
|
}
|
|
1037
1010
|
const process = async (outputArgs) => {
|
|
1038
|
-
const output = await core.codegen(
|
|
1039
|
-
...outputArgs,
|
|
1040
|
-
cache,
|
|
1041
|
-
});
|
|
1011
|
+
const output = await core.codegen(outputArgs);
|
|
1042
1012
|
result.push({
|
|
1043
1013
|
filename: outputArgs.filename,
|
|
1044
1014
|
content: output,
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDetailedError, DetailedError, createNoopProfiler, createProfiler, normalizeInstanceOrArray, normalizeConfig, normalizeOutputParam, getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { codegen } from '@graphql-codegen/core';
|
|
3
|
-
import {
|
|
3
|
+
import { AggregateError, isValidPath } from '@graphql-tools/utils';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import logSymbols from 'log-symbols';
|
|
6
6
|
import ansiEscapes from 'ansi-escapes';
|
|
@@ -8,7 +8,7 @@ import wrapAnsi from 'wrap-ansi';
|
|
|
8
8
|
import { stripIndent } from 'common-tags';
|
|
9
9
|
import { dummyLogger } from 'ts-log';
|
|
10
10
|
import UpdateRenderer from 'listr-update-renderer';
|
|
11
|
-
import {
|
|
11
|
+
import { GraphQLError } from 'graphql';
|
|
12
12
|
import path, { resolve, extname, join, delimiter, sep, dirname, isAbsolute, relative } from 'path';
|
|
13
13
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
14
14
|
import { env } from 'string-env-interpolation';
|
|
@@ -26,13 +26,13 @@ import { UrlLoader } from '@graphql-tools/url-loader';
|
|
|
26
26
|
import yaml from 'yaml';
|
|
27
27
|
import { createRequire } from 'module';
|
|
28
28
|
import fs, { promises, unlink, writeFileSync, readFileSync } from 'fs';
|
|
29
|
-
import { createHash } from 'crypto';
|
|
30
29
|
import { cpus } from 'os';
|
|
31
30
|
import Listr from 'listr';
|
|
32
31
|
import { exec } from 'child_process';
|
|
33
32
|
import isGlob from 'is-glob';
|
|
34
33
|
import debounce from 'debounce';
|
|
35
34
|
import mkdirp from 'mkdirp';
|
|
35
|
+
import { createHash } from 'crypto';
|
|
36
36
|
import inquirer from 'inquirer';
|
|
37
37
|
import detectIndent from 'detect-indent';
|
|
38
38
|
import getLatestVersion from 'latest-version';
|
|
@@ -670,52 +670,23 @@ class CodegenContext {
|
|
|
670
670
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
671
671
|
if (this._graphqlConfig) {
|
|
672
672
|
// TODO: SchemaWithLoader won't work here
|
|
673
|
-
return
|
|
673
|
+
return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
|
|
674
674
|
}
|
|
675
|
-
return
|
|
675
|
+
return loadSchema(pointer, config);
|
|
676
676
|
}
|
|
677
677
|
async loadDocuments(pointer) {
|
|
678
678
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
679
679
|
if (this._graphqlConfig) {
|
|
680
680
|
// TODO: pointer won't work here
|
|
681
|
-
|
|
681
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
682
|
+
return documents;
|
|
682
683
|
}
|
|
683
|
-
return
|
|
684
|
+
return loadDocuments(pointer, config);
|
|
684
685
|
}
|
|
685
686
|
}
|
|
686
687
|
function ensureContext(input) {
|
|
687
688
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
688
689
|
}
|
|
689
|
-
function hashContent(content) {
|
|
690
|
-
return createHash('sha256').update(content).digest('hex');
|
|
691
|
-
}
|
|
692
|
-
function hashSchema(schema) {
|
|
693
|
-
return hashContent(printSchemaWithDirectives(schema, {
|
|
694
|
-
assumeValid: true,
|
|
695
|
-
}));
|
|
696
|
-
}
|
|
697
|
-
function addHashToSchema(schemaPromise) {
|
|
698
|
-
return schemaPromise.then(schema => {
|
|
699
|
-
// It's consumed later on. The general purpose is to use it for caching.
|
|
700
|
-
schema.extensions['hash'] = hashSchema(schema);
|
|
701
|
-
return schema;
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
function hashDocument(doc) {
|
|
705
|
-
if (doc.rawSDL) {
|
|
706
|
-
return hashContent(doc.rawSDL);
|
|
707
|
-
}
|
|
708
|
-
if (doc.document) {
|
|
709
|
-
return hashContent(print(doc.document));
|
|
710
|
-
}
|
|
711
|
-
return null;
|
|
712
|
-
}
|
|
713
|
-
function addHashToDocumentFiles(documentFilesPromise) {
|
|
714
|
-
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
715
|
-
doc.hash = hashDocument(doc);
|
|
716
|
-
return doc;
|
|
717
|
-
}));
|
|
718
|
-
}
|
|
719
690
|
|
|
720
691
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
721
692
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -753,17 +724,18 @@ const makeDefaultLoader = (from) => {
|
|
|
753
724
|
return import(relativeRequire.resolve(mod));
|
|
754
725
|
};
|
|
755
726
|
};
|
|
756
|
-
|
|
727
|
+
// TODO: Replace any with types
|
|
728
|
+
function createCache(loader) {
|
|
757
729
|
const cache = new Map();
|
|
758
|
-
return
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
730
|
+
return {
|
|
731
|
+
load(key) {
|
|
732
|
+
if (cache.has(key)) {
|
|
733
|
+
return cache.get(key);
|
|
734
|
+
}
|
|
735
|
+
const value = loader(key);
|
|
736
|
+
cache.set(key, value);
|
|
737
|
+
return value;
|
|
738
|
+
},
|
|
767
739
|
};
|
|
768
740
|
}
|
|
769
741
|
async function executeCodegen(input) {
|
|
@@ -802,7 +774,20 @@ async function executeCodegen(input) {
|
|
|
802
774
|
let rootSchemas;
|
|
803
775
|
let rootDocuments;
|
|
804
776
|
const generates = {};
|
|
805
|
-
const
|
|
777
|
+
const schemaLoadingCache = createCache(async function (hash) {
|
|
778
|
+
const outputSchemaAst = await context.loadSchema(JSON.parse(hash));
|
|
779
|
+
const outputSchema = getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
780
|
+
return {
|
|
781
|
+
outputSchemaAst: outputSchemaAst,
|
|
782
|
+
outputSchema: outputSchema,
|
|
783
|
+
};
|
|
784
|
+
});
|
|
785
|
+
const documentsLoadingCache = createCache(async function (hash) {
|
|
786
|
+
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
787
|
+
return {
|
|
788
|
+
documents: documents,
|
|
789
|
+
};
|
|
790
|
+
});
|
|
806
791
|
function wrapTask(task, source, taskName) {
|
|
807
792
|
return () => {
|
|
808
793
|
return context.profiler.run(async () => {
|
|
@@ -920,14 +905,7 @@ async function executeCodegen(input) {
|
|
|
920
905
|
}
|
|
921
906
|
}
|
|
922
907
|
const hash = JSON.stringify(schemaPointerMap);
|
|
923
|
-
const result = await
|
|
924
|
-
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
925
|
-
const outputSchema = getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
926
|
-
return {
|
|
927
|
-
outputSchemaAst: outputSchemaAst,
|
|
928
|
-
outputSchema: outputSchema,
|
|
929
|
-
};
|
|
930
|
-
});
|
|
908
|
+
const result = await schemaLoadingCache.load(hash);
|
|
931
909
|
outputSchemaAst = await result.outputSchemaAst;
|
|
932
910
|
outputSchema = result.outputSchema;
|
|
933
911
|
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
@@ -939,12 +917,7 @@ async function executeCodegen(input) {
|
|
|
939
917
|
// get different cache for shared docs and output specific docs
|
|
940
918
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
941
919
|
const hash = JSON.stringify(docs);
|
|
942
|
-
return
|
|
943
|
-
const documents = await context.loadDocuments(docs);
|
|
944
|
-
return {
|
|
945
|
-
documents: documents,
|
|
946
|
-
};
|
|
947
|
-
});
|
|
920
|
+
return documentsLoadingCache.load(hash);
|
|
948
921
|
}));
|
|
949
922
|
const documents = [];
|
|
950
923
|
results.forEach(source => documents.push(...source.documents));
|
|
@@ -1008,10 +981,7 @@ async function executeCodegen(input) {
|
|
|
1008
981
|
];
|
|
1009
982
|
}
|
|
1010
983
|
const process = async (outputArgs) => {
|
|
1011
|
-
const output = await codegen(
|
|
1012
|
-
...outputArgs,
|
|
1013
|
-
cache,
|
|
1014
|
-
});
|
|
984
|
+
const output = await codegen(outputArgs);
|
|
1015
985
|
result.push({
|
|
1016
986
|
filename: outputArgs.filename,
|
|
1017
987
|
content: output,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.6.0
|
|
3
|
+
"version": "2.6.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.
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.
|
|
8
|
+
"@graphql-codegen/core": "2.5.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.4.0",
|
|
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",
|