@graphql-codegen/cli 2.6.0-alpha-c9d165f6a.0 → 2.6.0-alpha-679ebe9ab.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
@@ -730,32 +730,6 @@ function updateContextWithCliFlags(context, cliFlags) {
730
730
  class CodegenContext {
731
731
  constructor({ config, graphqlConfig, filepath, }) {
732
732
  this._pluginContext = {};
733
- this.loadSchema = useCache((pointer) => {
734
- const config = this.getConfig(defaultSchemaLoadOptions);
735
- if (this._graphqlConfig) {
736
- // TODO: SchemaWithLoader won't work here
737
- return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
738
- }
739
- return loadSchema(pointer, config);
740
- }, {
741
- cacheKey(pointer) {
742
- return JSON.stringify(pointer);
743
- },
744
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
745
- });
746
- this.loadDocuments = useCache((pointer) => {
747
- const config = this.getConfig(defaultDocumentsLoadOptions);
748
- if (this._graphqlConfig) {
749
- // TODO: pointer won't work here
750
- return this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
751
- }
752
- return loadDocuments(pointer, config);
753
- }, {
754
- cacheKey(pointer) {
755
- return JSON.stringify(pointer);
756
- },
757
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
758
- });
759
733
  this._config = config;
760
734
  this._graphqlConfig = graphqlConfig;
761
735
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -801,28 +775,27 @@ class CodegenContext {
801
775
  getPluginContext() {
802
776
  return this._pluginContext;
803
777
  }
778
+ async loadSchema(pointer) {
779
+ const config = this.getConfig(defaultSchemaLoadOptions);
780
+ if (this._graphqlConfig) {
781
+ // TODO: SchemaWithLoader won't work here
782
+ return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
783
+ }
784
+ return loadSchema(pointer, config);
785
+ }
786
+ async loadDocuments(pointer) {
787
+ const config = this.getConfig(defaultDocumentsLoadOptions);
788
+ if (this._graphqlConfig) {
789
+ // TODO: pointer won't work here
790
+ const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
791
+ return documents;
792
+ }
793
+ return loadDocuments(pointer, config);
794
+ }
804
795
  }
805
796
  function ensureContext(input) {
806
797
  return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
807
798
  }
808
- /**
809
- * The goal here is to avoid loading the same schema or documents across projects.
810
- */
811
- function useCache(originalFunction, { cacheKey, skip = () => false }) {
812
- if (skip()) {
813
- return originalFunction;
814
- }
815
- const cache = new Map();
816
- return (input) => {
817
- const key = cacheKey(input);
818
- if (cache.has(key)) {
819
- return cache.get(key);
820
- }
821
- const result = originalFunction(input);
822
- cache.set(key, result);
823
- return result;
824
- };
825
- }
826
799
 
827
800
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
828
801
  const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
package/config.d.ts CHANGED
@@ -110,7 +110,7 @@ export declare class CodegenContext {
110
110
  getPluginContext(): {
111
111
  [key: string]: any;
112
112
  };
113
- loadSchema: (input: Types.Schema) => Promise<GraphQLSchema>;
114
- loadDocuments: (input: Types.OperationDocument[]) => Promise<import("graphql-config").Source[]>;
113
+ loadSchema(pointer: Types.Schema): Promise<GraphQLSchema>;
114
+ loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
115
115
  }
116
116
  export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
package/index.js CHANGED
@@ -648,32 +648,6 @@ function updateContextWithCliFlags(context, cliFlags) {
648
648
  class CodegenContext {
649
649
  constructor({ config, graphqlConfig, filepath, }) {
650
650
  this._pluginContext = {};
651
- this.loadSchema = useCache((pointer) => {
652
- const config = this.getConfig(defaultSchemaLoadOptions);
653
- if (this._graphqlConfig) {
654
- // TODO: SchemaWithLoader won't work here
655
- return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
656
- }
657
- return loadSchema(pointer, config);
658
- }, {
659
- cacheKey(pointer) {
660
- return JSON.stringify(pointer);
661
- },
662
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
663
- });
664
- this.loadDocuments = useCache((pointer) => {
665
- const config = this.getConfig(defaultDocumentsLoadOptions);
666
- if (this._graphqlConfig) {
667
- // TODO: pointer won't work here
668
- return this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
669
- }
670
- return loadDocuments(pointer, config);
671
- }, {
672
- cacheKey(pointer) {
673
- return JSON.stringify(pointer);
674
- },
675
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
676
- });
677
651
  this._config = config;
678
652
  this._graphqlConfig = graphqlConfig;
679
653
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -719,28 +693,27 @@ class CodegenContext {
719
693
  getPluginContext() {
720
694
  return this._pluginContext;
721
695
  }
696
+ async loadSchema(pointer) {
697
+ const config = this.getConfig(defaultSchemaLoadOptions);
698
+ if (this._graphqlConfig) {
699
+ // TODO: SchemaWithLoader won't work here
700
+ return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
701
+ }
702
+ return loadSchema(pointer, config);
703
+ }
704
+ async loadDocuments(pointer) {
705
+ const config = this.getConfig(defaultDocumentsLoadOptions);
706
+ if (this._graphqlConfig) {
707
+ // TODO: pointer won't work here
708
+ const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
709
+ return documents;
710
+ }
711
+ return loadDocuments(pointer, config);
712
+ }
722
713
  }
723
714
  function ensureContext(input) {
724
715
  return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
725
716
  }
726
- /**
727
- * The goal here is to avoid loading the same schema or documents across projects.
728
- */
729
- function useCache(originalFunction, { cacheKey, skip = () => false }) {
730
- if (skip()) {
731
- return originalFunction;
732
- }
733
- const cache = new Map();
734
- return (input) => {
735
- const key = cacheKey(input);
736
- if (cache.has(key)) {
737
- return cache.get(key);
738
- }
739
- const result = originalFunction(input);
740
- cache.set(key, result);
741
- return result;
742
- };
743
- }
744
717
 
745
718
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
746
719
  const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
package/index.mjs CHANGED
@@ -621,32 +621,6 @@ function updateContextWithCliFlags(context, cliFlags) {
621
621
  class CodegenContext {
622
622
  constructor({ config, graphqlConfig, filepath, }) {
623
623
  this._pluginContext = {};
624
- this.loadSchema = useCache((pointer) => {
625
- const config = this.getConfig(defaultSchemaLoadOptions);
626
- if (this._graphqlConfig) {
627
- // TODO: SchemaWithLoader won't work here
628
- return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
629
- }
630
- return loadSchema(pointer, config);
631
- }, {
632
- cacheKey(pointer) {
633
- return JSON.stringify(pointer);
634
- },
635
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
636
- });
637
- this.loadDocuments = useCache((pointer) => {
638
- const config = this.getConfig(defaultDocumentsLoadOptions);
639
- if (this._graphqlConfig) {
640
- // TODO: pointer won't work here
641
- return this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
642
- }
643
- return loadDocuments(pointer, config);
644
- }, {
645
- cacheKey(pointer) {
646
- return JSON.stringify(pointer);
647
- },
648
- skip: () => { var _a; return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.watch); },
649
- });
650
624
  this._config = config;
651
625
  this._graphqlConfig = graphqlConfig;
652
626
  this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
@@ -692,28 +666,27 @@ class CodegenContext {
692
666
  getPluginContext() {
693
667
  return this._pluginContext;
694
668
  }
669
+ async loadSchema(pointer) {
670
+ const config = this.getConfig(defaultSchemaLoadOptions);
671
+ if (this._graphqlConfig) {
672
+ // TODO: SchemaWithLoader won't work here
673
+ return this._graphqlConfig.getProject(this._project).loadSchema(pointer, 'GraphQLSchema', config);
674
+ }
675
+ return loadSchema(pointer, config);
676
+ }
677
+ async loadDocuments(pointer) {
678
+ const config = this.getConfig(defaultDocumentsLoadOptions);
679
+ if (this._graphqlConfig) {
680
+ // TODO: pointer won't work here
681
+ const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
682
+ return documents;
683
+ }
684
+ return loadDocuments(pointer, config);
685
+ }
695
686
  }
696
687
  function ensureContext(input) {
697
688
  return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
698
689
  }
699
- /**
700
- * The goal here is to avoid loading the same schema or documents across projects.
701
- */
702
- function useCache(originalFunction, { cacheKey, skip = () => false }) {
703
- if (skip()) {
704
- return originalFunction;
705
- }
706
- const cache = new Map();
707
- return (input) => {
708
- const key = cacheKey(input);
709
- if (cache.has(key)) {
710
- return cache.get(key);
711
- }
712
- const result = originalFunction(input);
713
- cache.set(key, result);
714
- return result;
715
- };
716
- }
717
690
 
718
691
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
719
692
  const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.6.0-alpha-c9d165f6a.0",
3
+ "version": "2.6.0-alpha-679ebe9ab.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
  },