From 792ceed2ad5a0c8923ac8884b61d16508e4eb70b Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 31 Aug 2018 02:28:53 +0200 Subject: [PATCH] No more patched packages! --- package-lock.json | 11 +++++-- package.json | 2 +- .../lib/relay/withPaginationContainer.ts | 30 +++++++++++++++++-- .../stream/containers/ReplyListContainer.tsx | 4 +-- .../stream/containers/StreamContainer.tsx | 4 +-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 71f83ebd4..473eb21e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2069,9 +2069,14 @@ } }, "@types/react-relay": { - "version": "github:coralproject/patched#c8e07adee83418ca04acfc99a3c542e082d70116", - "from": "github:coralproject/patched#types/react-relay", - "dev": true + "version": "1.3.9", + "resolved": "https://registry.npmjs.org/@types/react-relay/-/react-relay-1.3.9.tgz", + "integrity": "sha512-DFhFrEiDUYxR6VWpkf14CnzS7vtpWaVku0EmnxT2X4U45rOUP75nnOEnRCixZyyxIgr7ULpg5Zc1G9VJpQF7GQ==", + "dev": true, + "requires": { + "@types/react": "*", + "@types/relay-runtime": "*" + } }, "@types/react-responsive": { "version": "3.0.1", diff --git a/package.json b/package.json index cc589fb99..ac9113a07 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,7 @@ "@types/query-string": "^6.1.0", "@types/react-copy-to-clipboard": "^4.2.5", "@types/react-dom": "^16.0.6", - "@types/react-relay": "github:coralproject/patched#types/react-relay", + "@types/react-relay": "^1.3.9", "@types/react-responsive": "^3.0.1", "@types/react-test-renderer": "^16.0.1", "@types/recompose": "^0.26.1", diff --git a/src/core/client/framework/lib/relay/withPaginationContainer.ts b/src/core/client/framework/lib/relay/withPaginationContainer.ts index 143c05b44..8535d0a7f 100644 --- a/src/core/client/framework/lib/relay/withPaginationContainer.ts +++ b/src/core/client/framework/lib/relay/withPaginationContainer.ts @@ -1,22 +1,46 @@ import { - ConnectionConfig, + ConnectionData, createPaginationContainer, FragmentOrRegularProp, GraphQLTaggedNode, RelayPaginationProp, } from "react-relay"; import { InferableComponentEnhancerWithProps } from "recompose"; +import { Variables } from "relay-runtime"; import { FragmentKeysNoLocal } from "./types"; +// TODO: (cvle) at some point we might switch these to stock react-relay typings +// when they become versatile enough. +export type FragmentVariablesGetter = ( + prevVars: V, + totalCount: number +) => V; + +export interface ConnectionConfig< + P, + V extends Variables = Variables, + F extends Variables = Variables +> { + direction?: "backward" | "forward"; + getConnectionFromProps?(props: P): ConnectionData | undefined | null; + getFragmentVariables?: FragmentVariablesGetter; + getVariables( + props: P, + paginationInfo: { count: number; cursor?: string }, + fragmentVariables: F + ): V; + query: GraphQLTaggedNode; +} + /** * withPaginationContainer is a curried version of `createPaginationContainers` * from Relay. */ -export default ( +export default ( fragmentSpec: { [P in FragmentKeysNoLocal]: GraphQLTaggedNode } & { _?: never; }, - connectionConfig: ConnectionConfig + connectionConfig: ConnectionConfig ): InferableComponentEnhancerWithProps< { [P in FragmentKeysNoLocal]: T[P] } & { relay: RelayPaginationProp }, { [P in FragmentKeysNoLocal]: FragmentOrRegularProp } diff --git a/src/core/client/stream/containers/ReplyListContainer.tsx b/src/core/client/stream/containers/ReplyListContainer.tsx index e2d409a6d..de741c60d 100644 --- a/src/core/client/stream/containers/ReplyListContainer.tsx +++ b/src/core/client/stream/containers/ReplyListContainer.tsx @@ -68,8 +68,8 @@ interface FragmentVariables { const enhanced = withPaginationContainer< InnerProps, - FragmentVariables, - ReplyListContainerPaginationQueryVariables + ReplyListContainerPaginationQueryVariables, + FragmentVariables >( { comment: graphql` diff --git a/src/core/client/stream/containers/StreamContainer.tsx b/src/core/client/stream/containers/StreamContainer.tsx index dc5f1409f..ff24de3fb 100644 --- a/src/core/client/stream/containers/StreamContainer.tsx +++ b/src/core/client/stream/containers/StreamContainer.tsx @@ -65,8 +65,8 @@ interface FragmentVariables { const enhanced = withPaginationContainer< InnerProps, - FragmentVariables, - StreamContainerPaginationQueryVariables + StreamContainerPaginationQueryVariables, + FragmentVariables >( { asset: graphql`