@graphql-codegen/cli 2.6.0 → 2.6.2
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 +71 -35
- package/index.js +71 -35
- package/index.mjs +73 -37
- package/package.json +4 -4
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');
|
|
56
57
|
const os = require('os');
|
|
57
58
|
const Listr = _interopDefault(require('listr'));
|
|
58
59
|
const isGlob = _interopDefault(require('is-glob'));
|
|
59
60
|
const debounce = _interopDefault(require('debounce'));
|
|
60
61
|
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'));
|
|
@@ -376,7 +376,12 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
async function getPresetByName(name, loader) {
|
|
379
|
-
const possibleNames = [
|
|
379
|
+
const possibleNames = [
|
|
380
|
+
`@graphql-codegen/${name}`,
|
|
381
|
+
`@graphql-codegen/${name}-preset`,
|
|
382
|
+
name,
|
|
383
|
+
path.resolve(process.cwd(), name),
|
|
384
|
+
];
|
|
380
385
|
for (const moduleName of possibleNames) {
|
|
381
386
|
try {
|
|
382
387
|
const loaded = await loader(moduleName);
|
|
@@ -779,23 +784,53 @@ class CodegenContext {
|
|
|
779
784
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
780
785
|
if (this._graphqlConfig) {
|
|
781
786
|
// TODO: SchemaWithLoader won't work here
|
|
782
|
-
return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
|
|
787
|
+
return addHashToSchema(this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config));
|
|
783
788
|
}
|
|
784
|
-
return loadSchema(pointer, config);
|
|
789
|
+
return addHashToSchema(loadSchema(pointer, config));
|
|
785
790
|
}
|
|
786
791
|
async loadDocuments(pointer) {
|
|
787
792
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
788
793
|
if (this._graphqlConfig) {
|
|
789
794
|
// TODO: pointer won't work here
|
|
790
|
-
|
|
791
|
-
return documents;
|
|
795
|
+
return addHashToDocumentFiles(this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config));
|
|
792
796
|
}
|
|
793
|
-
return loadDocuments(pointer, config);
|
|
797
|
+
return addHashToDocumentFiles(loadDocuments(pointer, config));
|
|
794
798
|
}
|
|
795
799
|
}
|
|
796
800
|
function ensureContext(input) {
|
|
797
801
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
798
802
|
}
|
|
803
|
+
function hashContent(content) {
|
|
804
|
+
return crypto.createHash('sha256').update(content).digest('hex');
|
|
805
|
+
}
|
|
806
|
+
function hashSchema(schema) {
|
|
807
|
+
return hashContent(graphql.print(pluginHelpers.getCachedDocumentNodeFromSchema(schema)));
|
|
808
|
+
}
|
|
809
|
+
function addHashToSchema(schemaPromise) {
|
|
810
|
+
return schemaPromise.then(schema => {
|
|
811
|
+
// It's consumed later on. The general purpose is to use it for caching.
|
|
812
|
+
if (!schema.extensions) {
|
|
813
|
+
schema.extensions = {};
|
|
814
|
+
}
|
|
815
|
+
schema.extensions['hash'] = hashSchema(schema);
|
|
816
|
+
return schema;
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
function hashDocument(doc) {
|
|
820
|
+
if (doc.rawSDL) {
|
|
821
|
+
return hashContent(doc.rawSDL);
|
|
822
|
+
}
|
|
823
|
+
if (doc.document) {
|
|
824
|
+
return hashContent(graphql.print(doc.document));
|
|
825
|
+
}
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
function addHashToDocumentFiles(documentFilesPromise) {
|
|
829
|
+
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
830
|
+
doc.hash = hashDocument(doc);
|
|
831
|
+
return doc;
|
|
832
|
+
}));
|
|
833
|
+
}
|
|
799
834
|
|
|
800
835
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
801
836
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -833,18 +868,17 @@ const makeDefaultLoader = (from) => {
|
|
|
833
868
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
834
869
|
};
|
|
835
870
|
};
|
|
836
|
-
|
|
837
|
-
function createCache(loader) {
|
|
871
|
+
function createCache() {
|
|
838
872
|
const cache = new Map();
|
|
839
|
-
return {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
873
|
+
return function ensure(namespace, key, factory) {
|
|
874
|
+
const cacheKey = `${namespace}:${key}`;
|
|
875
|
+
const cachedValue = cache.get(cacheKey);
|
|
876
|
+
if (cachedValue) {
|
|
877
|
+
return cachedValue;
|
|
878
|
+
}
|
|
879
|
+
const value = factory();
|
|
880
|
+
cache.set(cacheKey, value);
|
|
881
|
+
return value;
|
|
848
882
|
};
|
|
849
883
|
}
|
|
850
884
|
async function executeCodegen(input) {
|
|
@@ -883,20 +917,7 @@ async function executeCodegen(input) {
|
|
|
883
917
|
let rootSchemas;
|
|
884
918
|
let rootDocuments;
|
|
885
919
|
const generates = {};
|
|
886
|
-
const
|
|
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
|
-
});
|
|
920
|
+
const cache = createCache();
|
|
900
921
|
function wrapTask(task, source, taskName) {
|
|
901
922
|
return () => {
|
|
902
923
|
return context.profiler.run(async () => {
|
|
@@ -1014,7 +1035,14 @@ async function executeCodegen(input) {
|
|
|
1014
1035
|
}
|
|
1015
1036
|
}
|
|
1016
1037
|
const hash = JSON.stringify(schemaPointerMap);
|
|
1017
|
-
const result = await
|
|
1038
|
+
const result = await cache('schema', hash, async () => {
|
|
1039
|
+
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
1040
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
1041
|
+
return {
|
|
1042
|
+
outputSchemaAst: outputSchemaAst,
|
|
1043
|
+
outputSchema: outputSchema,
|
|
1044
|
+
};
|
|
1045
|
+
});
|
|
1018
1046
|
outputSchemaAst = await result.outputSchemaAst;
|
|
1019
1047
|
outputSchema = result.outputSchema;
|
|
1020
1048
|
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
@@ -1026,7 +1054,12 @@ async function executeCodegen(input) {
|
|
|
1026
1054
|
// get different cache for shared docs and output specific docs
|
|
1027
1055
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
1028
1056
|
const hash = JSON.stringify(docs);
|
|
1029
|
-
return
|
|
1057
|
+
return cache('documents', hash, async () => {
|
|
1058
|
+
const documents = await context.loadDocuments(docs);
|
|
1059
|
+
return {
|
|
1060
|
+
documents: documents,
|
|
1061
|
+
};
|
|
1062
|
+
});
|
|
1030
1063
|
}));
|
|
1031
1064
|
const documents = [];
|
|
1032
1065
|
results.forEach(source => documents.push(...source.documents));
|
|
@@ -1090,7 +1123,10 @@ async function executeCodegen(input) {
|
|
|
1090
1123
|
];
|
|
1091
1124
|
}
|
|
1092
1125
|
const process = async (outputArgs) => {
|
|
1093
|
-
const output = await core.codegen(
|
|
1126
|
+
const output = await core.codegen({
|
|
1127
|
+
...outputArgs,
|
|
1128
|
+
cache,
|
|
1129
|
+
});
|
|
1094
1130
|
result.push({
|
|
1095
1131
|
filename: outputArgs.filename,
|
|
1096
1132
|
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');
|
|
56
57
|
const os = require('os');
|
|
57
58
|
const Listr = _interopDefault(require('listr'));
|
|
58
59
|
const child_process = require('child_process');
|
|
59
60
|
const isGlob = _interopDefault(require('is-glob'));
|
|
60
61
|
const debounce = _interopDefault(require('debounce'));
|
|
61
62
|
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'));
|
|
@@ -294,7 +294,12 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
async function getPresetByName(name, loader) {
|
|
297
|
-
const possibleNames = [
|
|
297
|
+
const possibleNames = [
|
|
298
|
+
`@graphql-codegen/${name}`,
|
|
299
|
+
`@graphql-codegen/${name}-preset`,
|
|
300
|
+
name,
|
|
301
|
+
path.resolve(process.cwd(), name),
|
|
302
|
+
];
|
|
298
303
|
for (const moduleName of possibleNames) {
|
|
299
304
|
try {
|
|
300
305
|
const loaded = await loader(moduleName);
|
|
@@ -697,23 +702,53 @@ class CodegenContext {
|
|
|
697
702
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
698
703
|
if (this._graphqlConfig) {
|
|
699
704
|
// TODO: SchemaWithLoader won't work here
|
|
700
|
-
return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
|
|
705
|
+
return addHashToSchema(this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config));
|
|
701
706
|
}
|
|
702
|
-
return loadSchema(pointer, config);
|
|
707
|
+
return addHashToSchema(loadSchema(pointer, config));
|
|
703
708
|
}
|
|
704
709
|
async loadDocuments(pointer) {
|
|
705
710
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
706
711
|
if (this._graphqlConfig) {
|
|
707
712
|
// TODO: pointer won't work here
|
|
708
|
-
|
|
709
|
-
return documents;
|
|
713
|
+
return addHashToDocumentFiles(this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config));
|
|
710
714
|
}
|
|
711
|
-
return loadDocuments(pointer, config);
|
|
715
|
+
return addHashToDocumentFiles(loadDocuments(pointer, config));
|
|
712
716
|
}
|
|
713
717
|
}
|
|
714
718
|
function ensureContext(input) {
|
|
715
719
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
716
720
|
}
|
|
721
|
+
function hashContent(content) {
|
|
722
|
+
return crypto.createHash('sha256').update(content).digest('hex');
|
|
723
|
+
}
|
|
724
|
+
function hashSchema(schema) {
|
|
725
|
+
return hashContent(graphql.print(pluginHelpers.getCachedDocumentNodeFromSchema(schema)));
|
|
726
|
+
}
|
|
727
|
+
function addHashToSchema(schemaPromise) {
|
|
728
|
+
return schemaPromise.then(schema => {
|
|
729
|
+
// It's consumed later on. The general purpose is to use it for caching.
|
|
730
|
+
if (!schema.extensions) {
|
|
731
|
+
schema.extensions = {};
|
|
732
|
+
}
|
|
733
|
+
schema.extensions['hash'] = hashSchema(schema);
|
|
734
|
+
return schema;
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function hashDocument(doc) {
|
|
738
|
+
if (doc.rawSDL) {
|
|
739
|
+
return hashContent(doc.rawSDL);
|
|
740
|
+
}
|
|
741
|
+
if (doc.document) {
|
|
742
|
+
return hashContent(graphql.print(doc.document));
|
|
743
|
+
}
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
function addHashToDocumentFiles(documentFilesPromise) {
|
|
747
|
+
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
748
|
+
doc.hash = hashDocument(doc);
|
|
749
|
+
return doc;
|
|
750
|
+
}));
|
|
751
|
+
}
|
|
717
752
|
|
|
718
753
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
719
754
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -751,18 +786,17 @@ const makeDefaultLoader = (from) => {
|
|
|
751
786
|
return new Promise(function (resolve) { resolve(_interopNamespace(require(relativeRequire.resolve(mod)))); });
|
|
752
787
|
};
|
|
753
788
|
};
|
|
754
|
-
|
|
755
|
-
function createCache(loader) {
|
|
789
|
+
function createCache() {
|
|
756
790
|
const cache = new Map();
|
|
757
|
-
return {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
791
|
+
return function ensure(namespace, key, factory) {
|
|
792
|
+
const cacheKey = `${namespace}:${key}`;
|
|
793
|
+
const cachedValue = cache.get(cacheKey);
|
|
794
|
+
if (cachedValue) {
|
|
795
|
+
return cachedValue;
|
|
796
|
+
}
|
|
797
|
+
const value = factory();
|
|
798
|
+
cache.set(cacheKey, value);
|
|
799
|
+
return value;
|
|
766
800
|
};
|
|
767
801
|
}
|
|
768
802
|
async function executeCodegen(input) {
|
|
@@ -801,20 +835,7 @@ async function executeCodegen(input) {
|
|
|
801
835
|
let rootSchemas;
|
|
802
836
|
let rootDocuments;
|
|
803
837
|
const generates = {};
|
|
804
|
-
const
|
|
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
|
-
});
|
|
838
|
+
const cache = createCache();
|
|
818
839
|
function wrapTask(task, source, taskName) {
|
|
819
840
|
return () => {
|
|
820
841
|
return context.profiler.run(async () => {
|
|
@@ -932,7 +953,14 @@ async function executeCodegen(input) {
|
|
|
932
953
|
}
|
|
933
954
|
}
|
|
934
955
|
const hash = JSON.stringify(schemaPointerMap);
|
|
935
|
-
const result = await
|
|
956
|
+
const result = await cache('schema', hash, async () => {
|
|
957
|
+
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
958
|
+
const outputSchema = pluginHelpers.getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
959
|
+
return {
|
|
960
|
+
outputSchemaAst: outputSchemaAst,
|
|
961
|
+
outputSchema: outputSchema,
|
|
962
|
+
};
|
|
963
|
+
});
|
|
936
964
|
outputSchemaAst = await result.outputSchemaAst;
|
|
937
965
|
outputSchema = result.outputSchema;
|
|
938
966
|
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
@@ -944,7 +972,12 @@ async function executeCodegen(input) {
|
|
|
944
972
|
// get different cache for shared docs and output specific docs
|
|
945
973
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
946
974
|
const hash = JSON.stringify(docs);
|
|
947
|
-
return
|
|
975
|
+
return cache('documents', hash, async () => {
|
|
976
|
+
const documents = await context.loadDocuments(docs);
|
|
977
|
+
return {
|
|
978
|
+
documents: documents,
|
|
979
|
+
};
|
|
980
|
+
});
|
|
948
981
|
}));
|
|
949
982
|
const documents = [];
|
|
950
983
|
results.forEach(source => documents.push(...source.documents));
|
|
@@ -1008,7 +1041,10 @@ async function executeCodegen(input) {
|
|
|
1008
1041
|
];
|
|
1009
1042
|
}
|
|
1010
1043
|
const process = async (outputArgs) => {
|
|
1011
|
-
const output = await core.codegen(
|
|
1044
|
+
const output = await core.codegen({
|
|
1045
|
+
...outputArgs,
|
|
1046
|
+
cache,
|
|
1047
|
+
});
|
|
1012
1048
|
result.push({
|
|
1013
1049
|
filename: outputArgs.filename,
|
|
1014
1050
|
content: output,
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDetailedError, DetailedError, createNoopProfiler, createProfiler, normalizeInstanceOrArray, normalizeConfig, normalizeOutputParam
|
|
1
|
+
import { isDetailedError, DetailedError, createNoopProfiler, createProfiler, getCachedDocumentNodeFromSchema, normalizeInstanceOrArray, normalizeConfig, normalizeOutputParam } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { codegen } from '@graphql-codegen/core';
|
|
3
3
|
import { AggregateError, isValidPath } from '@graphql-tools/utils';
|
|
4
4
|
import chalk from 'chalk';
|
|
@@ -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 { GraphQLError } from 'graphql';
|
|
11
|
+
import { print, 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';
|
|
29
30
|
import { cpus } from 'os';
|
|
30
31
|
import Listr from 'listr';
|
|
31
32
|
import { exec } from 'child_process';
|
|
32
33
|
import isGlob from 'is-glob';
|
|
33
34
|
import debounce from 'debounce';
|
|
34
35
|
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';
|
|
@@ -267,7 +267,12 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
async function getPresetByName(name, loader) {
|
|
270
|
-
const possibleNames = [
|
|
270
|
+
const possibleNames = [
|
|
271
|
+
`@graphql-codegen/${name}`,
|
|
272
|
+
`@graphql-codegen/${name}-preset`,
|
|
273
|
+
name,
|
|
274
|
+
resolve(process.cwd(), name),
|
|
275
|
+
];
|
|
271
276
|
for (const moduleName of possibleNames) {
|
|
272
277
|
try {
|
|
273
278
|
const loaded = await loader(moduleName);
|
|
@@ -670,23 +675,53 @@ class CodegenContext {
|
|
|
670
675
|
const config = this.getConfig(defaultSchemaLoadOptions);
|
|
671
676
|
if (this._graphqlConfig) {
|
|
672
677
|
// TODO: SchemaWithLoader won't work here
|
|
673
|
-
return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
|
|
678
|
+
return addHashToSchema(this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config));
|
|
674
679
|
}
|
|
675
|
-
return loadSchema(pointer, config);
|
|
680
|
+
return addHashToSchema(loadSchema(pointer, config));
|
|
676
681
|
}
|
|
677
682
|
async loadDocuments(pointer) {
|
|
678
683
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
679
684
|
if (this._graphqlConfig) {
|
|
680
685
|
// TODO: pointer won't work here
|
|
681
|
-
|
|
682
|
-
return documents;
|
|
686
|
+
return addHashToDocumentFiles(this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config));
|
|
683
687
|
}
|
|
684
|
-
return loadDocuments(pointer, config);
|
|
688
|
+
return addHashToDocumentFiles(loadDocuments(pointer, config));
|
|
685
689
|
}
|
|
686
690
|
}
|
|
687
691
|
function ensureContext(input) {
|
|
688
692
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
689
693
|
}
|
|
694
|
+
function hashContent(content) {
|
|
695
|
+
return createHash('sha256').update(content).digest('hex');
|
|
696
|
+
}
|
|
697
|
+
function hashSchema(schema) {
|
|
698
|
+
return hashContent(print(getCachedDocumentNodeFromSchema(schema)));
|
|
699
|
+
}
|
|
700
|
+
function addHashToSchema(schemaPromise) {
|
|
701
|
+
return schemaPromise.then(schema => {
|
|
702
|
+
// It's consumed later on. The general purpose is to use it for caching.
|
|
703
|
+
if (!schema.extensions) {
|
|
704
|
+
schema.extensions = {};
|
|
705
|
+
}
|
|
706
|
+
schema.extensions['hash'] = hashSchema(schema);
|
|
707
|
+
return schema;
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
function hashDocument(doc) {
|
|
711
|
+
if (doc.rawSDL) {
|
|
712
|
+
return hashContent(doc.rawSDL);
|
|
713
|
+
}
|
|
714
|
+
if (doc.document) {
|
|
715
|
+
return hashContent(print(doc.document));
|
|
716
|
+
}
|
|
717
|
+
return null;
|
|
718
|
+
}
|
|
719
|
+
function addHashToDocumentFiles(documentFilesPromise) {
|
|
720
|
+
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
721
|
+
doc.hash = hashDocument(doc);
|
|
722
|
+
return doc;
|
|
723
|
+
}));
|
|
724
|
+
}
|
|
690
725
|
|
|
691
726
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
692
727
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
@@ -724,18 +759,17 @@ const makeDefaultLoader = (from) => {
|
|
|
724
759
|
return import(relativeRequire.resolve(mod));
|
|
725
760
|
};
|
|
726
761
|
};
|
|
727
|
-
|
|
728
|
-
function createCache(loader) {
|
|
762
|
+
function createCache() {
|
|
729
763
|
const cache = new Map();
|
|
730
|
-
return {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
764
|
+
return function ensure(namespace, key, factory) {
|
|
765
|
+
const cacheKey = `${namespace}:${key}`;
|
|
766
|
+
const cachedValue = cache.get(cacheKey);
|
|
767
|
+
if (cachedValue) {
|
|
768
|
+
return cachedValue;
|
|
769
|
+
}
|
|
770
|
+
const value = factory();
|
|
771
|
+
cache.set(cacheKey, value);
|
|
772
|
+
return value;
|
|
739
773
|
};
|
|
740
774
|
}
|
|
741
775
|
async function executeCodegen(input) {
|
|
@@ -774,20 +808,7 @@ async function executeCodegen(input) {
|
|
|
774
808
|
let rootSchemas;
|
|
775
809
|
let rootDocuments;
|
|
776
810
|
const generates = {};
|
|
777
|
-
const
|
|
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
|
-
});
|
|
811
|
+
const cache = createCache();
|
|
791
812
|
function wrapTask(task, source, taskName) {
|
|
792
813
|
return () => {
|
|
793
814
|
return context.profiler.run(async () => {
|
|
@@ -905,7 +926,14 @@ async function executeCodegen(input) {
|
|
|
905
926
|
}
|
|
906
927
|
}
|
|
907
928
|
const hash = JSON.stringify(schemaPointerMap);
|
|
908
|
-
const result = await
|
|
929
|
+
const result = await cache('schema', hash, async () => {
|
|
930
|
+
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
931
|
+
const outputSchema = getCachedDocumentNodeFromSchema(outputSchemaAst);
|
|
932
|
+
return {
|
|
933
|
+
outputSchemaAst: outputSchemaAst,
|
|
934
|
+
outputSchema: outputSchema,
|
|
935
|
+
};
|
|
936
|
+
});
|
|
909
937
|
outputSchemaAst = await result.outputSchemaAst;
|
|
910
938
|
outputSchema = result.outputSchema;
|
|
911
939
|
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
@@ -917,7 +945,12 @@ async function executeCodegen(input) {
|
|
|
917
945
|
// get different cache for shared docs and output specific docs
|
|
918
946
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
919
947
|
const hash = JSON.stringify(docs);
|
|
920
|
-
return
|
|
948
|
+
return cache('documents', hash, async () => {
|
|
949
|
+
const documents = await context.loadDocuments(docs);
|
|
950
|
+
return {
|
|
951
|
+
documents: documents,
|
|
952
|
+
};
|
|
953
|
+
});
|
|
921
954
|
}));
|
|
922
955
|
const documents = [];
|
|
923
956
|
results.forEach(source => documents.push(...source.documents));
|
|
@@ -981,7 +1014,10 @@ async function executeCodegen(input) {
|
|
|
981
1014
|
];
|
|
982
1015
|
}
|
|
983
1016
|
const process = async (outputArgs) => {
|
|
984
|
-
const output = await codegen(
|
|
1017
|
+
const output = await codegen({
|
|
1018
|
+
...outputArgs,
|
|
1019
|
+
cache,
|
|
1020
|
+
});
|
|
985
1021
|
result.push({
|
|
986
1022
|
filename: outputArgs.filename,
|
|
987
1023
|
content: output,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
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.5.
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "^2.4.
|
|
8
|
+
"@graphql-codegen/core": "2.5.1",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.4.1",
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"listr": "^0.14.3",
|
|
37
37
|
"listr-update-renderer": "^0.5.0",
|
|
38
38
|
"log-symbols": "^4.0.0",
|
|
39
|
-
"minimatch": "^
|
|
39
|
+
"minimatch": "^4.0.0",
|
|
40
40
|
"mkdirp": "^1.0.4",
|
|
41
41
|
"string-env-interpolation": "^1.0.1",
|
|
42
42
|
"ts-log": "^2.2.3",
|