Skip to content

Commit

Permalink
feat(flow): flow-operations tries to spread inexact objects #8000 (#15)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Athelian authored Feb 13, 2024
1 parent a269632 commit d13f6cc
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 153 deletions.
6 changes: 6 additions & 0 deletions .changeset/tricky-hats-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-codegen/flow-operations': patch
---

Flow types computed by graphql operations now adhere to flow exact configuration specified by the
user
156 changes: 78 additions & 78 deletions dev-test/githunt/flow.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,54 +176,54 @@ export type OnCommentAddedSubscriptionVariables = {
repoFullName: $ElementType<Scalars, 'String'>,
};

export type OnCommentAddedSubscription = {
export type OnCommentAddedSubscription = {|
...{ __typename?: 'Subscription' },
...{|
commentAdded?: ?{
commentAdded?: ?{|
...{ __typename?: 'Comment' },
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
...{|
postedBy: {
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, html_url: * |}>,
},
|},
|},
},
|},
|},
};
|};

export type CommentQueryVariables = {
repoFullName: $ElementType<Scalars, 'String'>,
limit?: ?$ElementType<Scalars, 'Int'>,
offset?: ?$ElementType<Scalars, 'Int'>,
};

export type CommentQuery = {
export type CommentQuery = {|
...{ __typename?: 'Query' },
...{|
currentUser?: ?{
currentUser?: ?{|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, html_url: * |}>,
},
entry?: ?{
|},
entry?: ?{|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| id: *, createdAt: *, commentCount: * |}>,
...{|
postedBy: {
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, html_url: * |}>,
},
comments: Array<?{
|},
comments: Array<?{|
...{ __typename?: 'Comment' },
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
...{|
postedBy: {
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, html_url: * |}>,
},
|},
|},
}>,
repository: {
|}>,
repository: {|
...{ __typename?: 'Repository' },
...$Pick<
Repository,
Expand All @@ -235,40 +235,40 @@ export type CommentQuery = {
html_url: *,
|},
>,
},
|},
|},
},
|},
|},
};
|};

export type CommentsPageCommentFragment = {
export type CommentsPageCommentFragment = {|
...{ __typename?: 'Comment' },
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
...{|
postedBy: {
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, html_url: * |}>,
},
|},
|},
};
|};

export type CurrentUserForProfileQueryVariables = {};

export type CurrentUserForProfileQuery = {
export type CurrentUserForProfileQuery = {|
...{ __typename?: 'Query' },
...{|
currentUser?: ?{
currentUser?: ?{|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, avatar_url: * |}>,
},
|},
|},
};
|};

export type FeedEntryFragment = {
export type FeedEntryFragment = {|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| id: *, commentCount: *, score: *, createdAt: * |}>,
...{|
repository: {
repository: {|
...{ __typename?: 'Repository' },
...$Pick<
Repository,
Expand All @@ -281,41 +281,41 @@ export type FeedEntryFragment = {
|},
>,
...{|
owner?: ?{
owner?: ?{|
...{ __typename?: 'User' },
...$Pick<User, {| avatar_url: * |}>,
},
|},
|},
},
vote: {
|},
vote: {|
...{ __typename?: 'Vote' },
...$Pick<Vote, {| vote_value: * |}>,
},
postedBy: {
|},
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| html_url: *, login: * |}>,
},
|},
|},
};
|};

export type FeedQueryVariables = {
type: FeedType,
offset?: ?$ElementType<Scalars, 'Int'>,
limit?: ?$ElementType<Scalars, 'Int'>,
};

export type FeedQuery = {
export type FeedQuery = {|
...{ __typename?: 'Query' },
...{|
currentUser?: ?{
currentUser?: ?{|
...{ __typename?: 'User' },
...$Pick<User, {| login: * |}>,
},
feed?: ?Array<?{
|},
feed?: ?Array<?{|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| id: *, commentCount: *, score: *, createdAt: * |}>,
...{|
repository: {
repository: {|
...{ __typename?: 'Repository' },
...$Pick<
Repository,
Expand All @@ -328,103 +328,103 @@ export type FeedQuery = {
|},
>,
...{|
owner?: ?{
owner?: ?{|
...{ __typename?: 'User' },
...$Pick<User, {| avatar_url: * |}>,
},
|},
|},
},
vote: {
|},
vote: {|
...{ __typename?: 'Vote' },
...$Pick<Vote, {| vote_value: * |}>,
},
postedBy: {
|},
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| html_url: *, login: * |}>,
},
|},
|},
}>,
|}>,
|},
};
|};

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

export type SubmitRepositoryMutation = {
export type SubmitRepositoryMutation = {|
...{ __typename?: 'Mutation' },
...{|
submitRepository?: ?{
submitRepository?: ?{|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| createdAt: * |}>,
},
|},
|},
};
|};

export type RepoInfoFragment = {
export type RepoInfoFragment = {|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| createdAt: * |}>,
...{|
repository: {
repository: {|
...{ __typename?: 'Repository' },
...$Pick<Repository, {| description?: *, stargazers_count: *, open_issues_count?: * |}>,
},
postedBy: {
|},
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| html_url: *, login: * |}>,
},
|},
|},
};
|};

export type SubmitCommentMutationVariables = {
repoFullName: $ElementType<Scalars, 'String'>,
commentContent: $ElementType<Scalars, 'String'>,
};

export type SubmitCommentMutation = {
export type SubmitCommentMutation = {|
...{ __typename?: 'Mutation' },
...{|
submitComment?: ?{
submitComment?: ?{|
...{ __typename?: 'Comment' },
...$Pick<Comment, {| id: *, createdAt: *, content: * |}>,
...{|
postedBy: {
postedBy: {|
...{ __typename?: 'User' },
...$Pick<User, {| login: *, html_url: * |}>,
},
|},
|},
},
|},
|},
};
|};

export type VoteButtonsFragment = {
export type VoteButtonsFragment = {|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| score: * |}>,
...{|
vote: {
vote: {|
...{ __typename?: 'Vote' },
...$Pick<Vote, {| vote_value: * |}>,
},
|},
|},
};
|};

export type VoteMutationVariables = {
repoFullName: $ElementType<Scalars, 'String'>,
type: VoteType,
};

export type VoteMutation = {
export type VoteMutation = {|
...{ __typename?: 'Mutation' },
...{|
vote?: ?{
vote?: ?{|
...{ __typename?: 'Entry' },
...$Pick<Entry, {| score: *, id: * |}>,
...{|
vote: {
vote: {|
...{ __typename?: 'Vote' },
...$Pick<Vote, {| vote_value: * |}>,
},
|},
|},
},
|},
|},
};
|};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ export class FlowWithPickSelectionSetProcessor extends BaseSelectionSetProcessor
if (pieces.length === 1) {
return pieces[0];
}
return `({\n ${pieces.map(t => indent(`...${t}`)).join(`,\n`)}\n})`;

const useFlowExactObject = this.config.useFlowExactObjects;

return `({${useFlowExactObject ? '|' : ''}\n ${pieces
.map(t => indent(`...${t}`))
.join(`,\n`)}\n${useFlowExactObject ? '|' : ''}})`;
}

transformLinkFields(fields: LinkField[]): ProcessResult {
Expand Down
Loading

0 comments on commit d13f6cc

Please sign in to comment.