@nmarks/graphql-codegen-per-operation-file-preset 1.0.7 → 1.0.8
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/cjs/index.js +10 -26
- package/esm/index.js +10 -26
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -337,21 +337,6 @@ exports.preset = {
|
|
|
337
337
|
...updatedFragmentImports,
|
|
338
338
|
...localFragmentImports,
|
|
339
339
|
];
|
|
340
|
-
/**
|
|
341
|
-
* ADD EXTERNAL FRAGMENTS TO DOCUMENT
|
|
342
|
-
*
|
|
343
|
-
* The plugin needs external fragment definitions in the document to properly resolve types.
|
|
344
|
-
* Without these, fragment spreads can't be expanded correctly.
|
|
345
|
-
*/
|
|
346
|
-
const singleDefDocumentWithFragments = {
|
|
347
|
-
...singleDefDocument,
|
|
348
|
-
definitions: [
|
|
349
|
-
...singleDefDocument.definitions,
|
|
350
|
-
...allExternalFragments.map(fragment => fragment.node),
|
|
351
|
-
],
|
|
352
|
-
};
|
|
353
|
-
// Update the source to use the document with external fragments
|
|
354
|
-
singleDefSource.document = singleDefDocumentWithFragments;
|
|
355
340
|
/**
|
|
356
341
|
* CHECK IF TYPES IMPORT IS NEEDED
|
|
357
342
|
*
|
|
@@ -362,7 +347,17 @@ exports.preset = {
|
|
|
362
347
|
* - Operations (all operations generate Variables type using Types.Exact)
|
|
363
348
|
*
|
|
364
349
|
* We DON'T import for just object type references (e.g., fragment on User)
|
|
350
|
+
*
|
|
351
|
+
* Note: We check against a document WITH external fragments for type detection,
|
|
352
|
+
* but we DON'T pass this to the plugin (that would create duplicate definitions).
|
|
365
353
|
*/
|
|
354
|
+
const singleDefDocumentWithFragments = {
|
|
355
|
+
...singleDefDocument,
|
|
356
|
+
definitions: [
|
|
357
|
+
...singleDefDocument.definitions,
|
|
358
|
+
...allExternalFragments.map(fragment => fragment.node),
|
|
359
|
+
],
|
|
360
|
+
};
|
|
366
361
|
const needsTypesImport = needsSchemaTypesImport(singleDefDocumentWithFragments, schemaObject, options.config);
|
|
367
362
|
// Generate the schema types import statement if needed
|
|
368
363
|
const importStatements = [];
|
|
@@ -401,17 +396,6 @@ exports.preset = {
|
|
|
401
396
|
externalFragments: allExternalFragments, // Includes both external + local fragments
|
|
402
397
|
fragmentImports: allFragmentImports, // Import declarations for all fragments
|
|
403
398
|
};
|
|
404
|
-
// DEBUG: Log fragment generation details
|
|
405
|
-
if (name === 'Items_item') {
|
|
406
|
-
console.log('\n=== GENERATING Items_item ===');
|
|
407
|
-
console.log('External fragments:', allExternalFragments.map(f => ({ name: f.name, level: f.level })));
|
|
408
|
-
console.log('Fragment imports:', allFragmentImports.map(fi => fi.importSource.path));
|
|
409
|
-
console.log('Document selections:', definition.selectionSet.selections.map((s) => s.kind === 'Field' ? s.name.value : `...${s.name.value}`));
|
|
410
|
-
console.log('Document definitions (should be 1):', singleDefDocument.definitions.length);
|
|
411
|
-
console.log('singleDefDocumentWithFragments definitions:', singleDefDocumentWithFragments.definitions.length);
|
|
412
|
-
console.log(' - Main definition:', singleDefDocumentWithFragments.definitions[0].kind);
|
|
413
|
-
console.log(' - External fragments added:', singleDefDocumentWithFragments.definitions.slice(1).map((d) => d.name.value));
|
|
414
|
-
}
|
|
415
399
|
/**
|
|
416
400
|
* CREATE GENERATION ARTIFACT
|
|
417
401
|
*
|
package/esm/index.js
CHANGED
|
@@ -333,21 +333,6 @@ export const preset = {
|
|
|
333
333
|
...updatedFragmentImports,
|
|
334
334
|
...localFragmentImports,
|
|
335
335
|
];
|
|
336
|
-
/**
|
|
337
|
-
* ADD EXTERNAL FRAGMENTS TO DOCUMENT
|
|
338
|
-
*
|
|
339
|
-
* The plugin needs external fragment definitions in the document to properly resolve types.
|
|
340
|
-
* Without these, fragment spreads can't be expanded correctly.
|
|
341
|
-
*/
|
|
342
|
-
const singleDefDocumentWithFragments = {
|
|
343
|
-
...singleDefDocument,
|
|
344
|
-
definitions: [
|
|
345
|
-
...singleDefDocument.definitions,
|
|
346
|
-
...allExternalFragments.map(fragment => fragment.node),
|
|
347
|
-
],
|
|
348
|
-
};
|
|
349
|
-
// Update the source to use the document with external fragments
|
|
350
|
-
singleDefSource.document = singleDefDocumentWithFragments;
|
|
351
336
|
/**
|
|
352
337
|
* CHECK IF TYPES IMPORT IS NEEDED
|
|
353
338
|
*
|
|
@@ -358,7 +343,17 @@ export const preset = {
|
|
|
358
343
|
* - Operations (all operations generate Variables type using Types.Exact)
|
|
359
344
|
*
|
|
360
345
|
* We DON'T import for just object type references (e.g., fragment on User)
|
|
346
|
+
*
|
|
347
|
+
* Note: We check against a document WITH external fragments for type detection,
|
|
348
|
+
* but we DON'T pass this to the plugin (that would create duplicate definitions).
|
|
361
349
|
*/
|
|
350
|
+
const singleDefDocumentWithFragments = {
|
|
351
|
+
...singleDefDocument,
|
|
352
|
+
definitions: [
|
|
353
|
+
...singleDefDocument.definitions,
|
|
354
|
+
...allExternalFragments.map(fragment => fragment.node),
|
|
355
|
+
],
|
|
356
|
+
};
|
|
362
357
|
const needsTypesImport = needsSchemaTypesImport(singleDefDocumentWithFragments, schemaObject, options.config);
|
|
363
358
|
// Generate the schema types import statement if needed
|
|
364
359
|
const importStatements = [];
|
|
@@ -397,17 +392,6 @@ export const preset = {
|
|
|
397
392
|
externalFragments: allExternalFragments, // Includes both external + local fragments
|
|
398
393
|
fragmentImports: allFragmentImports, // Import declarations for all fragments
|
|
399
394
|
};
|
|
400
|
-
// DEBUG: Log fragment generation details
|
|
401
|
-
if (name === 'Items_item') {
|
|
402
|
-
console.log('\n=== GENERATING Items_item ===');
|
|
403
|
-
console.log('External fragments:', allExternalFragments.map(f => ({ name: f.name, level: f.level })));
|
|
404
|
-
console.log('Fragment imports:', allFragmentImports.map(fi => fi.importSource.path));
|
|
405
|
-
console.log('Document selections:', definition.selectionSet.selections.map((s) => s.kind === 'Field' ? s.name.value : `...${s.name.value}`));
|
|
406
|
-
console.log('Document definitions (should be 1):', singleDefDocument.definitions.length);
|
|
407
|
-
console.log('singleDefDocumentWithFragments definitions:', singleDefDocumentWithFragments.definitions.length);
|
|
408
|
-
console.log(' - Main definition:', singleDefDocumentWithFragments.definitions[0].kind);
|
|
409
|
-
console.log(' - External fragments added:', singleDefDocumentWithFragments.definitions.slice(1).map((d) => d.name.value));
|
|
410
|
-
}
|
|
411
395
|
/**
|
|
412
396
|
* CREATE GENERATION ARTIFACT
|
|
413
397
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nmarks/graphql-codegen-per-operation-file-preset",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "GraphQL Code Generator preset for generating one file per operation/fragment",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"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"
|