Skip to content

Commit a80323d

Browse files
authored
Use import type in generated d.ts (#7)
* Use type imports * Changesets
1 parent 0b7c193 commit a80323d

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

.changeset/nine-seals-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/graphql-codegen': patch
3+
---
4+
5+
Use type imports in the generated d.ts file

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default {
8282
schema: './path/to/my-api-schema.json',
8383
documents: ['./src/graphql/my-api/*.{ts,tsx,js,jsx}'],
8484
presetConfig: {
85-
// Generate the line `import * as MyAPI from 'path/to/my-api-types';`.
85+
// Generate the line `import type * as MyAPI from 'path/to/my-api-types';`.
8686
// If you don't have generated types for your API beforehand,
8787
// omit this parameter to generate the types inline.
8888
importTypes: {
@@ -111,7 +111,7 @@ Then, include queries in your app that match the given schema and documents path
111111

112112
```ts
113113
// my-api.generated.d.ts
114-
import * as MyAPI from 'path/to/my-api-types';
114+
import type * as MyAPI from 'path/to/my-api-types';
115115

116116
export type LayoutQueryVariables = MyAPI.Exact<{[key: string]: never}>;
117117

examples/app/storefrontapi.generated.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable eslint-comments/disable-enable-pair */
22
/* eslint-disable eslint-comments/no-unlimited-disable */
33
/* eslint-disable */
4-
import * as StorefrontAPI from '../../tests/fixtures/storefront-api-types.d.ts';
4+
import type * as StorefrontAPI from '../../tests/fixtures/storefront-api-types.d.ts';
55

66
export type LayoutQueryVariables = StorefrontAPI.Exact<{[key: string]: never}>;
77

src/preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const preset: Types.OutputPreset<PresetConfig> = {
9090
importTypes
9191
? {
9292
[`add`]: {
93-
content: `import * as ${namespacedImportName} from '${importTypesFrom}';\n`,
93+
content: `import type * as ${namespacedImportName} from '${importTypesFrom}';\n`,
9494
},
9595
}
9696
: {

tests/codegen.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Shopify GraphQL Codegen', async () => {
6565

6666
// Imports SFAPI
6767
expect(generatedCode).toMatch(
68-
`import * as StorefrontAPI from './fixtures/storefront-api-types';`,
68+
`import type * as StorefrontAPI from './fixtures/storefront-api-types';`,
6969
);
7070

7171
// Uses Pick<...>
@@ -86,7 +86,7 @@ describe('Shopify GraphQL Codegen', async () => {
8686
"/* eslint-disable eslint-comments/disable-enable-pair */
8787
/* eslint-disable eslint-comments/no-unlimited-disable */
8888
/* eslint-disable */
89-
import * as StorefrontAPI from './fixtures/storefront-api-types';
89+
import type * as StorefrontAPI from './fixtures/storefront-api-types';
9090
9191
export type LayoutQueryVariables = StorefrontAPI.Exact<{ [key: string]: never; }>;
9292
@@ -131,7 +131,7 @@ describe('Shopify GraphQL Codegen', async () => {
131131
"/* eslint-disable eslint-comments/disable-enable-pair */
132132
/* eslint-disable eslint-comments/no-unlimited-disable */
133133
/* eslint-disable */
134-
import * as StorefrontAPI from './fixtures/storefront-api-types';
134+
import type * as StorefrontAPI from './fixtures/storefront-api-types';
135135
136136
type Media_ExternalVideo_Fragment = (
137137
{ __typename: 'ExternalVideo' }

0 commit comments

Comments
 (0)