@graphql-codegen/cli 2.5.0 → 2.6.0-alpha-bbecef04a.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;
|
|
@@ -782,14 +813,14 @@ class CodegenContext {
|
|
|
782
813
|
}
|
|
783
814
|
return loadSchema(pointer, config);
|
|
784
815
|
}
|
|
785
|
-
async loadDocuments(
|
|
816
|
+
async loadDocuments(input) {
|
|
786
817
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
787
818
|
if (this._graphqlConfig) {
|
|
788
819
|
// TODO: pointer won't work here
|
|
789
|
-
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
820
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(input.pointer, config);
|
|
790
821
|
return documents;
|
|
791
822
|
}
|
|
792
|
-
return loadDocuments(pointer, config);
|
|
823
|
+
return loadDocuments(input.pointer, config, input.schema);
|
|
793
824
|
}
|
|
794
825
|
}
|
|
795
826
|
function ensureContext(input) {
|
|
@@ -893,7 +924,7 @@ async function executeCodegen(input) {
|
|
|
893
924
|
const documentsLoadingCache = createCache(async function (hash) {
|
|
894
925
|
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
895
926
|
return {
|
|
896
|
-
documents
|
|
927
|
+
documents,
|
|
897
928
|
};
|
|
898
929
|
});
|
|
899
930
|
function wrapTask(task, source, taskName) {
|
|
@@ -1024,7 +1055,7 @@ async function executeCodegen(input) {
|
|
|
1024
1055
|
debugLog(`[CLI] Loading Documents`);
|
|
1025
1056
|
// get different cache for shared docs and output specific docs
|
|
1026
1057
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
1027
|
-
const hash = JSON.stringify(docs);
|
|
1058
|
+
const hash = JSON.stringify({ pointer: docs, schema: outputSchema });
|
|
1028
1059
|
return documentsLoadingCache.load(hash);
|
|
1029
1060
|
}));
|
|
1030
1061
|
const documents = [];
|
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
|
@@ -111,6 +111,9 @@ export declare class CodegenContext {
|
|
|
111
111
|
[key: string]: any;
|
|
112
112
|
};
|
|
113
113
|
loadSchema(pointer: Types.Schema): Promise<GraphQLSchema>;
|
|
114
|
-
loadDocuments(
|
|
114
|
+
loadDocuments(input: {
|
|
115
|
+
pointer: Types.OperationDocument[];
|
|
116
|
+
schema: GraphQLSchema;
|
|
117
|
+
}): Promise<Types.DocumentFile[]>;
|
|
115
118
|
}
|
|
116
119
|
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;
|
|
@@ -700,14 +731,14 @@ class CodegenContext {
|
|
|
700
731
|
}
|
|
701
732
|
return loadSchema(pointer, config);
|
|
702
733
|
}
|
|
703
|
-
async loadDocuments(
|
|
734
|
+
async loadDocuments(input) {
|
|
704
735
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
705
736
|
if (this._graphqlConfig) {
|
|
706
737
|
// TODO: pointer won't work here
|
|
707
|
-
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
738
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(input.pointer, config);
|
|
708
739
|
return documents;
|
|
709
740
|
}
|
|
710
|
-
return loadDocuments(pointer, config);
|
|
741
|
+
return loadDocuments(input.pointer, config, input.schema);
|
|
711
742
|
}
|
|
712
743
|
}
|
|
713
744
|
function ensureContext(input) {
|
|
@@ -811,7 +842,7 @@ async function executeCodegen(input) {
|
|
|
811
842
|
const documentsLoadingCache = createCache(async function (hash) {
|
|
812
843
|
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
813
844
|
return {
|
|
814
|
-
documents
|
|
845
|
+
documents,
|
|
815
846
|
};
|
|
816
847
|
});
|
|
817
848
|
function wrapTask(task, source, taskName) {
|
|
@@ -942,7 +973,7 @@ async function executeCodegen(input) {
|
|
|
942
973
|
debugLog(`[CLI] Loading Documents`);
|
|
943
974
|
// get different cache for shared docs and output specific docs
|
|
944
975
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
945
|
-
const hash = JSON.stringify(docs);
|
|
976
|
+
const hash = JSON.stringify({ pointer: docs, schema: outputSchema });
|
|
946
977
|
return documentsLoadingCache.load(hash);
|
|
947
978
|
}));
|
|
948
979
|
const documents = [];
|
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;
|
|
@@ -673,14 +704,14 @@ class CodegenContext {
|
|
|
673
704
|
}
|
|
674
705
|
return loadSchema(pointer, config);
|
|
675
706
|
}
|
|
676
|
-
async loadDocuments(
|
|
707
|
+
async loadDocuments(input) {
|
|
677
708
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
678
709
|
if (this._graphqlConfig) {
|
|
679
710
|
// TODO: pointer won't work here
|
|
680
|
-
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(pointer, config);
|
|
711
|
+
const documents = await this._graphqlConfig.getProject(this._project).loadDocuments(input.pointer, config);
|
|
681
712
|
return documents;
|
|
682
713
|
}
|
|
683
|
-
return loadDocuments(pointer, config);
|
|
714
|
+
return loadDocuments(input.pointer, config, input.schema);
|
|
684
715
|
}
|
|
685
716
|
}
|
|
686
717
|
function ensureContext(input) {
|
|
@@ -784,7 +815,7 @@ async function executeCodegen(input) {
|
|
|
784
815
|
const documentsLoadingCache = createCache(async function (hash) {
|
|
785
816
|
const documents = await context.loadDocuments(JSON.parse(hash));
|
|
786
817
|
return {
|
|
787
|
-
documents
|
|
818
|
+
documents,
|
|
788
819
|
};
|
|
789
820
|
});
|
|
790
821
|
function wrapTask(task, source, taskName) {
|
|
@@ -915,7 +946,7 @@ async function executeCodegen(input) {
|
|
|
915
946
|
debugLog(`[CLI] Loading Documents`);
|
|
916
947
|
// get different cache for shared docs and output specific docs
|
|
917
948
|
const results = await Promise.all([rootDocuments, outputSpecificDocuments].map(docs => {
|
|
918
|
-
const hash = JSON.stringify(docs);
|
|
949
|
+
const hash = JSON.stringify({ pointer: docs, schema: outputSchema });
|
|
919
950
|
return documentsLoadingCache.load(hash);
|
|
920
951
|
}));
|
|
921
952
|
const documents = [];
|
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.6.0-alpha-bbecef04a.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.5.0",
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "
|
|
8
|
+
"@graphql-codegen/core": "2.5.1-alpha-bbecef04a.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "2.4.1-alpha-bbecef04a.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",
|