import { createUseMetaState , UseMetaState } from './meta/useMetaState' ; import { createUseMutation , UseMutation } from './mutation/useMutation' ; import { createGraphqlHOC , GraphQLHOC } from './query/hoc' ; import { createPrepareQuery , PrepareQuery } from './query/preparedQuery' ; import { createUseLazyQuery , LazyFetchPolicy , UseLazyQuery , } from './query/useLazyQuery' ; import { createUseQuery , UseQuery } from './query/useQuery' ; import { createUseRefetch , UseRefetch } from './query/useRefetch' ; import { createUseTransactionQuery , UseTransactionQuery , } from './query/useTransactionQuery' ; import { createSSRHelpers , PrepareReactRender , UseHydrateCache , } from './ssr/ssr' ; import { createUseSubscription , UseSubscription , } from './subscription/useSubscription' ; import type { RetryOptions , GQtyClient } from 'gqty' ; import type { FetchPolicy } from './common' ; import type { ReactClientOptionsWithDefaults } from './utils' ; import { createUsePaginatedQuery , PaginatedQueryFetchPolicy , UsePaginatedQuery , } from './query/usePaginatedQuery' ; export interface ReactClientDefaults { default suspense ? : boolean ; default lazyQuerySuspense ? : boolean ; /**
     * Enable/Disable by default 'React Suspense' behavior for useTransactionQuery hook
     *
     * > _Valid only for __useTransactionQuery___
     *
     * > _You can override it on a per-hook basis_
     *
     * __The _default value_ is obtained from the "`defaults.suspense`" value__
     */ transactionQuerySuspense ? : boolean ; default mutationSuspense ? : boolean ; /**
     * Enable/Disable by default 'React Suspense' behavior for prepareQuery hooks
     *
     * > _Valid only for __prepareQuery___ hooks
     *
     * > _You can override it on a per-hook basis_
     *
     * __The _default value_ is obtained from the "`defaults.suspense`" value__
     */ preparedSuspense ? : boolean ; default paginatedQuerySuspense ? : boolean ; default transactionFetchPolicy ? : FetchPolicy ; default lazyFetchPolicy ? : LazyFetchPolicy ; default paginatedQueryFetchPolicy ? : PaginatedQueryFetchPolicy ; default staleWhileRevalidate ? : boolean ; default retry ? : RetryOptions ; default refetchAfterHydrate ? : boolean ; } export interface CreateReactClientOptions { /**
     * Default behaviour values
     */ defaults ? : ReactClientDefaults ; } export interface ReactClient < GeneratedSchema extends { query : object ; mutation : object ; subscription : object ; } > { useQuery : UseQuery < GeneratedSchema > ; useRefetch : UseRefetch ; useLazyQuery : UseLazyQuery < GeneratedSchema > ; useTransactionQuery : UseTransactionQuery < GeneratedSchema > ; usePaginatedQuery : UsePaginatedQuery < GeneratedSchema > ; useMutation : UseMutation < GeneratedSchema > ; graphql : GraphQLHOC ; state : { isLoading : boolean ; } ; prepareReactRender : PrepareReactRender ; useHydrateCache : UseHydrateCache ; useMetaState : UseMetaState ; useSubscription : UseSubscription < GeneratedSchema > ; prepareQuery : PrepareQuery < GeneratedSchema > ; } export function createReactClient < GeneratedSchema extends { query : object ; mutation : object ; subscription : object ; } > ( client , optsCreate = { } ) { const { suspense = false } = ( optsCreate . defaults ||= { } ) ; const { transactionFetchPolicy = 'cache-first' , lazyFetchPolicy = 'network-only' , staleWhileRevalidate = false , retry = true , lazyQuerySuspense = false , transactionQuerySuspense = suspense , mutationSuspense = false , preparedSuspense = suspense , refetchAfterHydrate = false , paginatedQueryFetchPolicy = 'cache-first' , paginatedQuerySuspense = suspense , } = optsCreate . defaults ; const defaults = { transactionFetchPolicy , lazyFetchPolicy , staleWhileRevalidate , suspense , retry , lazyQuerySuspense , transactionQuerySuspense , mutationSuspense , preparedSuspense , refetchAfterHydrate , paginatedQueryFetchPolicy , paginatedQuerySuspense , } ; const opts = Object . assign ( { } , optsCreate , { defaults , } ) ; const state = new Proxy ( { isLoading : false , } , { get ( target , key , receiver ) { if ( key === 'isLoading' ) return Boolean ( client . scheduler . resolving ) ; return Reflect . get ( target , key , receiver ) ; } , } ) ; const { prepareReactRender , useHydrateCache } = createSSRHelpers ( client , opts ) ; return { useQuery : createUseQuery < GeneratedSchema > ( client , opts ) , useRefetch : createUseRefetch ( client , opts ) , useLazyQuery : createUseLazyQuery < GeneratedSchema > ( client , opts ) , useTransactionQuery : createUseTransactionQuery < GeneratedSchema > ( client , opts ) , usePaginatedQuery : createUsePaginatedQuery < GeneratedSchema > ( client , opts ) , useMutation : createUseMutation < GeneratedSchema > ( client , opts ) , graphql : createGraphqlHOC ( client , opts ) , state , prepareReactRender , useHydrateCache , useMetaState : createUseMetaState ( client ) , useSubscription : createUseSubscription < GeneratedSchema > ( client , opts ) , prepareQuery : createPrepareQuery < GeneratedSchema > ( client , opts ) , } ; }