Skip to content

Commit d84afec

Browse files
authored
feat: generate TypeScript modules compatible exports map and dist structure (#7978)
* feat: generate TypeScript modules compatible exports map * chore: upgrade to latest bob * fix: bob check errors * chore: prettier * fix: bin path for dev-tests * revert dev-test code changes * remove .js for website * ok no .js here * revert accidential test string changes * feat: esm lfg * chore: add changeset * chore: run dev tests on both cjs and esm * chore: upgrade bob to version 3 * chore: test whether the cache is fucked up * why why oh why * fix: urql graphcache code * chore: add changeset * fix: resolve ESM modules when running graphql-codegen via the esm binary * chore: remove testing package from the changeset * fix: also support the esm error code when trying to load a plugin * chore: patch @urql/introspection so the graphql logic is loaded from the top level export (cjs module) * chore: remove obsolete prepack command
1 parent f5491b3 commit d84afec

File tree

295 files changed

+3964
-3604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+3964
-3604
lines changed

.changeset/lovely-lies-talk.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-codegen/cli': minor
3+
---
4+
5+
Add bin CLI command for running `graphql-code-generator` in ESM mode. You can now use `graphql-codegen-esm` instead of `graphql-codegen`.
6+
7+
GraphQL Code Generator will continue supporting both ESM and CommonJS in parallel.

.changeset/orange-pants-type.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
'@graphql-cli/codegen': minor
3+
'@graphql-codegen/cli': minor
4+
'@graphql-codegen/core': minor
5+
'@graphql-codegen/c-sharp': minor
6+
'@graphql-codegen/c-sharp-common': minor
7+
'@graphql-codegen/c-sharp-operations': minor
8+
'@graphql-codegen/flow': minor
9+
'@graphql-codegen/flow-operations': minor
10+
'@graphql-codegen/flow-resolvers': minor
11+
'@graphql-codegen/java-apollo-android': minor
12+
'@graphql-codegen/java-common': minor
13+
'@graphql-codegen/java': minor
14+
'@graphql-codegen/kotlin': minor
15+
'@graphql-codegen/java-resolvers': minor
16+
'@graphql-codegen/add': minor
17+
'@graphql-codegen/fragment-matcher': minor
18+
'@graphql-codegen/hasura-allow-list': minor
19+
'@graphql-codegen/introspection': minor
20+
'@graphql-codegen/jsdoc': minor
21+
'@graphql-codegen/schema-ast': minor
22+
'@graphql-codegen/time': minor
23+
'@graphql-codegen/urql-introspection': minor
24+
'@graphql-codegen/visitor-plugin-common': minor
25+
'@graphql-codegen/typescript-apollo-angular': minor
26+
'@graphql-codegen/typescript-apollo-client-helpers': minor
27+
'@graphql-codegen/typescript-document-nodes': minor
28+
'@graphql-codegen/typescript-enum-array': minor
29+
'@graphql-codegen/typescript-generic-sdk': minor
30+
'@graphql-codegen/gql-tag-operations': minor
31+
'@graphql-codegen/typescript-graphql-apollo': minor
32+
'@graphql-codegen/typescript-graphql-files-modules': minor
33+
'@graphql-codegen/typescript-graphql-request': minor
34+
'@graphql-codegen/typescript-jit-sdk': minor
35+
'@graphql-codegen/typescript-mongodb': minor
36+
'@graphql-codegen/typescript-msw': minor
37+
'@graphql-codegen/named-operations-object': minor
38+
'@graphql-codegen/typescript-oclif': minor
39+
'@graphql-codegen/typescript-operations': minor
40+
'@graphql-codegen/typescript-react-apollo': minor
41+
'@graphql-codegen/typescript-react-offix': minor
42+
'@graphql-codegen/typescript-react-query': minor
43+
'@graphql-codegen/typescript-resolvers': minor
44+
'@graphql-codegen/typescript-rtk-query': minor
45+
'@graphql-codegen/typescript-stencil-apollo': minor
46+
'@graphql-codegen/typescript-type-graphql': minor
47+
'@graphql-codegen/typed-document-node': minor
48+
'@graphql-codegen/typescript': minor
49+
'@graphql-codegen/typescript-urql': minor
50+
'@graphql-codegen/typescript-urql-graphcache': minor
51+
'@graphql-codegen/urql-svelte-operations-store': minor
52+
'@graphql-codegen/typescript-vue-apollo': minor
53+
'@graphql-codegen/typescript-vue-apollo-smart-ops': minor
54+
'@graphql-codegen/typescript-vue-urql': minor
55+
'@graphql-codegen/gql-tag-operations-preset': minor
56+
'@graphql-codegen/graphql-modules-preset': minor
57+
'@graphql-codegen/import-types-preset': minor
58+
'@graphql-codegen/near-operation-file-preset': minor
59+
'@graphql-codegen/plugin-helpers': minor
60+
---
61+
62+
Support TypeScript ESM modules (`"module": "node16"` and `"moduleResolution": "node16"`).
63+
64+
[More information on the TypeScript Release Notes.](https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js)

.changeset/warm-humans-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/typescript-urql-graphcache': patch
3+
---
4+
5+
Don't depend on schema AST for cache update generation.

.github/workflows/main.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ jobs:
5959
dev-tests:
6060
name: Validating dev-tests
6161
runs-on: ubuntu-latest
62+
strategy:
63+
matrix:
64+
method:
65+
- 'cjs'
66+
- 'esm'
6267
steps:
6368
- name: Checkout
6469
uses: actions/checkout@v3
@@ -79,12 +84,12 @@ jobs:
7984
run: yarn build
8085
env:
8186
CI: true
82-
- name: Test dev-tests
87+
- name: Test dev-tests ${{matrix.method}}
8388
run: |
84-
yarn run generate:examples
89+
yarn run generate:examples:${{matrix.method}}
8590
git diff --exit-code -- dev-test/
8691
esm:
87-
name: Testing ESM
92+
name: Testing exports integrity
8893
runs-on: ubuntu-latest
8994
steps:
9095
- name: Checkout
@@ -106,8 +111,8 @@ jobs:
106111
run: yarn build
107112
env:
108113
CI: true
109-
- name: Test ESM
110-
run: node scripts/test-esm.mjs
114+
- name: Test ESM & CJS integrity
115+
run: yarn bob check
111116
test:
112117
name: Unit Test on Node ${{matrix.node_version}} (${{matrix.os}}) and GraphQL v${{matrix.graphql_version}}
113118
runs-on: ubuntu-latest

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ packages/plugins/flow/flow/tests/flow.js
44
packages/presets/gql-tag-operations/tests/fixtures/crlf-operation.ts
55
dist/
66
.next/
7+
.bob
78
CHANGELOG.md
89
.husky/_/
910
.changeset/*.md

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
"coverage": true,
2121
"npm": true
2222
},
23-
"typescript.tsdk": "node_modules/typescript/lib"
23+
"typescript.tsdk": "node_modules/typescript/lib",
24+
"editor.formatOnSave": true,
25+
"editor.defaultFormatter": "esbenp.prettier-vscode"
2426
}

bob.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dev-test/githunt/types.urql.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,64 +1059,64 @@ export type GraphCacheKeysConfig = {
10591059

10601060
export type GraphCacheResolvers = {
10611061
Query?: {
1062-
feed?: GraphCacheResolver<WithTypename<Query>, QueryFeedArgs, Array<WithTypename<Entry> | string>>;
1063-
entry?: GraphCacheResolver<WithTypename<Query>, QueryEntryArgs, WithTypename<Entry> | string>;
10641062
currentUser?: GraphCacheResolver<WithTypename<Query>, Record<string, never>, WithTypename<User> | string>;
1063+
entry?: GraphCacheResolver<WithTypename<Query>, QueryEntryArgs, WithTypename<Entry> | string>;
1064+
feed?: GraphCacheResolver<WithTypename<Query>, QueryFeedArgs, Array<WithTypename<Entry> | string>>;
10651065
};
10661066
Comment?: {
1067+
content?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, Scalars['String'] | string>;
1068+
createdAt?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, Scalars['Float'] | string>;
10671069
id?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, Scalars['Int'] | string>;
10681070
postedBy?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, WithTypename<User> | string>;
1069-
createdAt?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, Scalars['Float'] | string>;
1070-
content?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, Scalars['String'] | string>;
10711071
repoName?: GraphCacheResolver<WithTypename<Comment>, Record<string, never>, Scalars['String'] | string>;
10721072
};
10731073
Entry?: {
1074-
repository?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, WithTypename<Repository> | string>;
1075-
postedBy?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, WithTypename<User> | string>;
1074+
commentCount?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Int'] | string>;
1075+
comments?: GraphCacheResolver<WithTypename<Entry>, EntryCommentsArgs, Array<WithTypename<Comment> | string>>;
10761076
createdAt?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Float'] | string>;
1077-
score?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Int'] | string>;
10781077
hotScore?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Float'] | string>;
1079-
comments?: GraphCacheResolver<WithTypename<Entry>, EntryCommentsArgs, Array<WithTypename<Comment> | string>>;
1080-
commentCount?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Int'] | string>;
10811078
id?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Int'] | string>;
1079+
postedBy?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, WithTypename<User> | string>;
1080+
repository?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, WithTypename<Repository> | string>;
1081+
score?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, Scalars['Int'] | string>;
10821082
vote?: GraphCacheResolver<WithTypename<Entry>, Record<string, never>, WithTypename<Vote> | string>;
10831083
};
10841084
Repository?: {
1085-
name?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['String'] | string>;
1086-
full_name?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['String'] | string>;
10871085
description?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['String'] | string>;
1086+
full_name?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['String'] | string>;
10881087
html_url?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['String'] | string>;
1089-
stargazers_count?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['Int'] | string>;
1088+
name?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['String'] | string>;
10901089
open_issues_count?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['Int'] | string>;
10911090
owner?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, WithTypename<User> | string>;
1091+
stargazers_count?: GraphCacheResolver<WithTypename<Repository>, Record<string, never>, Scalars['Int'] | string>;
10921092
};
10931093
User?: {
1094-
login?: GraphCacheResolver<WithTypename<User>, Record<string, never>, Scalars['String'] | string>;
10951094
avatar_url?: GraphCacheResolver<WithTypename<User>, Record<string, never>, Scalars['String'] | string>;
10961095
html_url?: GraphCacheResolver<WithTypename<User>, Record<string, never>, Scalars['String'] | string>;
1096+
login?: GraphCacheResolver<WithTypename<User>, Record<string, never>, Scalars['String'] | string>;
10971097
};
10981098
Vote?: {
10991099
vote_value?: GraphCacheResolver<WithTypename<Vote>, Record<string, never>, Scalars['Int'] | string>;
11001100
};
11011101
};
11021102

11031103
export type GraphCacheOptimisticUpdaters = {
1104+
submitComment?: GraphCacheOptimisticMutationResolver<MutationSubmitCommentArgs, Maybe<WithTypename<Comment>>>;
11041105
submitRepository?: GraphCacheOptimisticMutationResolver<MutationSubmitRepositoryArgs, Maybe<WithTypename<Entry>>>;
11051106
vote?: GraphCacheOptimisticMutationResolver<MutationVoteArgs, Maybe<WithTypename<Entry>>>;
1106-
submitComment?: GraphCacheOptimisticMutationResolver<MutationSubmitCommentArgs, Maybe<WithTypename<Comment>>>;
11071107
};
11081108

11091109
export type GraphCacheUpdaters = {
11101110
Mutation?: {
1111+
submitComment?: GraphCacheUpdateResolver<
1112+
{ submitComment: Maybe<WithTypename<Comment>> },
1113+
MutationSubmitCommentArgs
1114+
>;
11111115
submitRepository?: GraphCacheUpdateResolver<
11121116
{ submitRepository: Maybe<WithTypename<Entry>> },
11131117
MutationSubmitRepositoryArgs
11141118
>;
11151119
vote?: GraphCacheUpdateResolver<{ vote: Maybe<WithTypename<Entry>> }, MutationVoteArgs>;
1116-
submitComment?: GraphCacheUpdateResolver<
1117-
{ submitComment: Maybe<WithTypename<Comment>> },
1118-
MutationSubmitCommentArgs
1119-
>;
11201120
};
11211121
Subscription?: {
11221122
commentAdded?: GraphCacheUpdateResolver<

dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import * as graphql from './graphql';
2+
import * as graphql from './graphql.js';
33
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
44

55
const documents = {

dev-test/gql-tag-operations-masking/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import * as graphql from './graphql';
2+
import * as graphql from './graphql.js';
33
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
44

55
const documents = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import * as graphql from './graphql';
2+
import * as graphql from './graphql.js';
33
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
44

55
const documents = {

dev-test/gql-tag-operations/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22

3-
import { gql, DocumentType } from '../gql';
3+
import { gql, DocumentType } from '../gql.js';
44

55
const FooQuery = gql(/* GraphQL */ `
66
query Foo {

examples/programmatic-typescript/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"@graphql-codegen/typescript": "*",
1414
"@graphql-codegen/typescript-operations": "*",
1515
"@graphql-codegen/typescript-resolvers": "*",
16-
"@graphql-tools/graphql-file-loader": "^7.0.1",
17-
"@graphql-tools/load": "^7.3.0",
18-
"@graphql-tools/schema": "^8.3.1",
16+
"@graphql-tools/graphql-file-loader": "^7.4.0",
17+
"@graphql-tools/load": "^7.7.0",
18+
"@graphql-tools/schema": "^8.5.0",
1919
"graphql": "^15.5.1",
2020
"graphql-tag": "^2.12.5",
2121
"prettier": "^2.3.2"

examples/programmatic-typescript/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
1414
import { loadDocuments } from '@graphql-tools/load';
1515
import { makeExecutableSchema } from '@graphql-tools/schema';
1616

17-
import type { Resolvers } from './gql.generated';
17+
import type { Resolvers } from './gql.generated.js';
1818

1919
const schema = makeExecutableSchema({
2020
typeDefs: gql`

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports =
77
: {
88
rootDir: __dirname,
99
projects: ['<rootDir>/packages/**/*/jest.config.js'],
10+
resolver: 'bob-the-bundler/jest-resolver.js',
1011
};

jest.project.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ module.exports = ({ dirname, projectMode = true }) => {
1616
rootDir: dirname,
1717
restoreMocks: true,
1818
reporters: ['default'],
19-
modulePathIgnorePatterns: ['dist'],
19+
modulePathIgnorePatterns: ['dist', '.bob'],
2020
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: `${ROOT_DIR}/` }),
2121
cacheDirectory: resolve(ROOT_DIR, `${CI ? '' : 'node_modules/'}.cache/jest`),
2222
setupFiles: [`${ROOT_DIR}/dev-test/setup.js`],
2323
collectCoverage: false,
2424
testTimeout: 20000,
25+
resolver: 'bob-the-bundler/jest-resolver.js',
2526
};
2627
};

