Skip to content

Commit 5930f73

Browse files
committed
Implement filePerOperation logic
1 parent 4599a9e commit 5930f73

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

packages/presets/near-operation-file/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,14 @@ export const preset: Types.OutputPreset<NearOperationFileConfig> = {
264264
schemaObject,
265265
{
266266
baseDir,
267-
generateFilePath(location: string) {
267+
generateFilePath(location, operationName) {
268268
const newFilePath = defineFilepathSubfolder(location, folder);
269269

270-
return appendFileNameToFilePath(newFilePath, fileName, extension);
270+
return appendFileNameToFilePath(
271+
newFilePath,
272+
filePerOperation ? operationName : fileName,
273+
extension,
274+
);
271275
},
272276
schemaTypesSource: {
273277
path: shouldAbsolute ? join(options.baseOutputDir, baseTypesPath) : baseTypesPath,

packages/presets/near-operation-file/src/resolve-document-imports.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type DocumentImportResolverOptions = {
2525
/**
2626
* Generates a target file path from the source `document.location`
2727
*/
28-
generateFilePath: (location: string) => string;
28+
generateFilePath: (location: string, operationName: string) => string;
2929
/**
3030
* Schema base types source
3131
*/
@@ -69,7 +69,12 @@ export function resolveDocumentImports<T>(
6969

7070
return documents.map(documentFile => {
7171
try {
72-
const generatedFilePath = generateFilePath(documentFile.location);
72+
// FIXME
73+
const operationName =
74+
documentFile.document.definitions.find(d => d.kind === 'OperationDefinition')?.name
75+
?.value ?? documentFile.document.definitions[0].name.value;
76+
77+
const generatedFilePath = generateFilePath(documentFile.location, operationName);
7378
const importStatements: string[] = [];
7479
const { externalFragments, fragmentImports } = resolveFragments(
7580
generatedFilePath,

0 commit comments

Comments
 (0)