Skip to content

Commit 2cbcbb3

Browse files
saihajcharlypoly
andauthored
feat: add emitLegacyCommonJSImports flag (dotansimha#8077)
* feat: add `emitLegacyCommonJSImports` flag * add changeset * update docs * fix * fix(emitLegacyCommonJSImports): normalize value across plugins and presets + fix specs Introduced a `shouldEmitLegacyCommonJSImports()` helper to get proper value Co-authored-by: Charly POLY <[email protected]>
1 parent 9e5773c commit 2cbcbb3

31 files changed

+173
-67
lines changed

.changeset/kind-taxis-refuse.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@graphql-codegen/cli': minor
3+
'@graphql-codegen/visitor-plugin-common': minor
4+
'@graphql-codegen/gql-tag-operations': minor
5+
'@graphql-codegen/near-operation-file-preset': minor
6+
'@graphql-codegen/plugin-helpers': minor
7+
---
8+
9+
Add new flag to emit legacy common js imports. Default it will be `true` this way it ensure that generated code works with [non-compliant bundlers](https://github.com/dotansimha/graphql-code-generator/issues/8065).
10+
11+
You can use the option in your config:
12+
```yaml
13+
schema: 'schema.graphql'
14+
documents:
15+
- 'src/**/*.graphql'
16+
emitLegacyCommonJSImports: true
17+
```
18+
19+
Alternative you can use the CLI to set this option:
20+
```bash
21+
$ codegen --config-file=config.yml --emit-legacy-common-js-imports
22+
```

dev-test/codegen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
hooks:
22
afterAllFileWrite:
33
- prettier --write
4+
emitLegacyCommonJSImports: false
45
generates:
56
./dev-test/test-schema/resolvers-types.ts:
67
schema: ./dev-test/test-schema/schema-text.js

dev-test/githunt/__generated__/comment.query.stencil-component.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-test/githunt/__generated__/feed-entry.fragment.stencil-component.tsx

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-test/githunt/__generated__/feed.query.stencil-component.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-test/githunt/__generated__/submit-comment.mutation.stencil-component.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-test/gql-tag-operations-urql/gql/gql.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
44
declare module '@urql/core' {
55
export function gql(
66
source: '\n query Foo {\n Tweets {\n id\n }\n }\n'
7-
): typeof import('./graphql').FooDocument;
7+
): typeof import('./graphql.js').FooDocument;
88
export function gql(
99
source: '\n fragment Lel on Tweet {\n id\n body\n }\n'
10-
): typeof import('./graphql').LelFragmentDoc;
10+
): typeof import('./graphql.js').LelFragmentDoc;
1111
export function gql(
1212
source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n'
13-
): typeof import('./graphql').BarDocument;
13+
): typeof import('./graphql.js').BarDocument;
1414
export function gql(source: string): unknown;
1515

1616
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<

dev-test/star-wars/__generated__/CreateReviewForEpisode.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-test/star-wars/__generated__/HeroAndFriendsNames.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-test/star-wars/__generated__/HeroAppearsIn.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)