Skip to content

Commit d13f6cc

Browse files
authored
feat(flow): flow-operations tries to spread inexact objects #8000 (#15)
* feat(flow): config.exact also exactifies top-level Before this change, only inner fragments are made exact * fix(flow): flowExactObjects linter errors * chore(flow): add changeset * chore(flow): update existing tests * chore(flow): prettify * chore(flow): generate examples
1 parent a269632 commit d13f6cc

File tree

5 files changed

+164
-153
lines changed

5 files changed

+164
-153
lines changed

.changeset/tricky-hats-push.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-codegen/flow-operations': patch
3+
---
4+
5+
Flow types computed by graphql operations now adhere to flow exact configuration specified by the
6+
user

dev-test/githunt/flow.flow.js

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -176,54 +176,54 @@ export type OnCommentAddedSubscriptionVariables = {
176176
repoFullName: $ElementType<Scalars, 'String'>,
177177
};
178178

179-
export type OnCommentAddedSubscription = {
179+
export type OnCommentAddedSubscription = {|
180180
...{ __typename?: 'Subscription' },
181181
...{|
182-
commentAdded?: ?{
182+
commentAdded?: ?{|
183183
...{ __typename?: 'Comment' },
184184
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
185185
...{|
186-
postedBy: {
186+
postedBy: {|
187187
...{ __typename?: 'User' },
188188
...$Pick<User, {| login: *, html_url: * |}>,
189-
},
189+
|},
190190
|},
191-
},
191+
|},
192192
|},
193-
};
193+
|};
194194

195195
export type CommentQueryVariables = {
196196
repoFullName: $ElementType<Scalars, 'String'>,
197197
limit?: ?$ElementType<Scalars, 'Int'>,
198198
offset?: ?$ElementType<Scalars, 'Int'>,
199199
};
200200

201-
export type CommentQuery = {
201+
export type CommentQuery = {|
202202
...{ __typename?: 'Query' },
203203
...{|
204-
currentUser?: ?{
204+
currentUser?: ?{|
205205
...{ __typename?: 'User' },
206206
...$Pick<User, {| login: *, html_url: * |}>,
207-
},
208-
entry?: ?{
207+
|},
208+
entry?: ?{|
209209
...{ __typename?: 'Entry' },
210210
...$Pick<Entry, {| id: *, createdAt: *, commentCount: * |}>,
211211
...{|
212-
postedBy: {
212+
postedBy: {|
213213
...{ __typename?: 'User' },
214214
...$Pick<User, {| login: *, html_url: * |}>,
215-
},
216-
comments: Array<?{
215+
|},
216+
comments: Array<?{|
217217
...{ __typename?: 'Comment' },
218218
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
219219
...{|
220-
postedBy: {
220+
postedBy: {|
221221
...{ __typename?: 'User' },
222222
...$Pick<User, {| login: *, html_url: * |}>,
223-
},
223+
|},
224224
|},
225-
}>,
226-
repository: {
225+
|}>,
226+
repository: {|
227227
...{ __typename?: 'Repository' },
228228
...$Pick<
229229
Repository,
@@ -235,40 +235,40 @@ export type CommentQuery = {
235235
html_url: *,
236236
|},
237237
>,
238-
},
238+
|},
239239
|},
240-
},
240+
|},
241241
|},
242-
};
242+
|};
243243

244-
export type CommentsPageCommentFragment = {
244+
export type CommentsPageCommentFragment = {|
245245
...{ __typename?: 'Comment' },
246246
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
247247
...{|
248-
postedBy: {
248+
postedBy: {|
249249
...{ __typename?: 'User' },
250250
...$Pick<User, {| login: *, html_url: * |}>,
251-
},
251+
|},
252252
|},
253-
};
253+
|};
254254

255255
export type CurrentUserForProfileQueryVariables = {};
256256

257-
export type CurrentUserForProfileQuery = {
257+
export type CurrentUserForProfileQuery = {|
258258
...{ __typename?: 'Query' },
259259
...{|
260-
currentUser?: ?{
260+
currentUser?: ?{|
261261
...{ __typename?: 'User' },
262262
...$Pick<User, {| login: *, avatar_url: * |}>,
263-
},
263+
|},
264264
|},
265-
};
265+
|};
266266

267-
export type FeedEntryFragment = {
267+
export type FeedEntryFragment = {|
268268
...{ __typename?: 'Entry' },
269269
...$Pick<Entry, {| id: *, commentCount: *, score: *, createdAt: * |}>,
270270
...{|
271-
repository: {
271+
repository: {|
272272
...{ __typename?: 'Repository' },
273273
...$Pick<
274274
Repository,
@@ -281,41 +281,41 @@ export type FeedEntryFragment = {
281281
|},
282282
>,
283283
...{|
284-
owner?: ?{
284+
owner?: ?{|
285285
...{ __typename?: 'User' },
286286
...$Pick<User, {| avatar_url: * |}>,
287-
},
287+
|},
288288
|},
289-
},
290-
vote: {
289+
|},
290+
vote: {|
291291
...{ __typename?: 'Vote' },
292292
...$Pick<Vote, {| vote_value: * |}>,
293-
},
294-
postedBy: {
293+
|},
294+
postedBy: {|
295295
...{ __typename?: 'User' },
296296
...$Pick<User, {| html_url: *, login: * |}>,
297-
},
297+
|},
298298
|},
299-
};
299+
|};
300300

301301
export type FeedQueryVariables = {
302302
type: FeedType,
303303
offset?: ?$ElementType<Scalars, 'Int'>,
304304
limit?: ?$ElementType<Scalars, 'Int'>,
305305
};
306306

