@graphql-codegen/cli 2.4.0 → 2.5.0-alpha-bc33c031d.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 +42 -11
- package/codegen.d.ts +1 -0
- package/config.d.ts +4 -1
- package/index.js +42 -11
- package/index.mjs +42 -11
- package/load.d.ts +1 -1
- package/package.json +3 -3
package/bin.js
CHANGED
|
@@ -505,20 +505,30 @@ async function loadSchema(schemaPointers, config) {
|
|
|
505
505
|
|
|
506
506
|
${e.message || e}
|
|
507
507
|
${e.stack || ''}
|
|
508
|
-
|
|
508
|
+
|
|
509
509
|
GraphQL Code Generator supports:
|
|
510
510
|
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
511
511
|
- Introspection JSON File
|
|
512
512
|
- URL of GraphQL endpoint
|
|
513
513
|
- Multiple files with type definitions (glob expression)
|
|
514
514
|
- String in config file
|
|
515
|
-
|
|
515
|
+
|
|
516
516
|
Try to use one of above options and run codegen again.
|
|
517
|
-
|
|
517
|
+
|
|
518
518
|
`);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
|
-
async
|
|
521
|
+
const requiredLoader = async (pointers, schema) => {
|
|
522
|
+
return Promise.all(pointers.map(async (pointer) => {
|
|
523
|
+
const userLoader = (await makeDefaultLoader(process.cwd())(pointer.require)).default;
|
|
524
|
+
const documents = userLoader(pointer.config || {}, schema);
|
|
525
|
+
return documents;
|
|
526
|
+
})).then(results => [].concat(...results));
|
|
527
|
+
};
|
|
528
|
+
const isRequirePointer = (pointer) => {
|
|
529
|
+
return typeof pointer === 'object' && 'require' in pointer;
|
|
530
|
+
};
|
|
531
|
+
async function loadDocuments(documentPointers, config, schema) {
|
|
522
532
|
const loaders = [
|
|
523
533
|
new codeFileLoader.CodeFileLoader({
|
|
524
534
|
pluckConfig: {
|
|
@@ -537,14 +547,35 @@ async function loadDocuments(documentPointers, config) {
|
|
|
537
547
|
}
|
|
538
548
|
ignore.push(path.join(process.cwd(), generatePath));
|
|
539
549
|
}
|
|
540
|
-
const
|
|
550
|
+
const loaderPointers = [];
|
|
551
|
+
const requestPointers = [];
|
|
552
|
+
if (Array.isArray(documentPointers)) {
|
|
553
|
+
documentPointers.forEach(pointer => {
|
|
554
|
+
if (isRequirePointer(pointer)) {
|
|
555
|
+
requestPointers.push(pointer);
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
loaderPointers.push(pointer);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
if (isRequirePointer(documentPointers)) {
|
|
564
|
+
requestPointers.push(documentPointers);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
loaderPointers.push(documentPointers);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const loadedFromToolkit = await load.loadDocuments(loaderPointers, {
|
|
541
571
|
...defaultDocumentsLoadOptions,
|
|
542
572
|
ignore,
|
|
543
573
|
loaders,
|
|
544
574
|
...config,
|
|
545
575
|
...config.config,
|
|
546
576
|
});
|
|
547
|
-
|
|
577
|
+
const loadedAlterantively = await requiredLoader(requestPointers, schema);
|
|
578
|
+
return [...loadedFromToolkit, ...loadedAlterantively];
|
|
548
579
|
}
|
|
549
580
|
|
|
550
581
|
const { lstat } = fs.promises;
|
|
@@ -767,14 +798,14 @@ class CodegenContext {
|
|
|
767
798
|
}
|
|
768
799
|
return loadSchema(pointer, config);
|
|
769
800
|
}
|
|
770
|
-
async loadDocuments(
|
|
801
|
+
async loadDocuments(input) {
|
|
771
802
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
772
803
|
if (this._graphqlConfig) {
|
|
773
804
|
// TODO: pointer won't work here
|
|
774
|
-
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
805
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(input.pointer, config);
|
|
775
806
|
return documents;
|
|
776
807
|
}
|
|
777
|
-
return loadDocuments(pointer, config);
|
|
808
|
+
return loadDocuments(input.pointer, config, input.schema);
|
|
778
809
|
}
|
|
779
810
|
}
|
|
780
811
|
function ensureContext(input) {
|
|
@@ -864,7 +895,7 @@ async function executeCodegen(input) {
|
|
|
864
895
|
const documentsLoadingCache = createCache(async function (hash) {
|
|
865
896
|
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
866
897
|
return {
|
|
867
|
-
documents
|
|
898
|
+
documents,
|
|
868
899
|
};
|
|
869
900
|
});
|
|
870
901
|
async function normalize() {
|
|
@@ -979,7 +1010,7 @@ async function executeCodegen(input) {
|
|
|
979
1010
|
task: wrapTask(async () => {
|
|
980
1011
|
debugLog(`[CLI] Loading Documents`);
|
|
981
1012
|
const allDocuments = [...rootDocuments, ...outputSpecificDocuments];
|
|
982
|
-
const hash = JSON.stringify(allDocuments);
|
|
1013
|
+
const hash = JSON.stringify({ pointer: allDocuments, schema: outputSchema });
|
|
983
1014
|
const result = await documentsLoadingCache.load(hash);
|
|
984
1015
|
const documents = result.documents;
|
|
985
1016
|
if (documents.length > 0) {
|
package/codegen.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from './config';
|
|
3
|
+
export declare const makeDefaultLoader: (from: string) => (mod: string) => Promise<any>;
|
|
3
4
|
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<Types.FileOutput[]>;
|
package/config.d.ts
CHANGED
|
@@ -103,6 +103,9 @@ export declare class CodegenContext {
|
|
|
103
103
|
[key: string]: any;
|
|
104
104
|
};
|
|
105
105
|
loadSchema(pointer: Types.Schema): Promise<GraphQLSchema>;
|
|
106
|
-
loadDocuments(
|
|
106
|
+
loadDocuments(input: {
|
|
107
|
+
pointer: Types.OperationDocument[];
|
|
108
|
+
schema: GraphQLSchema;
|
|
109
|
+
}): Promise<Types.DocumentFile[]>;
|
|
107
110
|
}
|
|
108
111
|
export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
|
package/index.js
CHANGED
|
@@ -423,20 +423,30 @@ async function loadSchema(schemaPointers, config) {
|
|
|
423
423
|
|
|
424
424
|
${e.message || e}
|
|
425
425
|
${e.stack || ''}
|
|
426
|
-
|
|
426
|
+
|
|
427
427
|
GraphQL Code Generator supports:
|
|
428
428
|
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
429
429
|
- Introspection JSON File
|
|
430
430
|
- URL of GraphQL endpoint
|
|
431
431
|
- Multiple files with type definitions (glob expression)
|
|
432
432
|
- String in config file
|
|
433
|
-
|
|
433
|
+
|
|
434
434
|
Try to use one of above options and run codegen again.
|
|
435
|
-
|
|
435
|
+
|
|
436
436
|
`);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
async
|
|
439
|
+
const requiredLoader = async (pointers, schema) => {
|
|
440
|
+
return Promise.all(pointers.map(async (pointer) => {
|
|
441
|
+
const userLoader = (await makeDefaultLoader(process.cwd())(pointer.require)).default;
|
|
442
|
+
const documents = userLoader(pointer.config || {}, schema);
|
|
443
|
+
return documents;
|
|
444
|
+
})).then(results => [].concat(...results));
|
|
445
|
+
};
|
|
446
|
+
const isRequirePointer = (pointer) => {
|
|
447
|
+
return typeof pointer === 'object' && 'require' in pointer;
|
|
448
|
+
};
|
|
449
|
+
async function loadDocuments(documentPointers, config, schema) {
|
|
440
450
|
const loaders = [
|
|
441
451
|
new codeFileLoader.CodeFileLoader({
|
|
442
452
|
pluckConfig: {
|
|
@@ -455,14 +465,35 @@ async function loadDocuments(documentPointers, config) {
|
|
|
455
465
|
}
|
|
456
466
|
ignore.push(path.join(process.cwd(), generatePath));
|
|
457
467
|
}
|
|
458
|
-
const
|
|
468
|
+
const loaderPointers = [];
|
|
469
|
+
const requestPointers = [];
|
|
470
|
+
if (Array.isArray(documentPointers)) {
|
|
471
|
+
documentPointers.forEach(pointer => {
|
|
472
|
+
if (isRequirePointer(pointer)) {
|
|
473
|
+
requestPointers.push(pointer);
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
loaderPointers.push(pointer);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
if (isRequirePointer(documentPointers)) {
|
|
482
|
+
requestPointers.push(documentPointers);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
loaderPointers.push(documentPointers);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const loadedFromToolkit = await load.loadDocuments(loaderPointers, {
|
|
459
489
|
...defaultDocumentsLoadOptions,
|
|
460
490
|
ignore,
|
|
461
491
|
loaders,
|
|
462
492
|
...config,
|
|
463
493
|
...config.config,
|
|
464
494
|
});
|
|
465
|
-
|
|
495
|
+
const loadedAlterantively = await requiredLoader(requestPointers, schema);
|
|
496
|
+
return [...loadedFromToolkit, ...loadedAlterantively];
|
|
466
497
|
}
|
|
467
498
|
|
|
468
499
|
const { lstat } = fs.promises;
|
|
@@ -685,14 +716,14 @@ class CodegenContext {
|
|
|
685
716
|
}
|
|
686
717
|
return loadSchema(pointer, config);
|
|
687
718
|
}
|
|
688
|
-
async loadDocuments(
|
|
719
|
+
async loadDocuments(input) {
|
|
689
720
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
690
721
|
if (this._graphqlConfig) {
|
|
691
722
|
// TODO: pointer won't work here
|
|
692
|
-
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
723
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(input.pointer, config);
|
|
693
724
|
return documents;
|
|
694
725
|
}
|
|
695
|
-
return loadDocuments(pointer, config);
|
|
726
|
+
return loadDocuments(input.pointer, config, input.schema);
|
|
696
727
|
}
|
|
697
728
|
}
|
|
698
729
|
function ensureContext(input) {
|
|
@@ -782,7 +813,7 @@ async function executeCodegen(input) {
|
|
|
782
813
|
const documentsLoadingCache = createCache(async function (hash) {
|
|
783
814
|
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
784
815
|
return {
|
|
785
|
-
documents
|
|
816
|
+
documents,
|
|
786
817
|
};
|
|
787
818
|
});
|
|
788
819
|
async function normalize() {
|
|
@@ -897,7 +928,7 @@ async function executeCodegen(input) {
|
|
|
897
928
|
task: wrapTask(async () => {
|
|
898
929
|
debugLog(`[CLI] Loading Documents`);
|
|
899
930
|
const allDocuments = [...rootDocuments, ...outputSpecificDocuments];
|
|
900
|
-
const hash = JSON.stringify(allDocuments);
|
|
931
|
+
const hash = JSON.stringify({ pointer: allDocuments, schema: outputSchema });
|
|
901
932
|
const result = await documentsLoadingCache.load(hash);
|
|
902
933
|
const documents = result.documents;
|
|
903
934
|
if (documents.length > 0) {
|
package/index.mjs
CHANGED
|
@@ -396,20 +396,30 @@ async function loadSchema(schemaPointers, config) {
|
|
|
396
396
|
|
|
397
397
|
${e.message || e}
|
|
398
398
|
${e.stack || ''}
|
|
399
|
-
|
|
399
|
+
|
|
400
400
|
GraphQL Code Generator supports:
|
|
401
401
|
- ES Modules and CommonJS exports (export as default or named export "schema")
|
|
402
402
|
- Introspection JSON File
|
|
403
403
|
- URL of GraphQL endpoint
|
|
404
404
|
- Multiple files with type definitions (glob expression)
|
|
405
405
|
- String in config file
|
|
406
|
-
|
|
406
|
+
|
|
407
407
|
Try to use one of above options and run codegen again.
|
|
408
|
-
|
|
408
|
+
|
|
409
409
|
`);
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
async
|
|
412
|
+
const requiredLoader = async (pointers, schema) => {
|
|
413
|
+
return Promise.all(pointers.map(async (pointer) => {
|
|
414
|
+
const userLoader = (await makeDefaultLoader(process.cwd())(pointer.require)).default;
|
|
415
|
+
const documents = userLoader(pointer.config || {}, schema);
|
|
416
|
+
return documents;
|
|
417
|
+
})).then(results => [].concat(...results));
|
|
418
|
+
};
|
|
419
|
+
const isRequirePointer = (pointer) => {
|
|
420
|
+
return typeof pointer === 'object' && 'require' in pointer;
|
|
421
|
+
};
|
|
422
|
+
async function loadDocuments(documentPointers, config, schema) {
|
|
413
423
|
const loaders = [
|
|
414
424
|
new CodeFileLoader({
|
|
415
425
|
pluckConfig: {
|
|
@@ -428,14 +438,35 @@ async function loadDocuments(documentPointers, config) {
|
|
|
428
438
|
}
|
|
429
439
|
ignore.push(join(process.cwd(), generatePath));
|
|
430
440
|
}
|
|
431
|
-
const
|
|
441
|
+
const loaderPointers = [];
|
|
442
|
+
const requestPointers = [];
|
|
443
|
+
if (Array.isArray(documentPointers)) {
|
|
444
|
+
documentPointers.forEach(pointer => {
|
|
445
|
+
if (isRequirePointer(pointer)) {
|
|
446
|
+
requestPointers.push(pointer);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
loaderPointers.push(pointer);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
if (isRequirePointer(documentPointers)) {
|
|
455
|
+
requestPointers.push(documentPointers);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
loaderPointers.push(documentPointers);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const loadedFromToolkit = await loadDocuments$1(loaderPointers, {
|
|
432
462
|
...defaultDocumentsLoadOptions,
|
|
433
463
|
ignore,
|
|
434
464
|
loaders,
|
|
435
465
|
...config,
|
|
436
466
|
...config.config,
|
|
437
467
|
});
|
|
438
|
-
|
|
468
|
+
const loadedAlterantively = await requiredLoader(requestPointers, schema);
|
|
469
|
+
return [...loadedFromToolkit, ...loadedAlterantively];
|
|
439
470
|
}
|
|
440
471
|
|
|
441
472
|
const { lstat } = promises;
|
|
@@ -658,14 +689,14 @@ class CodegenContext {
|
|
|
658
689
|
}
|
|
659
690
|
return loadSchema(pointer, config);
|
|
660
691
|
}
|
|
661
|
-
async loadDocuments(
|
|
692
|
+
async loadDocuments(input) {
|
|
662
693
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
663
694
|
if (this._graphqlConfig) {
|
|
664
695
|
// TODO: pointer won't work here
|
|
665
|
-
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
696
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(input.pointer, config);
|
|
666
697
|
return documents;
|
|
667
698
|
}
|
|
668
|
-
return loadDocuments(pointer, config);
|
|
699
|
+
return loadDocuments(input.pointer, config, input.schema);
|
|
669
700
|
}
|
|
670
701
|
}
|
|
671
702
|
function ensureContext(input) {
|
|
@@ -755,7 +786,7 @@ async function executeCodegen(input) {
|
|
|
755
786
|
const documentsLoadingCache = createCache(async function (hash) {
|
|
756
787
|
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
757
788
|
return {
|
|
758
|
-
documents
|
|
789
|
+
documents,
|
|
759
790
|
};
|
|
760
791
|
});
|
|
761
792
|
async function normalize() {
|
|
@@ -870,7 +901,7 @@ async function executeCodegen(input) {
|
|
|
870
901
|
task: wrapTask(async () => {
|
|
871
902
|
debugLog(`[CLI] Loading Documents`);
|
|
872
903
|
const allDocuments = [...rootDocuments, ...outputSpecificDocuments];
|
|
873
|
-
const hash = JSON.stringify(allDocuments);
|
|
904
|
+
const hash = JSON.stringify({ pointer: allDocuments, schema: outputSchema });
|
|
874
905
|
const result = await documentsLoadingCache.load(hash);
|
|
875
906
|
const documents = result.documents;
|
|
876
907
|
if (documents.length > 0) {
|
package/load.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export declare const defaultDocumentsLoadOptions: {
|
|
|
12
12
|
skipGraphQLImport: boolean;
|
|
13
13
|
};
|
|
14
14
|
export declare function loadSchema(schemaPointers: UnnormalizedTypeDefPointer, config: Types.Config): Promise<GraphQLSchema>;
|
|
15
|
-
export declare function loadDocuments(documentPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], config: Types.Config): Promise<Types.DocumentFile[]>;
|
|
15
|
+
export declare function loadDocuments(documentPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], config: Types.Config, schema: GraphQLSchema): Promise<Types.DocumentFile[]>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-alpha-bc33c031d.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.4.0",
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "
|
|
8
|
+
"@graphql-codegen/core": "2.4.1-alpha-bc33c031d.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "2.3.3-alpha-bc33c031d.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",
|