Skip to content

Commit

Permalink
Introduce VariablesOf utility type
Browse files Browse the repository at this point in the history
Reviewed By: kassens

Differential Revision: D22165729

fbshipit-source-id: 740750ea7cffe7afd51feefa56a3a0e74bbb0294
  • Loading branch information
rbalicki2 authored and facebook-github-bot committed Jul 6, 2020
1 parent 61c8627 commit f1f784f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/relay-experimental/EntryPointTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import type {
Observable,
OperationType,
RequestParameters,
VariablesOf as _VariablesOf,
} from 'relay-runtime';

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

export type PreloadFetchPolicy =
| 'store-or-network'
| 'store-and-network'
Expand Down
3 changes: 2 additions & 1 deletion packages/relay-experimental/fetchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
IEnvironment,
OperationDescriptor,
OperationType,
VariablesOf,
} from 'relay-runtime';

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ import type {
function fetchQuery<TQuery: OperationType>(
environment: IEnvironment,
query: GraphQLTaggedNode,
variables: $ElementType<TQuery, 'variables'>,
variables: VariablesOf<TQuery>,
options?: $ReadOnly<{|
fetchPolicy?: FetchQueryFetchPolicy,
networkCacheConfig?: CacheConfig,
Expand Down
5 changes: 3 additions & 2 deletions packages/relay-experimental/preloadQuery_DEPRECATED.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
PreloadFetchPolicy,
PreloadOptions,
PreloadQueryStatus,
VariablesOf,
} from './EntryPointTypes.flow';
import type {
ConcreteRequest,
Expand Down Expand Up @@ -76,7 +77,7 @@ type PendingQueryEntry =
function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
environment: IEnvironment,
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
variables: $ElementType<TQuery, 'variables'>,
variables: VariablesOf<TQuery>,
options?: ?PreloadOptions,
environmentProviderOptions?: ?TEnvironmentProviderOptions,
): PreloadedQueryInner_DEPRECATED<TQuery, TEnvironmentProviderOptions> {
Expand Down Expand Up @@ -126,7 +127,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
environment: Environment,
pendingQueries: Map<string, PendingQueryEntry>,
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
variables: $ElementType<TQuery, 'variables'>,
variables: VariablesOf<TQuery>,
options: ?PreloadOptions,
): PendingQueryEntry {
let params;
Expand Down
3 changes: 2 additions & 1 deletion packages/relay-experimental/useLazyLoadQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import type {
GraphQLTaggedNode,
OperationType,
RenderPolicy,
VariablesOf,
} from 'relay-runtime';

function useLazyLoadQuery<TQuery: OperationType>(
gqlQuery: GraphQLTaggedNode,
variables: $ElementType<TQuery, 'variables'>,
variables: VariablesOf<TQuery>,
options?: {|
fetchKey?: string | number,
fetchPolicy?: FetchPolicy,
Expand Down
3 changes: 2 additions & 1 deletion packages/relay-experimental/useLoadMoreFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type {
OperationType,
ReaderFragment,
ReaderPaginationMetadata,
VariablesOf,
} from 'relay-runtime';

export type Direction = 'forward' | 'backward';
Expand All @@ -49,7 +50,7 @@ export type LoadMoreFn<TQuery: OperationType> = (
count: number,
options?: {|
onComplete?: (Error | null) => void,
UNSTABLE_extraVariables?: $Shape<$ElementType<TQuery, 'variables'>>,
UNSTABLE_extraVariables?: $Shape<VariablesOf<TQuery>>,
|},
) => Disposable;

Expand Down
5 changes: 3 additions & 2 deletions packages/relay-experimental/useRefetchableFragmentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import type {
ReaderFragment,
RenderPolicy,
Variables,
VariablesOf,
} from 'relay-runtime';

export type RefetchFn<
Expand Down Expand Up @@ -103,13 +104,13 @@ type RefetchFnBase<TVars, TOptions> = (
) => Disposable;

type RefetchFnExact<TQuery: OperationType, TOptions = Options> = RefetchFnBase<
$ElementType<TQuery, 'variables'>,
VariablesOf<TQuery>,
TOptions,
>;
type RefetchFnInexact<
TQuery: OperationType,
TOptions = Options,
> = RefetchFnBase<$Shape<$ElementType<TQuery, 'variables'>>, TOptions>;
> = RefetchFnBase<$Shape<VariablesOf<TQuery>>, TOptions>;

type Action =
| {|
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 @@ -189,6 +189,7 @@ export type {
OperationType,
RenderPolicy,
Variables,
VariablesOf,
} from './util/RelayRuntimeTypes';
export type {Local3DPayload} from './util/createPayloadFor3DField';

Expand Down
2 changes: 2 additions & 0 deletions packages/relay-runtime/util/RelayRuntimeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type OperationType = {|
+rawResponse?: {...},
|};

export type VariablesOf<T: OperationType> = $ElementType<T, 'variables'>;

/**
* Settings for how a query response may be cached.
*
Expand Down

0 comments on commit f1f784f

Please sign in to comment.