Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/react-relay/relay-hooks/EntryPointTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import type {
IEnvironment,
Observable,
OperationType,
PreloadableConcreteRequest,
RequestParameters,
VariablesOf as _VariablesOf,
} from 'relay-runtime';

export type {PreloadableConcreteRequest};

export type VariablesOf<T> = _VariablesOf<T>;

export type PreloadFetchPolicy =
Expand All @@ -46,17 +49,6 @@ export type LoadQueryOptions = {
readonly __nameForWarning?: ?string,
};

export type PreloadableConcreteRequest<out TQuery extends OperationType> = {
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<T>
readonly __phantom__?: ?TQuery,
};

export type EnvironmentProviderOptions = {readonly [string]: unknown, ...};

export type PreloadedQuery<
Expand Down
1 change: 1 addition & 0 deletions packages/relay-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export type {
ClientRequest,
ConcreteUpdatableQuery,
GeneratedNode,
PreloadableConcreteRequest,
RequestParameters,
} from './util/RelayConcreteNode';
export type {
Expand Down
24 changes: 24 additions & 0 deletions packages/relay-runtime/util/RelayConcreteNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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<out TQuery extends OperationType> = {
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<T>
readonly __phantom__?: ?TQuery,
};

export type NormalizationRootNode =
ConcreteRequest | NormalizationSplitOperation;

Expand Down