Skip to content

Commit a8a4bd5

Browse files
committed
[typescript-operations][client-preset] Integrate new typescript-operations with client preset (#10540)
* Do not use typescript and its config in Client Preset * Fix issue where enumValues are imported even if not used * Split enum tests for client preset * Update unit tests * Update examples * Generate Incremental utilty type * Add changeset * Rebase tests (with errors)
1 parent 9e5ff1b commit a8a4bd5

55 files changed

Lines changed: 435 additions & 20295 deletions

File tree

Some content is hidden

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

.changeset/salty-guests-retire.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-codegen/typescript-operations': major
3+
'@graphql-codegen/client-preset': major
4+
---
5+
6+
Integrate new typescript-operations into client-preset

dev-test/codegen.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const config: CodegenConfig = {
4040
{ add: { content: 'declare namespace GraphQL {' } },
4141
{ add: { placement: 'append', content: '}' } },
4242
'typescript',
43-
'typescript-operations',
4443
],
4544
},
4645
'./dev-test/test-schema/env.types.ts': {
@@ -68,87 +67,87 @@ const config: CodegenConfig = {
6867
'./dev-test/githunt/typed-document-nodes.ts': {
6968
schema: './dev-test/githunt/schema.json',
7069
documents: './dev-test/githunt/**/*.graphql',
71-
plugins: ['typescript', 'typescript-operations', 'typed-document-node'],
70+
plugins: ['typescript-operations', 'typed-document-node'],
7271
},
7372
'./dev-test/githunt/types.ts': {
7473
schema: './dev-test/githunt/schema.json',
7574
documents: './dev-test/githunt/**/*.graphql',
76-
plugins: ['typescript', 'typescript-operations'],
75+
plugins: ['typescript-operations'],
7776
},
7877
'./dev-test/githunt/types.preResolveTypes.ts': {
7978
schema: './dev-test/githunt/schema.json',
8079
documents: './dev-test/githunt/**/*.graphql',
8180
config: { preResolveTypes: true },
82-
plugins: ['typescript', 'typescript-operations'],
81+
plugins: ['typescript-operations'],
8382
},
8483
'./dev-test/githunt/types.onlyEnums.ts': {
8584
schema: './dev-test/githunt/schema.json',
8685
documents: './dev-test/githunt/**/*.graphql',
87-
config: { onlyEnums: true },
88-
plugins: ['typescript'],
86+
config: { generatesOperationTypes: false },
87+
plugins: ['typescript-operations'],
8988
},
9089
'./dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts': {
9190
schema: './dev-test/githunt/schema.json',
9291
documents: './dev-test/githunt/**/*.graphql',
93-
config: { preResolveTypes: true, onlyOperationTypes: true },
94-
plugins: ['typescript', 'typescript-operations'],
92+
config: { preResolveTypes: true },
93+
plugins: ['typescript-operations'],
9594
},
9695
'./dev-test/githunt/types.flatten.preResolveTypes.ts': {
9796
schema: './dev-test/githunt/schema.json',
9897
documents: './dev-test/githunt/**/*.graphql',
9998
config: { preResolveTypes: true, flattenGeneratedTypes: true },
100-
plugins: ['typescript', 'typescript-operations'],
99+
plugins: ['typescript-operations'],
101100
},
102101
'./dev-test/githunt/types.enumsAsTypes.ts': {
103102
schema: './dev-test/githunt/schema.json',
104103
documents: './dev-test/githunt/**/*.graphql',
105-
config: { enumsAsTypes: true },
106-
plugins: ['typescript', 'typescript-operations'],
104+
config: { enumType: 'string-literal' },
105+
plugins: ['typescript-operations'],
107106
},
108107
'./dev-test/githunt/types.d.ts': {
109108
schema: './dev-test/githunt/schema.json',
110109
documents: './dev-test/githunt/**/*.graphql',
111-
config: { enumsAsTypes: true },
112-
plugins: ['typescript', 'typescript-operations'],
110+
config: {},
111+
plugins: ['typescript-operations'],
113112
},
114113
'./dev-test/githunt/types.avoidOptionals.ts': {
115114
schema: './dev-test/githunt/schema.json',
116115
documents: './dev-test/githunt/**/*.graphql',
117116
config: { avoidOptionals: true },
118-
plugins: ['typescript', 'typescript-operations'],
117+
plugins: ['typescript-operations'],
119118
},
120119
'./dev-test/githunt/types.immutableTypes.ts': {
121120
schema: './dev-test/githunt/schema.json',
122121
documents: './dev-test/githunt/**/*.graphql',
123122
config: { immutableTypes: true },
124-
plugins: ['typescript', 'typescript-operations'],
123+
plugins: ['typescript-operations'],
125124
},
126125
'./dev-test/star-wars/types.ts': {
127126
schema: './dev-test/star-wars/schema.json',
128127
documents: './dev-test/star-wars/**/*.graphql',
129-
plugins: ['typescript', 'typescript-operations'],
128+
plugins: ['typescript-operations'],
130129
},
131130
'./dev-test/star-wars/types.excludeQueryAlpha.ts': {
132131
schema: './dev-test/star-wars/schema.json',
133132
documents: [
134133
'./dev-test/star-wars/**/*.graphql',
135134
'!./dev-test/star-wars/**/ExcludeQueryAlpha.graphql',
136135
],
137-
plugins: ['typescript', 'typescript-operations'],
136+
plugins: ['typescript-operations'],
138137
},
139138
'./dev-test/star-wars/types.excludeQueryBeta.ts': {
140139
schema: './dev-test/star-wars/schema.json',
141140
documents: [
142141
'./dev-test/star-wars/**/*.graphql',
143142
'!./dev-test/star-wars/**/ExcludeQueryBeta.graphql',
144143
],
145-
plugins: ['typescript', 'typescript-operations'],
144+
plugins: ['typescript-operations'],
146145
},
147146
'./dev-test/star-wars/types.preResolveTypes.ts': {
148147
schema: './dev-test/star-wars/schema.json',
149148
documents: './dev-test/star-wars/**/*.graphql',
150149
config: { preResolveTypes: true },
151-
plugins: ['typescript', 'typescript-operations'],
150+
plugins: ['typescript-operations'],
152151
},
153152
'./dev-test/star-wars/types.OnlyEnums.ts': {
154153
schema: './dev-test/star-wars/schema.json',
@@ -159,25 +158,25 @@ const config: CodegenConfig = {
159158
'./dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts': {
160159
schema: './dev-test/star-wars/schema.json',
161160
documents: './dev-test/star-wars/**/*.graphql',
162-
config: { preResolveTypes: true, onlyOperationTypes: true },
163-
plugins: ['typescript', 'typescript-operations'],
161+
config: { preResolveTypes: true },
162+
plugins: ['typescript-operations'],
164163
},
165164
'./dev-test/test-schema/types.preResolveTypes.ts': {
166165
schema: './dev-test/test-schema/schema.graphql',
167166
documents: ['query test { testArr1 testArr2 testArr3 }'],
168167
config: { preResolveTypes: true },
169-
plugins: ['typescript', 'typescript-operations'],
168+
plugins: ['typescript-operations'],
170169
},
171170
'./dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts': {
172171
schema: './dev-test/test-schema/schema.graphql',
173172
documents: ['query test { testArr1 testArr2 testArr3 }'],
174-
config: { preResolveTypes: true, onlyOperationTypes: true },
175-
plugins: ['typescript', 'typescript-operations'],
173+
config: { preResolveTypes: true },
174+
plugins: ['typescript-operations'],
176175
},
177176
'./dev-test/star-wars/types.d.ts': {
178177
schema: './dev-test/star-wars/schema.json',
179-
config: { enumsAsTypes: true },
180-
plugins: ['typescript', 'typescript-operations'],
178+
config: { enumType: 'string-literal' },
179+
plugins: ['typescript-operations'],
181180
},
182181
'./dev-test/modules/': {
183182
schema: './dev-test/modules/*/types/*.graphql',
@@ -188,25 +187,25 @@ const config: CodegenConfig = {
188187
'./dev-test/star-wars/types.globallyAvailable.d.ts': {
189188
schema: './dev-test/star-wars/schema.json',
190189
documents: './dev-test/star-wars/**/*.graphql',
191-
config: { enumsAsTypes: true, noExport: true },
192-
plugins: ['typescript', 'typescript-operations'],
190+
config: { noExport: true },
191+
plugins: ['typescript-operations'],
193192
},
194193
'./dev-test/star-wars/types.avoidOptionals.ts': {
195194
schema: './dev-test/star-wars/schema.json',
196195
documents: './dev-test/star-wars/**/*.graphql',
197196
config: { avoidOptionals: true },
198-
plugins: ['typescript', 'typescript-operations'],
197+
plugins: ['typescript-operations'],
199198
},
200199
'./dev-test/star-wars/types.immutableTypes.ts': {
201200
schema: './dev-test/star-wars/schema.json',
202201
documents: './dev-test/star-wars/**/*.graphql',
203202
config: { immutableTypes: true },
204-
plugins: ['typescript', 'typescript-operations'],
203+
plugins: ['typescript-operations'],
205204
},
206205
'./dev-test/star-wars/types.skipSchema.ts': {
207206
schema: './dev-test/star-wars/schema.json',
208207
documents: './dev-test/star-wars/**/*.graphql',
209-
plugins: ['typescript', 'typescript-operations'],
208+
plugins: ['typescript-operations'],
210209
},
211210
'./dev-test/gql-tag-operations/gql/': {
212211
schema: './dev-test/gql-tag-operations/schema.graphql',
@@ -233,7 +232,7 @@ const config: CodegenConfig = {
233232
'./dev-test/test-null-value/result.d.ts': {
234233
schema: './dev-test/test-null-value/schema.graphql',
235234
documents: ['./dev-test/test-null-value/query.ts'],
236-
plugins: ['typescript', 'typescript-operations'],
235+
plugins: ['typescript-operations'],
237236
config: {
238237
// The combination of these two flags caused the following issue:
239238
// https://github.com/dotansimha/graphql-code-generator/pull/9709

dev-test/external-documents/app/types.generated.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
2+
export type Incremental<T> =
3+
| T
4+
| { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
25
export type UserQueryVariables = Exact<{
3-
id: Scalars['ID']['input'];
6+
id: string;
47
}>;
58

69
export type UserQuery = {

dev-test/githunt/typed-document-nodes.ts

Lines changed: 1 addition & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,9 @@
11
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
22

3-
export type Maybe<T> = T | null;
4-
export type InputMaybe<T> = Maybe<T>;
5-
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
6-
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
7-
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = {
8-
[_ in K]?: never;
9-
};
3+
type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
104
export type Incremental<T> =
115
| T
126
| { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
13-
type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
14-
/** All built-in and custom scalars, mapped to their actual values */
15-
export type Scalars = {
16-
ID: { input: string; output: string };
17-
String: { input: string; output: string };
18-
Boolean: { input: boolean; output: boolean };
19-
Int: { input: number; output: number };
20-
Float: { input: number; output: number };
21-
};
22-
23-
/** A comment about an entry, submitted by a user */
24-
export type Comment = {
25-
__typename?: 'Comment';
26-
/** The text of the comment */
27-
content: Scalars['String']['output'];
28-
/** A timestamp of when the comment was posted */
29-
createdAt: Scalars['Float']['output'];
30-
/** The SQL ID of this entry */
31-
id: Scalars['Int']['output'];
32-
/** The GitHub user who posted the comment */
33-
postedBy: User;
34-
/** The repository which this comment is about */
35-
repoName: Scalars['String']['output'];
36-
};
37-
38-
/** Information about a GitHub repository submitted to GitHunt */
39-
export type Entry = {
40-
__typename?: 'Entry';
41-
/** The number of comments posted about this repository */
42-
commentCount: Scalars['Int']['output'];
43-
/** Comments posted about this repository */
44-
comments: Array<Maybe<Comment>>;
45-
/** A timestamp of when the entry was submitted */
46-
createdAt: Scalars['Float']['output'];
47-
/** The hot score of this repository */
48-
hotScore: Scalars['Float']['output'];
49-
/** The SQL ID of this entry */
50-
id: Scalars['Int']['output'];
51-
/** The GitHub user who submitted this entry */
52-
postedBy: User;
53-
/** Information about the repository from GitHub */
54-
repository: Repository;
55-
/** The score of this repository, upvotes - downvotes */
56-
score: Scalars['Int']['output'];
57-
/** XXX to be changed */
58-
vote: Vote;
59-
};
60-
61-
/** Information about a GitHub repository submitted to GitHunt */
62-
export type EntryCommentsArgs = {
63-
limit?: InputMaybe<Scalars['Int']['input']>;
64-
offset?: InputMaybe<Scalars['Int']['input']>;
65-
};
66-
67-
/** A list of options for the sort order of the feed */
68-
export enum FeedType {
69-
/** Sort by a combination of freshness and score, using Reddit's algorithm */
70-
Hot = 'HOT',
71-
/** Newest entries first */
72-
New = 'NEW',
73-
/** Highest score entries first */
74-
Top = 'TOP',
75-
}
76-
77-
export type Mutation = {
78-
__typename?: 'Mutation';
79-
/** Comment on a repository, returns the new comment */
80-
submitComment?: Maybe<Comment>;
81-
/** Submit a new repository, returns the new submission */
82-
submitRepository?: Maybe<Entry>;
83-
/** Vote on a repository submission, returns the submission that was voted on */
84-
vote?: Maybe<Entry>;
85-
};
86-
87-
export type MutationSubmitCommentArgs = {
88-
commentContent: Scalars['String']['input'];
89-
repoFullName: Scalars['String']['input'];
90-
};
91-
92-
export type MutationSubmitRepositoryArgs = {
93-
repoFullName: Scalars['String']['input'];
94-
};
95-
96-
export type MutationVoteArgs = {
97-
repoFullName: Scalars['String']['input'];
98-
type: VoteType;
99-
};
100-
101-
export type Query = {
102-
__typename?: 'Query';
103-
/** Return the currently logged in user, or null if nobody is logged in */
104-
currentUser?: Maybe<User>;
105-
/** A single entry */
106-
entry?: Maybe<Entry>;
107-
/** A feed of repository submissions */
108-
feed?: Maybe<Array<Maybe<Entry>>>;
109-
};
110-
111-
export type QueryEntryArgs = {
112-
repoFullName: Scalars['String']['input'];
113-
};
114-
115-
export type QueryFeedArgs = {
116-
limit?: InputMaybe<Scalars['Int']['input']>;
117-
offset?: InputMaybe<Scalars['Int']['input']>;
118-
type: FeedType;
119-
};
120-
121-
/**
122-
* A repository object from the GitHub API. This uses the exact field names returned by the
123-
* GitHub API for simplicity, even though the convention for GraphQL is usually to camel case.
124-
*/
125-
export type Repository = {
126-
__typename?: 'Repository';
127-
/** The description of the repository */
128-
description?: Maybe<Scalars['String']['output']>;
129-
/** The full name of the repository with the username, e.g. apollostack/GitHunt-API */
130-
full_name: Scalars['String']['output'];
131-
/** The link to the repository on GitHub */
132-
html_url: Scalars['String']['output'];
133-
/** Just the name of the repository, e.g. GitHunt-API */
134-
name: Scalars['String']['output'];
135-
/** The number of open issues on this repository on GitHub */
136-
open_issues_count?: Maybe<Scalars['Int']['output']>;
137-
/** The owner of this repository on GitHub, e.g. apollostack */
138-
owner?: Maybe<User>;
139-
/** The number of people who have starred this repository on GitHub */
140-
stargazers_count: Scalars['Int']['output'];
141-
};
142-
143-
export type Subscription = {
144-
__typename?: 'Subscription';
145-
/** Subscription fires on every comment added */
146-
commentAdded?: Maybe<Comment>;
147-
};
148-
149-
export type SubscriptionCommentAddedArgs = {
150-
repoFullName: Scalars['String']['input'];
151-
};
152-
153-
/** A user object from the GitHub API. This uses the exact field names returned from the GitHub API. */
154-
export type User = {
155-
__typename?: 'User';
156-
/** The URL to a directly embeddable image for this user's avatar */
157-
avatar_url: Scalars['String']['output'];
158-
/** The URL of this user's GitHub page */
159-
html_url: Scalars['String']['output'];
160-
/** The name of the user, e.g. apollostack */
161-
login: Scalars['String']['output'];
162-
};
163-
164-
/** XXX to be removed */
165-
export type Vote = {
166-
__typename?: 'Vote';
167-
vote_value: Scalars['Int']['output'];
168-
};
169-
170-
/** The type of vote to record, when submitting a vote */
171-
export enum VoteType {
172-
Cancel = 'CANCEL',
173-
Down = 'DOWN',
174-
Up = 'UP',
175-
}
176-
1777
export type OnCommentAddedSubscriptionVariables = Exact<{
1788
repoFullName: string;
1799
}>;

0 commit comments

Comments
 (0)