package.json

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"postinstall": "patch-package && husky install",
66
"clean": "rimraf \"{,!(node_modules)/**/}node_modules/\"",
77
"prebuild": "rimraf \"{,!(node_modules)/**/}dist/\" .bob/ tsconfig.tsbuildinfo",
8-
"build": "tsc --project tsconfig.json && bob build",
8+
"build": "bob build",
99
"watch-build": "npx tsc-watch --project tsconfig.json --onSuccess \"bob build\"",
1010
"test": "jest --forceExit --no-watchman",
1111
"lint": "eslint --ext .ts .",
@@ -16,26 +16,22 @@
1616
"prerelease": "yarn build",
1717
"release": "changeset publish",
1818
"release:canary": "node scripts/canary-release.js && yarn build && yarn changeset publish --tag alpha",
19-
"generate:examples": "node packages/graphql-codegen-cli/dist/bin.js --require dotenv/config --config ./dev-test/codegen.yml dotenv_config_path=dev-test/.env"
20-
},
21-
"workspaces": {
22-
"packages": [
23-
"packages/*",
24-
"packages/utils/*",
25-
"packages/plugins/flow/*",
26-
"packages/plugins/java/*",
27-
"packages/plugins/c-sharp/*",
28-
"packages/plugins/typescript/*",
29-
"packages/plugins/other/*",
30-
"packages/presets/*",
31-
"website",
32-
"examples/*"
33-
],
34-
"nohoist": [
35-
"**/@babel-*",
36-
"**/@babel-*/**"
37-
]
19+
"generate:examples:esm": "node packages/graphql-codegen-cli/dist/esm/bin.js --require dotenv/config --config ./dev-test/codegen.yml dotenv_config_path=dev-test/.env",
20+
"generate:examples:cjs": "node packages/graphql-codegen-cli/dist/cjs/bin.js --require dotenv/config --config ./dev-test/codegen.yml dotenv_config_path=dev-test/.env",
21+
"generate:examples": "yarn generate:examples:cjs"
3822
},
23+
"workspaces": [
24+
"packages/*",
25+
"packages/utils/*",
26+
"packages/plugins/flow/*",
27+
"packages/plugins/java/*",
28+
"packages/plugins/c-sharp/*",
29+
"packages/plugins/typescript/*",
30+
"packages/plugins/other/*",
31+
"packages/presets/*",
32+
"website",
33+
"examples/*"
34+
],
3935
"devDependencies": {
4036
"@apollo/client": "3.6.9",
4137
"@babel/core": "7.18.6",
@@ -60,7 +56,7 @@
6056
"apollo-server": "3.9.0",
6157
"auto-bind": "4.0.0",
6258
"babel-jest": "27.5.1",
63-
"bob-the-bundler": "1.7.3",
59+
"bob-the-bundler": "3.0.0",
6460
"chalk": "4.1.2",
6561
"dotenv": "16.0.1",
6662
"eslint": "8.19.0",

0 commit comments

Comments
 (0)