Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

feat: Added helping generic types for hooks #3726

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export {
resetApolloContext
} from '@apollo/react-common';

export { useQuery } from './useQuery';
export { useLazyQuery } from './useLazyQuery';
export { useMutation } from './useMutation';
export { useSubscription } from './useSubscription';
export * from './useQuery';
export * from './useLazyQuery';
export * from './useMutation';
export * from './useSubscription';
export { useApolloClient } from './useApolloClient';

export { RenderPromises } from './ssr/RenderPromises';
Expand Down
5 changes: 5 additions & 0 deletions packages/hooks/src/useLazyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { DocumentNode } from 'graphql';
import { LazyQueryHookOptions, QueryTuple } from './types';
import { useBaseQuery } from './utils/useBaseQuery';

export type UseLazyQuery<TData = any, TVariables = OperationVariables> = (
query: DocumentNode,
options?: LazyQueryHookOptions<TData, TVariables>
) => QueryTuple<TData, TVariables>;

export function useLazyQuery<TData = any, TVariables = OperationVariables>(
query: DocumentNode,
options?: LazyQueryHookOptions<TData, TVariables>
Expand Down
5 changes: 5 additions & 0 deletions packages/hooks/src/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { DocumentNode } from 'graphql';
import { MutationHookOptions, MutationTuple } from './types';
import { MutationData } from './data/MutationData';

export type UseMutation<TData = any, TVariables = OperationVariables> = (
query: DocumentNode,
options?: MutationHookOptions<TData, TVariables>
) => MutationTuple<TData, TVariables>;

export function useMutation<TData = any, TVariables = OperationVariables>(
mutation: DocumentNode,
options?: MutationHookOptions<TData, TVariables>
Expand Down
5 changes: 5 additions & 0 deletions packages/hooks/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { DocumentNode } from 'graphql';
import { QueryHookOptions } from './types';
import { useBaseQuery } from './utils/useBaseQuery';

export type UseQuery<TData = any, TVariables = OperationVariables> = (
query: DocumentNode,
options?: QueryHookOptions<TData, TVariables>
) => QueryResult<TData, TVariables>;

export function useQuery<TData = any, TVariables = OperationVariables>(
query: DocumentNode,
options?: QueryHookOptions<TData, TVariables>
Expand Down
11 changes: 11 additions & 0 deletions packages/hooks/src/useSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { useContext, useState, useRef, useEffect } from 'react';
import { DocumentNode } from 'graphql';
import { ApolloError } from 'apollo-client';
import { getApolloContext, OperationVariables } from '@apollo/react-common';

import { SubscriptionHookOptions } from './types';
import { SubscriptionData } from './data/SubscriptionData';

export type UseSubscription<TData = any, TVariables = OperationVariables> = (
query: DocumentNode,
options?: SubscriptionHookOptions<TData, TVariables>
) => {
variables: TVariables;
loading: boolean;
data?: TData;
error?: ApolloError;
};

export function useSubscription<TData = any, TVariables = OperationVariables>(
subscription: DocumentNode,
options?: SubscriptionHookOptions<TData, TVariables>
Expand Down