mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 05:17:42 +08:00
Finish porting to relay-1.7 including types
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import { _RefType } from "react-relay";
|
||||
|
||||
export type FragmentKeys<T> = {
|
||||
[P in keyof T]: T[P] extends _RefType<any> | null ? P : never
|
||||
}[keyof T];
|
||||
|
||||
export type FragmentKeysNoLocal<T> = Exclude<FragmentKeys<T>, "local">;
|
||||
@@ -1,12 +1,22 @@
|
||||
import { createFragmentContainer, GraphQLTaggedNode } from "react-relay";
|
||||
import {
|
||||
_RefType,
|
||||
createFragmentContainer,
|
||||
FragmentOrRegularProp,
|
||||
GraphQLTaggedNode,
|
||||
} from "react-relay";
|
||||
import { InferableComponentEnhancerWithProps } from "recompose";
|
||||
import { FragmentKeysNoLocal } from "./types";
|
||||
|
||||
/**
|
||||
* withFragmentContainer is a curried version of `createFragmentContainers`
|
||||
* from Relay.
|
||||
*/
|
||||
export default <T>(
|
||||
fragmentSpec: { [P in keyof T]: GraphQLTaggedNode }
|
||||
): InferableComponentEnhancerWithProps<T, { [P in keyof T]: any }> => (
|
||||
component: React.ComponentType<any>
|
||||
) => createFragmentContainer(component, fragmentSpec) as any;
|
||||
fragmentSpec: { [P in FragmentKeysNoLocal<T>]: GraphQLTaggedNode } & {
|
||||
_?: never;
|
||||
}
|
||||
): InferableComponentEnhancerWithProps<
|
||||
{ [P in FragmentKeysNoLocal<T>]: T[P] },
|
||||
{ [P in FragmentKeysNoLocal<T>]: FragmentOrRegularProp<T[P]> }
|
||||
> => (component: React.ComponentType<any>) =>
|
||||
createFragmentContainer(component, fragmentSpec) as any;
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
GraphQLTaggedNode,
|
||||
} from "relay-runtime";
|
||||
|
||||
import { _RefType } from "react-relay";
|
||||
import { withContext } from "../bootstrap";
|
||||
|
||||
interface Props {
|
||||
@@ -35,9 +36,9 @@ export const LOCAL_ID = "client:root.local";
|
||||
* The `fragmentSpec` must be a `Fragment` on the `LOCAL_TYPE` which
|
||||
* must have the `LOCAL_ID`.
|
||||
*/
|
||||
function withLocalStateContainer<T>(
|
||||
function withLocalStateContainer(
|
||||
fragmentSpec: GraphQLTaggedNode
|
||||
): InferableComponentEnhancer<{ local: T }> {
|
||||
): InferableComponentEnhancer<{ local: _RefType<any> }> {
|
||||
return compose(
|
||||
withContext(({ relayEnvironment }) => ({ relayEnvironment })),
|
||||
hoistStatics((BaseComponent: React.ComponentType<any>) => {
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import {
|
||||
ConnectionConfig,
|
||||
createPaginationContainer,
|
||||
FragmentOrRegularProp,
|
||||
GraphQLTaggedNode,
|
||||
RelayPaginationProp,
|
||||
} from "react-relay";
|
||||
import { InferableComponentEnhancerWithProps } from "recompose";
|
||||
import { FragmentKeysNoLocal } from "./types";
|
||||
|
||||
/**
|
||||
* withPaginationContainer is a curried version of `createPaginationContainers`
|
||||
* from Relay.
|
||||
*/
|
||||
export default <T, InnerProps, FragmentVariables, QueryVariables>(
|
||||
fragmentSpec: { [P in keyof T]: GraphQLTaggedNode },
|
||||
connectionConfig: ConnectionConfig<
|
||||
InnerProps,
|
||||
FragmentVariables,
|
||||
QueryVariables
|
||||
>
|
||||
export default <T, FragmentVariables, QueryVariables>(
|
||||
fragmentSpec: { [P in FragmentKeysNoLocal<T>]: GraphQLTaggedNode } & {
|
||||
_?: never;
|
||||
},
|
||||
connectionConfig: ConnectionConfig<T, FragmentVariables, QueryVariables>
|
||||
): InferableComponentEnhancerWithProps<
|
||||
T & { relay: RelayPaginationProp },
|
||||
{ [P in keyof T]: any }
|
||||
{ [P in FragmentKeysNoLocal<T>]: T[P] } & { relay: RelayPaginationProp },
|
||||
{ [P in FragmentKeysNoLocal<T>]: FragmentOrRegularProp<T[P]> }
|
||||
> => (component: React.ComponentType<any>) =>
|
||||
createPaginationContainer(component, fragmentSpec, connectionConfig) as any;
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
import {
|
||||
createRefetchContainer,
|
||||
FragmentOrRegularProp,
|
||||
GraphQLTaggedNode,
|
||||
RelayRefetchProp,
|
||||
} from "react-relay";
|
||||
import { InferableComponentEnhancerWithProps } from "recompose";
|
||||
import { FragmentKeysNoLocal } from "./types";
|
||||
|
||||
/**
|
||||
* withRefetchContainer is a curried version of `createRefetchContainers`
|
||||
* from Relay.
|
||||
*/
|
||||
export default <T>(
|
||||
fragmentSpec: { [P in keyof T]: GraphQLTaggedNode },
|
||||
fragmentSpec: { [P in FragmentKeysNoLocal<T>]: GraphQLTaggedNode } & {
|
||||
_?: never;
|
||||
},
|
||||
refetchQuery: GraphQLTaggedNode
|
||||
): InferableComponentEnhancerWithProps<
|
||||
T & { relay: RelayRefetchProp },
|
||||
{ [P in keyof T]: any }
|
||||
{ [P in FragmentKeysNoLocal<T>]: T[P] } & { relay: RelayRefetchProp },
|
||||
{ [P in FragmentKeysNoLocal<T>]: FragmentOrRegularProp<T[P]> }
|
||||
> => (component: React.ComponentType<any>) =>
|
||||
createRefetchContainer(component, fragmentSpec, refetchQuery) as any;
|
||||
|
||||
Reference in New Issue
Block a user