From 373dea0a8c2312e46b248b31fd3d10313bc6666e Mon Sep 17 00:00:00 2001 From: Andrew Moss Date: Tue, 18 Oct 2022 19:04:53 -0600 Subject: [PATCH] feat: Adding in vars to the api --- __specs__/useQuery.spec.ts | 2 +- src/useQueryRd.ts | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/__specs__/useQuery.spec.ts b/__specs__/useQuery.spec.ts index 756dfd9..5292a0c 100644 --- a/__specs__/useQuery.spec.ts +++ b/__specs__/useQuery.spec.ts @@ -25,7 +25,7 @@ describe('useQueryRd', () => { beforeEach(() => { result = { - data: null, + data: undefined, loading: false, error: undefined, _rd: { diff --git a/src/useQueryRd.ts b/src/useQueryRd.ts index 3cfb7cc..9ad75dc 100644 --- a/src/useQueryRd.ts +++ b/src/useQueryRd.ts @@ -1,21 +1,19 @@ -import { - DocumentNode, - QueryResult, - useQuery -} from '@apollo/client' +import { DocumentNode, OperationVariables, QueryResult, useQuery } from '@apollo/client' import { RemoteData } from './rd' -export type QueryResultWithRemoteData = QueryResult & { _rd: RemoteData } +export type QueryResultWithRemoteData = QueryResult & { _rd: RemoteData } /** * @description Maps a `useQuery` QueryResult to the appropriate RemoteData discriminant - * @param d DocumentNode + * @param query DocumentNode + * @param vars Query variables * @returns Everything from `QueryResult` with an accompanying `_rd` property wth the RemoteData object */ -export const useQueryRd = ( - d: DocumentNode -): QueryResultWithRemoteData => { - const res = useQuery(d) +export const useQueryRd = ( + query: DocumentNode, + vars?: V +): QueryResultWithRemoteData => { + const res = useQuery(query, { variables: vars ? { ...vars } : undefined }) if (!res.called) { return {