From 6acb2f5e6c05db20e20103a8edbed96adb74a909 Mon Sep 17 00:00:00 2001 From: Lucas Constantino Silva Date: Mon, 2 Dec 2019 16:11:21 +0100 Subject: [PATCH] feat: Added helping generic types for hooks --- packages/hooks/src/index.ts | 8 ++++---- packages/hooks/src/useLazyQuery.ts | 5 +++++ packages/hooks/src/useMutation.ts | 5 +++++ packages/hooks/src/useQuery.ts | 5 +++++ packages/hooks/src/useSubscription.ts | 11 +++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/hooks/src/index.ts b/packages/hooks/src/index.ts index e2f32282ab..cdec528073 100644 --- a/packages/hooks/src/index.ts +++ b/packages/hooks/src/index.ts @@ -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'; diff --git a/packages/hooks/src/useLazyQuery.ts b/packages/hooks/src/useLazyQuery.ts index 23670d23c9..e0fd662398 100644 --- a/packages/hooks/src/useLazyQuery.ts +++ b/packages/hooks/src/useLazyQuery.ts @@ -4,6 +4,11 @@ import { DocumentNode } from 'graphql'; import { LazyQueryHookOptions, QueryTuple } from './types'; import { useBaseQuery } from './utils/useBaseQuery'; +export type UseLazyQuery = ( + query: DocumentNode, + options?: LazyQueryHookOptions +) => QueryTuple; + export function useLazyQuery( query: DocumentNode, options?: LazyQueryHookOptions diff --git a/packages/hooks/src/useMutation.ts b/packages/hooks/src/useMutation.ts index f079d77b97..afee31e811 100644 --- a/packages/hooks/src/useMutation.ts +++ b/packages/hooks/src/useMutation.ts @@ -5,6 +5,11 @@ import { DocumentNode } from 'graphql'; import { MutationHookOptions, MutationTuple } from './types'; import { MutationData } from './data/MutationData'; +export type UseMutation = ( + query: DocumentNode, + options?: MutationHookOptions +) => MutationTuple; + export function useMutation( mutation: DocumentNode, options?: MutationHookOptions diff --git a/packages/hooks/src/useQuery.ts b/packages/hooks/src/useQuery.ts index b3b9a493c1..15f6856fa1 100644 --- a/packages/hooks/src/useQuery.ts +++ b/packages/hooks/src/useQuery.ts @@ -4,6 +4,11 @@ import { DocumentNode } from 'graphql'; import { QueryHookOptions } from './types'; import { useBaseQuery } from './utils/useBaseQuery'; +export type UseQuery = ( + query: DocumentNode, + options?: QueryHookOptions +) => QueryResult; + export function useQuery( query: DocumentNode, options?: QueryHookOptions diff --git a/packages/hooks/src/useSubscription.ts b/packages/hooks/src/useSubscription.ts index 274e778d23..787a4d3323 100644 --- a/packages/hooks/src/useSubscription.ts +++ b/packages/hooks/src/useSubscription.ts @@ -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 = ( + query: DocumentNode, + options?: SubscriptionHookOptions +) => { + variables: TVariables; + loading: boolean; + data?: TData; + error?: ApolloError; +}; + export function useSubscription( subscription: DocumentNode, options?: SubscriptionHookOptions