@graphql-codegen/cli 2.6.4 → 2.6.5-alpha-43974d1af.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 CHANGED
@@ -830,9 +830,6 @@ function addHashToDocumentFiles(documentFilesPromise) {
830
830
  }));
831
831
  }
832
832
 
833
- const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
834
- const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
835
-
836
833
  function isListrError(err) {
837
834
  return err.name === 'ListrError' && Array.isArray(err.errors) && err.errors.length > 0;
838
835
  }
@@ -849,12 +846,9 @@ function cliError(err, exitOnError = true) {
849
846
  }
850
847
  // eslint-disable-next-line no-console
851
848
  console.error(msg);
852
- if (exitOnError && isNode) {
849
+ if (exitOnError) {
853
850
  process.exit(1);
854
851
  }
855
- else if (exitOnError && isBrowser) {
856
- throw err;
857
- }
858
852
  }
859
853
 
860
854
  const makeDefaultLoader = (from) => {
@@ -1014,7 +1008,7 @@ async function executeCodegen(input) {
1014
1008
  let outputSchemaAst;
1015
1009
  let outputSchema;
1016
1010
  const outputFileTemplateConfig = outputConfig.config || {};
1017
- const outputDocuments = [];
1011
+ let outputDocuments = [];
1018
1012
  const outputSpecificSchemas = pluginHelpers.normalizeInstanceOrArray(outputConfig.schema);
1019
1013
  const outputSpecificDocuments = pluginHelpers.normalizeInstanceOrArray(outputConfig.documents);
1020
1014
  return new Listr([
@@ -1050,20 +1044,24 @@ async function executeCodegen(input) {
1050
1044
  task: wrapTask(async () => {
1051
1045
  debugLog(`[CLI] Loading Documents`);
1052
1046
  // get different cache for shared docs and output specific docs
1053
- const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
1054
- const hash = JSON.stringify(docs);
1055
- return cache('documents', hash, async () => {
1056
- const documents = await context.loadDocuments(docs);
1057
- return {
1058
- documents,
1059
- };
1060
- });
1061
- }));
1062
- const documents = [];
1063
- results.forEach(source => documents.push(...source.documents));
1064
- if (documents.length > 0) {
1065
- outputDocuments.push(...documents);
1047
+ const documentPointerMap = {};
1048
+ const allDocumentsUnnormalizedPointers = [...rootDocuments, ...outputSpecificDocuments];
1049
+ for (const unnormalizedPtr of allDocumentsUnnormalizedPointers) {
1050
+ if (typeof unnormalizedPtr === 'string') {
1051
+ documentPointerMap[unnormalizedPtr] = {};
1052
+ }
1053
+ else if (typeof unnormalizedPtr === 'object') {
1054
+ Object.assign(documentPointerMap, unnormalizedPtr);
1055
+ }
1066
1056
  }
1057
+ const hash = JSON.stringify(documentPointerMap);
1058
+ const result = await cache('documents', hash, async () => {
1059
+ const documents = await context.loadDocuments(documentPointerMap);
1060
+ return {
1061
+ documents,
1062
+ };
1063
+ });
1064
+ outputDocuments = await result.documents;
1067
1065
  }, filename, `Load GraphQL documents: ${filename}`),
1068
1066
  },
1069
1067
  {
package/index.js CHANGED
@@ -750,9 +750,6 @@ function addHashToDocumentFiles(documentFilesPromise) {
750
750
  }));
751
751
  }
752
752
 
753
- const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
754
- const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
755
-
756
753
  function isListrError(err) {
757
754
  return err.name === 'ListrError' && Array.isArray(err.errors) && err.errors.length > 0;
758
755
  }
@@ -769,12 +766,9 @@ function cliError(err, exitOnError = true) {
769
766
  }
770
767
  // eslint-disable-next-line no-console
771
768
  console.error(msg);
772
- if (exitOnError && isNode) {
769
+ if (exitOnError) {
773
770
  process.exit(1);
774
771
  }
775
- else if (exitOnError && isBrowser) {
776
- throw err;
777
- }
778
772
  }
779
773
 
