Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-bats-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/api-codegen-preset': patch
---

Fixed TypeScript module resolution error by including file extensions (.d.ts or .ts) in generated import paths to support Node16/NodeNext module resolution strategies.
8 changes: 7 additions & 1 deletion packages/api-clients/api-codegen-preset/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import {preset as hydrogenPreset} from '@shopify/graphql-codegen';

import {type ShopifyApiPresetConfig} from './types';
import {apiConfigs} from './helpers/api-configs';
import {getOutputFiles} from './helpers/get-output-files';

export const preset: Types.OutputPreset<ShopifyApiPresetConfig> = {
buildGeneratesSection: (options) => {
const apiType = options.presetConfig.apiType;

const {interfaceExtension, module, presetConfigs} = apiConfigs[apiType];
const typesFile = apiConfigs[apiType].typesFile;

// Determine if the output file is a declaration file
const isDts = options.baseOutputDir.endsWith('.d.ts');

// Get the correct filename with extension (.d.ts or .ts)
const {typesFile} = getOutputFiles(apiType, isDts);

return hydrogenPreset.buildGeneratesSection({
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Preset', () => {

// Imports Admin API
expect(generatedCode).toMatch(
`import type * as AdminTypes from './admin.types';`,
`import type * as AdminTypes from './admin.types.d.ts';`,
);

// Uses Pick<...>
Expand All @@ -59,7 +59,7 @@ describe('Preset', () => {
.toBe(`/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable eslint-comments/no-unlimited-disable */
/* eslint-disable */
import type * as AdminTypes from './admin.types';
import type * as AdminTypes from './admin.types.d.ts';

export type TestQueryQueryVariables = AdminTypes.Exact<{ [key: string]: never; }>;

Expand Down Expand Up @@ -100,7 +100,7 @@ declare module '@shopify/admin-api-client' {
)!.content;

expect(generatedCode).toMatch(
"import type * as AdminTypes from './admin.types';",
"import type * as AdminTypes from './admin.types.d.ts';",
);
});

Expand All @@ -116,7 +116,7 @@ declare module '@shopify/admin-api-client' {
)!.content;

expect(generatedCode).toMatch(
"import * as AdminTypes from './admin.types';",
"import * as AdminTypes from './admin.types.ts';",
);
});
});