import { createPaginationContainer , FragmentOrRegularProp , GraphQLTaggedNode , RelayPaginationProp , } from "react-relay" ; import { InferableComponentEnhancerWithProps , wrapDisplayName , } from "recompose" ; import { PageInfo , Variables } from "relay-runtime" ; import { resolveModule , resolveModuleObject } from "./helpers" ; import { FragmentKeysNoLocal } from "./types" ; interface ConnectionData { edges ? : ReadonlyArray < any > | null ; pageInfo ? : Partial < PageInfo > | null ; } export type FragmentVariablesGetter < V extends Variables = Variables > = ( prevVars : V , totalCount : number ) => V ; export interface ConnectionConfig < P , V extends Variables = Variables , F extends Variables = Variables > { direction ? : "backward" | "forward" ; getConnectionFromProps ? ( props ) : ConnectionData | undefined | null ; getFragmentVariables ? : FragmentVariablesGetter < F > ; getVariables ( props , paginationInfo , fragmentVariables ) : V ; query : GraphQLTaggedNode ; } /**
 * withPaginationContainer is a curried version of `createPaginationContainers`
 * from Relay.
 */ export default < T , QueryVariables , FragmentVariables > ( fragmentSpec , connectionConfig ) : InferableComponentEnhancerWithProps < { [ P in FragmentKeysNoLocal < T > ] : T [ P ] ; } & { relay : RelayPaginationProp ; } , { [ P in FragmentKeysNoLocal < T > ] : FragmentOrRegularProp < T [ P ] > ; } > => ( component ) => { const result = createPaginationContainer ( component , resolveModuleObject ( fragmentSpec ) , { ... connectionConfig , query : resolveModule ( connectionConfig . query ) , } ) ; result . displayName = wrapDisplayName ( component , "Relay" ) ; return result as any ; } ;