Skip to content

Commit abdabe2

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 f3315d4 commit abdabe2

54 files changed

Lines changed: 420 additions & 20205 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': { schema: process.env.SCHEMA_PATH, plugins: ['typescript'] },
@@ -65,81 +64,81 @@ const config: CodegenConfig = {
6564
'./dev-test/githunt/typed-document-nodes.ts': {
6665
schema: './dev-test/githunt/schema.json',
6766
documents: './dev-test/githunt/**/*.graphql',
68-
plugins: ['typescript', 'typescript-operations', 'typed-document-node'],
67+
plugins: ['typescript-operations', 'typed-document-node'],
6968
},
7069
'./dev-test/githunt/types.ts': {
7170
schema: './dev-test/githunt/schema.json',
7271
documents: './dev-test/githunt/**/*.graphql',
73-
plugins: ['typescript', 'typescript-operations'],
72+
plugins: ['typescript-operations'],
7473
},
7574
'./dev-test/githunt/types.preResolveTypes.ts': {
7675
schema: './dev-test/githunt/schema.json',
7776
documents: './dev-test/githunt/**/*.graphql',
7877
config: { preResolveTypes: true },
79-
plugins: ['typescript', 'typescript-operations'],
78+
plugins: ['typescript-operations'],
8079
},
8180
'./dev-test/githunt/types.onlyEnums.ts': {
8281
schema: './dev-test/githunt/schema.json',
8382
documents: './dev-test/githunt/**/*.graphql',
84-
config: { onlyEnums: true },
85-
plugins: ['typescript'],
83+
config: { generatesOperationTypes: false },
84+
plugins: ['typescript-operations'],
8685
},
8786
'./dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts': {
8887
schema: './dev-test/githunt/schema.json',
8988
documents: './dev-test/githunt/**/*.graphql',
90-
config: { preResolveTypes: true, onlyOperationTypes: true },
91-
plugins: ['typescript', 'typescript-operations'],
89+
config: { preResolveTypes: true },
90+
plugins: ['typescript-operations'],
9291
},
9392
'./dev-test/githunt/types.flatten.preResolveTypes.ts': {
9493
schema: './dev-test/githunt/schema.json',
9594
documents: './dev-test/githunt/**/*.graphql',
9695
config: { preResolveTypes: true, flattenGeneratedTypes: true },
97-
plugins: ['typescript', 'typescript-operations'],
96+
plugins: ['typescript-operations'],
9897
},
9998
'./dev-test/githunt/types.enumsAsTypes.ts': {
10099
schema: './dev-test/githunt/schema.json',
101100
documents: './dev-test/githunt/**/*.graphql',
102-
config: { enumsAsTypes: true },
103-
plugins: ['typescript', 'typescript-operations'],
101+
config: { enumType: 'string-literal' },
102+
plugins: ['typescript-operations'],
104103
},
105104
'./dev-test/githunt/types.d.ts': {
106105
schema: './dev-test/githunt/schema.json',
107106
documents: './dev-test/githunt/**/*.graphql',
108-
config: { enumsAsTypes: true },
109-
plugins: ['typescript', 'typescript-operations'],
107+
config: {},
108+
plugins: ['typescript-operations'],
110109
},
111110
'./dev-test/githunt/types.avoidOptionals.ts': {
112111
schema: './dev-test/githunt/schema.json',
113112
documents: './dev-test/githunt/**/*.graphql',
114113
config: { avoidOptionals: true },
115-
plugins: ['typescript', 'typescript-operations'],
114+
plugins: ['typescript-operations'],
116115
},
117116
'./dev-test/githunt/types.immutableTypes.ts': {
118117
schema: './dev-test/githunt/schema.json',
119118
documents: './dev-test/githunt/**/*.graphql',
120119
config: { immutableTypes: true },
121-
plugins: ['typescript', 'typescript-operations'],
120+
plugins: ['typescript-operations'],
122121
},
123122
'./dev-test/star-wars/types.ts': {
124123
schema: './dev-test/star-wars/schema.json',
125124
documents: './dev-test/star-wars/**/*.graphql',
126-
plugins: ['typescript', 'typescript-operations'],
125+
plugins: ['typescript-operations'],
127126
},
128127
'./dev-test/star-wars/types.excludeQueryAlpha.ts': {
129128
schema: './dev-test/star-wars/schema.json',
130129
documents: ['./dev-test/star-wars/**/*.graphql', '!./dev-test/star-wars/**/ExcludeQueryAlpha.graphql'],
131-
plugins: ['typescript', 'typescript-operations'],
130+
plugins: ['typescript-operations'],
132131
},
133132
'./dev-test/star-wars/types.excludeQueryBeta.ts': {
134133
schema: './dev-test/star-wars/schema.json',
135134
documents: ['./dev-test/star-wars/**/*.graphql', '!./dev-test/star-wars/**/ExcludeQueryBeta.graphql'],
136-
plugins: ['typescript', 'typescript-operations'],
135+
plugins: ['typescript-operations'],
137136
},
138137
'./dev-test/star-wars/types.preResolveTypes.ts': {
139138
schema: './dev-test/star-wars/schema.json',
140139
documents: './dev-test/star-wars/**/*.graphql',
141140
config: { preResolveTypes: true },
142-
plugins: ['typescript', 'typescript-operations'],
141+
plugins: ['typescript-operations'],
143142
},
144143
'./dev-test/star-wars/types.OnlyEnums.ts': {
145144
schema: './dev-test/star-wars/schema.json',
@@ -150,25 +149,25 @@ const config: CodegenConfig = {
150149
'./dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts': {
151150
schema: './dev-test/star-wars/schema.json',
152151
documents: './dev-test/star-wars/**/*.graphql',
153-
config: { preResolveTypes: true, onlyOperationTypes: true },
154-
plugins: ['typescript', 'typescript-operations'],
152+
config: { preResolveTypes: true },
153+
plugins: ['typescript-operations'],
155154
},
156155
'./dev-test/test-schema/types.preResolveTypes.ts': {
157156
schema: './dev-test/test-schema/schema.graphql',
158157
documents: ['query test { testArr1 testArr2 testArr3 }'],
159158
config: { preResolveTypes: true },
160-
plugins: ['typescript', 'typescript-operations'],
159+
plugins: ['typescript-operations'],
161160
},
162161
'./dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts': {
163162
schema: './dev-test/test-schema/schema.graphql',
164163
documents: ['query test { testArr1 testArr2 testArr3 }'],
165-
config: { preResolveTypes: true, onlyOperationTypes: true },
166-
plugins: ['typescript', 'typescript-operations'],
164+
config: { preResolveTypes: true },
165+
plugins: ['typescript-operations'],
167166
},
168167
'./dev-test/star-wars/types.d.ts': {
169168
schema: './dev-test/star-wars/schema.json',
170-
config: { enumsAsTypes: true },
171-
plugins: ['typescript', 'typescript-operations'],
169+
config: { enumType: 'string-literal' },
170+
plugins: ['typescript-operations'],
172171
},
173172
'./dev-test/modules/': {
174173
schema: './dev-test/modules/*/types/*.graphql',
@@ -179,25 +178,25 @@ const config: CodegenConfig = {
179178
'./dev-test/star-wars/types.globallyAvailable.d.ts': {
180179
schema: './dev-test/star-wars/schema.json',
181180
documents: './dev-test/star-wars/**/*.graphql',
182-
config: { enumsAsTypes: true, noExport: true },
183-
plugins: ['typescript', 'typescript-operations'],
181+
config: { noExport: true },
182+
plugins: ['typescript-operations'],
184183
},
185184
'./dev-test/star-wars/types.avoidOptionals.ts': {
186185
schema: './dev-test/star-wars/schema.json',
187186
documents: './dev-test/star-wars/**/*.graphql',
188187
config: { avoidOptionals: true },
189-
plugins: ['typescript', 'typescript-operations'],
188+
plugins: ['typescript-operations'],
190189
},
191190
'./dev-test/star-wars/types.immutableTypes.ts': {
192191
schema: './dev-test/star-wars/schema.json',
193192
documents: './dev-test/star-wars/**/*.graphql',
194193
config: { immutableTypes: true },
195-
plugins: ['typescript', 'typescript-operations'],
194+
plugins: ['typescript-operations'],
196195
},
197196
'./dev-test/star-wars/types.skipSchema.ts': {
198197
schema: './dev-test/star-wars/schema.json',
199198
documents: './dev-test/star-wars/**/*.graphql',
200-
plugins: ['typescript', 'typescript-operations'],
199+
plugins: ['typescript-operations'],
201200
},
202201
'./dev-test/gql-tag-operations/gql/': {
203202
schema: './dev-test/gql-tag-operations/schema.graphql',
@@ -224,7 +223,7 @@ const config: CodegenConfig = {
224223
'./dev-test/test-null-value/result.d.ts': {
225224
schema: './dev-test/test-null-value/schema.graphql',
226225
documents: ['./dev-test/test-null-value/query.ts'],
227-
plugins: ['typescript', 'typescript-operations'],
226+
plugins: ['typescript-operations'],
228227
config: {
229228
// The combination of these two flags caused the following issue:
230229
// https://github.com/dotansimha/graphql-code-generator/pull/9709

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

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

0 commit comments

Comments
 (0)