Skip to content

Commit

Permalink
feat(typescript-react-apollo): support useBackgroundQuery and useLoad…
Browse files Browse the repository at this point in the history
…ableQuery

Implement `useBackgroundQuery` and `useLoadableQuery` hooks for React
Apollo. These APIs are added in 3.8.0 and 3.9.0 respectively.

Suspense support in Apollo Client provides 5 new hooks as described in
https://www.apollographql.com/docs/react/data/suspense/.
`useSuspenseQuery` support was added in
dotansimha#434.
Among other 4 hooks, `useBackgroundQuery` and `useLoadableQuery` are
the ones that take a GraphQL document as an argument like other existing
hooks. The support for these hooks are added in this change.

Other hooks, `useQueryRefHanders` and `useReadQuery` do not take a
GraphQL document as an argument, so they do not need to be added as the
generated code. Both take the return values of other hooks as an
argument, and the types are inferred from it.
  • Loading branch information
draftcode committed Aug 7, 2024
1 parent a563726 commit 1ececc4
Show file tree
Hide file tree
Showing 21 changed files with 952 additions and 79 deletions.
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: * |}>,
|},
},
|},
|},
},
|},
|};
};
Loading

0 comments on commit 1ececc4

Please sign in to comment.