780
774
  const makeDefaultLoader = (from) => {
@@ -934,7 +928,7 @@ async function executeCodegen(input) {
934
928
  let outputSchemaAst;
935
929
  let outputSchema;
936
930
  const outputFileTemplateConfig = outputConfig.config || {};
937
- const outputDocuments = [];
931
+ let outputDocuments = [];
938
932
  const outputSpecificSchemas = pluginHelpers.normalizeInstanceOrArray(outputConfig.schema);
939
933
  const outputSpecificDocuments = pluginHelpers.normalizeInstanceOrArray(outputConfig.documents);
940
934
  return new Listr([
@@ -970,20 +964,24 @@ async function executeCodegen(input) {
970
964
  task: wrapTask(async () => {
971
965
  debugLog(`[CLI] Loading Documents`);
972
966
  // get different cache for shared docs and output specific docs
973
- const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
974
- const hash = JSON.stringify(docs);
975
- return cache('documents', hash, async () => {
976
- const documents = await context.loadDocuments(docs);
977
- return {
978
- documents,
979
- };
980
- });
981
- }));
982
- const documents = [];
983
- results.forEach(source => documents.push(...source.documents));
984
- if (documents.length > 0) {
985
- outputDocuments.push(...documents);
967
+ const documentPointerMap = {};
968
+ const allDocumentsUnnormalizedPointers = [...rootDocuments, ...outputSpecificDocuments];
969
+ for (const unnormalizedPtr of allDocumentsUnnormalizedPointers) {
970
+ if (typeof unnormalizedPtr === 'string') {
971
+ documentPointerMap[unnormalizedPtr] = {};
972
+ }
973
+ else if (typeof unnormalizedPtr === 'object') {
974
+ Object.assign(documentPointerMap, unnormalizedPtr);
975
+ }
986
976
  }
977
+ const hash = JSON.stringify(documentPointerMap);
978
+ const result = await cache('documents', hash, async () => {
979
+ const documents = await context.loadDocuments(documentPointerMap);
980
+ return {
981
+ documents,
982
+ };
983
+ });
984
+ outputDocuments = await result.documents;
987
985
  }, filename, `Load GraphQL documents: ${filename}`),
988
986
  },
989
987
  {
package/index.mjs CHANGED
@@ -723,9 +723,6 @@ function addHashToDocumentFiles(documentFilesPromise) {
723
723
  }));
724
724
  }
725
725
 
726
- const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
727
- const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
728
-
729
726
  function isListrError(err) {
730
727
  return err.name === 'ListrError' && Array.isArray(err.errors) && err.errors.length > 0;
731
728
  }
@@ -742,12 +739,9 @@ function cliError(err, exitOnError = true) {
742
739
  }
743
740
  // eslint-disable-next-line no-console
744
741
  console.error(msg);
745
- if (exitOnError && isNode) {
742
+ if (exitOnError) {
746
743
  process.exit(1);
747
744
  }
748
- else if (exitOnError && isBrowser) {
749
- throw err;
750
- }
751
745
  }
752
746
 
753
747
  const makeDefaultLoader = (from) => {
@@ -907,7 +901,7 @@ async function executeCodegen(input) {
907
901
  let outputSchemaAst;
908
902
  let outputSchema;
909
903
  const outputFileTemplateConfig = outputConfig.config || {};
910
- const outputDocuments = [];
904
+ let outputDocuments = [];
911
905
  const outputSpecificSchemas = normalizeInstanceOrArray(outputConfig.schema);
912
906
  const outputSpecificDocuments = normalizeInstanceOrArray(outputConfig.documents);
913
907
  return new Listr([
@@ -943,20 +937,24 @@ async function executeCodegen(input) {
943
937
  task: wrapTask(async () => {
944
938
  debugLog(`[CLI] Loading Documents`);
945
939
  // get different cache for shared docs and output specific docs
946
- const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
947
- const hash = JSON.stringify(docs);
948
- return cache('documents', hash, async () => {
949
- const documents = await context.loadDocuments(docs);
950
- return {
951
- documents,
952
- };
953
- });
954
- }));
955
- const documents = [];
956
- results.forEach(source => documents.push(...source.documents));
957
- if (documents.length > 0) {
958
- outputDocuments.push(...documents);
940
+ const documentPointerMap = {};
941
+ const allDocumentsUnnormalizedPointers = [...rootDocuments, ...outputSpecificDocuments];
942
+ for (const unnormalizedPtr of allDocumentsUnnormalizedPointers) {
943
+ if (typeof unnormalizedPtr === 'string') {
944
+ documentPointerMap[unnormalizedPtr] = {};
945
+ }
946
+ else if (typeof unnormalizedPtr === 'object') {
947
+ Object.assign(documentPointerMap, unnormalizedPtr);
948
+ }
959
949
  }
950
+ const hash = JSON.stringify(documentPointerMap);
951
+ const result = await cache('documents', hash, async () => {
952
+ const documents = await context.loadDocuments(documentPointerMap);
953
+ return {
954
+ documents,
955
+ };
956
+ });
957
+ outputDocuments = await result.documents;
960
958
  }, filename, `Load GraphQL documents: ${filename}`),
961
959
  },
962
960
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.6.4",
3
+ "version": "2.6.5-alpha-43974d1af.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
  },
@@ -1,3 +0,0 @@
1
- declare const isBrowser: boolean;
2
- declare const isNode: boolean;
3
- export { isBrowser, isNode };
@@ -1,2 +0,0 @@
1
- import { DocumentNode, GraphQLSchema } from 'graphql';
2
- export declare function tryToBuildSchema(schema: DocumentNode): GraphQLSchema;