/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format */ // flowlint ambiguous-object-type:error 'use strict'; import type { Disposable, FragmentReference, GraphQLTaggedNode, IEnvironment, Observer, Variables, } from 'relay-runtime'; export type GeneratedNodeMap = {[key: string]: GraphQLTaggedNode, ...}; export type ObserverOrCallback = Observer | ((error: ?Error) => mixed); // NOTE: This is an inexact type in order to allow a RelayPaginationProp or // RelayRefetchProp to flow into a RelayProp. export type RelayProp = {+environment: IEnvironment, ...}; export type RelayPaginationProp = {| +environment: IEnvironment, +hasMore: () => boolean, +isLoading: () => boolean, +loadMore: ( pageSize: number, observerOrCallback: ?ObserverOrCallback, options?: RefetchOptions, ) => ?Disposable, +refetchConnection: ( totalCount: number, observerOrCallback: ?ObserverOrCallback, refetchVariables: ?Variables, ) => ?Disposable, |}; export type RelayRefetchProp = {| +environment: IEnvironment, +refetch: ( refetchVariables: Variables | ((fragmentVariables: Variables) => Variables), renderVariables: ?Variables, observerOrCallback: ?ObserverOrCallback, options?: RefetchOptions, ) => Disposable, |}; export type RefetchOptions = {| +force?: boolean, +fetchPolicy?: 'store-or-network' | 'network-only', +metadata?: {[key: string]: mixed, ...}, |}; /** * A utility type which takes the type of a fragment's data (typically found in * a relay generated file) and returns a fragment reference type. This is used * when the input to a Relay component needs to be explicitly typed: * * // ExampleComponent.js * import type {ExampleComponent_data} from './generated/ExampleComponent_data.graphql'; * type Props = { * title: string, * data: ExampleComponent_data, * }; * * export default createFragmentContainer( * (props: Props) =>
{props.title}, {props.data.someField}
, * graphql` * fragment ExampleComponent_data on SomeType { * someField * }` * ); * * // ExampleUsage.js * import type {ExampleComponent_data} from './generated/ExampleComponent_data.graphql'; * type Props = { * title: string, * data: $FragmentRef, * }; * * export default function ExampleUsage(props: Props) { * return * } * */ export type $FragmentRef = { +$fragmentRefs: $PropertyType, ... }; /** * A utility type that takes the Props of a component and the type of * `props.relay` and returns the props of the container. */ // prettier-ignore export type $RelayProps = $ObjMap< $Diff, & (( T) => T) & ((?T) => ?T) & (( T ) => $FragmentRef ) & ((? T ) => ? $FragmentRef ) & (( $ReadOnlyArray< T>) => $ReadOnlyArray< $FragmentRef>) & ((?$ReadOnlyArray< T>) => ?$ReadOnlyArray< $FragmentRef>) & (( $ReadOnlyArray) => $ReadOnlyArray>) & ((?$ReadOnlyArray) => ?$ReadOnlyArray>) & ((T) => T), >; export type RelayFragmentContainer = React$ComponentType< $RelayProps, RelayProp>, >; export type RelayPaginationContainer = React$ComponentType< $RelayProps, RelayPaginationProp>, >; export type RelayRefetchContainer = React$ComponentType< $RelayProps, RelayRefetchProp>, >;