diff --git a/packages/react-relay/relay-hooks/EntryPointTypes.flow.js b/packages/react-relay/relay-hooks/EntryPointTypes.flow.js index 5df282d16aec..8f0f1c92657c 100644 --- a/packages/react-relay/relay-hooks/EntryPointTypes.flow.js +++ b/packages/react-relay/relay-hooks/EntryPointTypes.flow.js @@ -22,10 +22,13 @@ import type { IEnvironment, Observable, OperationType, + PreloadableConcreteRequest, RequestParameters, VariablesOf as _VariablesOf, } from 'relay-runtime'; +export type {PreloadableConcreteRequest}; + export type VariablesOf = _VariablesOf; export type PreloadFetchPolicy = @@ -46,17 +49,6 @@ export type LoadQueryOptions = { readonly __nameForWarning?: ?string, }; -export type PreloadableConcreteRequest = { - kind: 'PreloadableConcreteRequest', - params: RequestParameters, - // Note: the phantom type parameter here helps ensures that the - // $Parameters.js value matches the type param provided to preloadQuery. - // We also need to add usage of this generic here, - // becuase not using the generic in the definition makes it - // unconstrained in the call to a function that accepts PreloadableConcreteRequest - readonly __phantom__?: ?TQuery, -}; - export type EnvironmentProviderOptions = {readonly [string]: unknown, ...}; export type PreloadedQuery< diff --git a/packages/relay-runtime/index.js b/packages/relay-runtime/index.js index 196eb3c4b144..a485e966eff7 100644 --- a/packages/relay-runtime/index.js +++ b/packages/relay-runtime/index.js @@ -223,6 +223,7 @@ export type { ClientRequest, ConcreteUpdatableQuery, GeneratedNode, + PreloadableConcreteRequest, RequestParameters, } from './util/RelayConcreteNode'; export type { diff --git a/packages/relay-runtime/util/RelayConcreteNode.js b/packages/relay-runtime/util/RelayConcreteNode.js index 6790a951eb5e..542479de7184 100644 --- a/packages/relay-runtime/util/RelayConcreteNode.js +++ b/packages/relay-runtime/util/RelayConcreteNode.js @@ -16,6 +16,7 @@ import type { NormalizationSplitOperation, } from './NormalizationNode'; import type {ReaderFragment, ReaderInlineDataFragment} from './ReaderNode'; +import type {OperationType} from './RelayRuntimeTypes'; /** * Represents a common GraphQL request that can be executed, an `operation` @@ -35,6 +36,29 @@ export type ConcreteUpdatableQuery = { readonly fragment: ReaderFragment, }; +/** + * A lightweight stand-in for a `ConcreteRequest` emitted by the compiler for + * `@preloadable` queries: a `$Parameters.js` artifact containing only the + * `RequestParameters` (e.g. the persisted query `id`), so that the full + * normalization/reader AST can be code-split away from eager query loaders. + * + * This mirrors the type already published in the TypeScript declarations + * (`RelayConcreteNode.d.ts`) and re-exported from `relay-runtime`'s + * `index.d.ts`; the Flow definition previously only lived in `react-relay` + * (`EntryPointTypes.flow.js`), so Flow consumers could not import it from + * `relay-runtime` the way TypeScript consumers can. + */ +export type PreloadableConcreteRequest = { + kind: 'PreloadableConcreteRequest', + params: RequestParameters, + // Note: the phantom type parameter here helps ensures that the + // $Parameters.js value matches the type param provided to preloadQuery. + // We also need to add usage of this generic here, + // becuase not using the generic in the definition makes it + // unconstrained in the call to a function that accepts PreloadableConcreteRequest + readonly __phantom__?: ?TQuery, +}; + export type NormalizationRootNode = ConcreteRequest | NormalizationSplitOperation;