307-
export type FeedQuery = {
307+
export type FeedQuery = {|
308308
...{ __typename?: 'Query' },
309309
...{|
310-
currentUser?: ?{
310+
currentUser?: ?{|
311311
...{ __typename?: 'User' },
312312
...$Pick<User, {| login: * |}>,
313-
},
314-
feed?: ?Array<?{
313+
|},
314+
feed?: ?Array<?{|
315315
...{ __typename?: 'Entry' },
316316
...$Pick<Entry, {| id: *, commentCount: *, score: *, createdAt: * |}>,
317317
...{|
318-
repository: {
318+
repository: {|
319319
...{ __typename?: 'Repository' },
320320
...$Pick<
321321
Repository,
@@ -328,103 +328,103 @@ export type FeedQuery = {
328328
|},
329329
>,
330330
...{|
331-
owner?: ?{
331+
owner?: ?{|
332332
...{ __typename?: 'User' },
333333
...$Pick<User, {| avatar_url: * |}>,
334-
},
334+
|},
335335
|},
336-
},
337-
vote: {
336+
|},
337+
vote: {|
338338
...{ __typename?: 'Vote' },
339339
...$Pick<Vote, {| vote_value: * |}>,
340-
},
341-
postedBy: {
340+
|},
341+
postedBy: {|
342342
...{ __typename?: 'User' },
343343
...$Pick<User, {| html_url: *, login: * |}>,
344-
},
344+
|},
345345
|},
346-
}>,
346+
|}>,
347347
|},
348-
};
348+
|};
349349

350350
export type SubmitRepositoryMutationVariables = {
351351
repoFullName: $ElementType<Scalars, 'String'>,
352352
};
353353

354-
export type SubmitRepositoryMutation = {
354+
export type SubmitRepositoryMutation = {|
355355
...{ __typename?: 'Mutation' },
356356
...{|
357-
submitRepository?: ?{
357+
submitRepository?: ?{|
358358
...{ __typename?: 'Entry' },
359359
...$Pick<Entry, {| createdAt: * |}>,
360-
},
360+
|},
361361
|},
362-
};
362+
|};
363363

364-
export type RepoInfoFragment = {
364+
export type RepoInfoFragment = {|
365365
...{ __typename?: 'Entry' },
366366
...$Pick<Entry, {| createdAt: * |}>,
367367
...{|
368-
repository: {
368+
repository: {|
369369
...{ __typename?: 'Repository' },
370370
...$Pick<Repository, {| description?: *, stargazers_count: *, open_issues_count?: * |}>,
371-
},
372-
postedBy: {
371+
|},
372+
postedBy: {|
373373
...{ __typename?: 'User' },
374374
...$Pick<User, {| html_url: *, login: * |}>,
375-
},
375+
|},
376376
|},
377-
};
377+
|};
378378

379379
export type SubmitCommentMutationVariables = {
380380
repoFullName: $ElementType<Scalars, 'String'>,
381381
commentContent: $ElementType<Scalars, 'String'>,
382382
};
383383

384-
export type SubmitCommentMutation = {
384+
export type SubmitCommentMutation = {|
385385
...{ __typename?: 'Mutation' },
386386
...{|
387-
submitComment?: ?{
387+
submitComment?: ?{|
388388
...{ __typename?: 'Comment' },
389389
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
390390
...{|
391-
postedBy: {
391+
postedBy: {|
392392
...{ __typename?: 'User' },
393393
...$Pick<User, {| login: *, html_url: * |}>,
394-
},
394+
|},
395395
|},
396-
},
396+
|},
397397
|},
398-
};
398+
|};
399399

400-
export type VoteButtonsFragment = {
400+
export type VoteButtonsFragment = {|
401401
...{ __typename?: 'Entry' },
402402
...$Pick<Entry, {| score: * |}>,
403403
...{|
404-
vote: {
404+
vote: {|
405405
...{ __typename?: 'Vote' },
406406
...$Pick<Vote, {| vote_value: * |}>,
407-
},
407+
|},
408408
|},
409-
};
409+
|};
410410

411411
export type VoteMutationVariables = {
412412
repoFullName: $ElementType<Scalars, 'String'>,
413413
type: VoteType,
414414
};
415415

416-
export type VoteMutation = {
416+
export type VoteMutation = {|
417417
...{ __typename?: 'Mutation' },
418418
...{|
419-
vote?: ?{
419+
vote?: ?{|
420420
...{ __typename?: 'Entry' },
421421
...$Pick<Entry, {| score: *, id: * |}>,
422422
...{|
423-
vote: {
423+
vote: {|
424424
...{ __typename?: 'Vote' },
425425
...$Pick<Vote, {| vote_value: * |}>,
426-
},
426+
|},
427427
|},
428-
},
428+
|},
429429
|},
430-
};
430+
|};

packages/plugins/flow/operations/src/flow-selection-set-processor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ export class FlowWithPickSelectionSetProcessor extends BaseSelectionSetProcessor
5555
if (pieces.length === 1) {
5656
return pieces[0];
5757
}
58-
return `({\n ${pieces.map(t => indent(`...${t}`)).join(`,\n`)}\n})`;
58+
59+
const useFlowExactObject = this.config.useFlowExactObjects;
60+
61+
return `({${useFlowExactObject ? '|' : ''}\n ${pieces
62+
.map(t => indent(`...${t}`))
63+
.join(`,\n`)}\n${useFlowExactObject ? '|' : ''}})`;
5964
}
6065

6166
transformLinkFields(fields: LinkField[]): ProcessResult {

0 commit comments

Comments
 (0)