Skip to content

Commit

Permalink
Expose hooks utils from relay-runtime
Browse files Browse the repository at this point in the history
Reviewed By: poteto

Differential Revision: D29163249

fbshipit-source-id: 488c9171a80b705adc7ed8b6b01ede2371ecf8e4
  • Loading branch information
Juan Tejada authored and facebook-github-bot committed Jun 16, 2021
1 parent f4ddbf6 commit 3b6f70d
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/react-relay/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type {
MatchPointer,
} from './relay-hooks/MatchContainer';
export type {ProfilerContextType} from './relay-hooks/ProfilerContext';
export type {Direction, LoadMoreFn} from './relay-hooks/useLoadMoreFunction';
export type {LoadMoreFn} from './relay-hooks/useLoadMoreFunction';
export type {UseMutationConfig} from './relay-hooks/useMutation';
export type {UseQueryLoaderLoadQueryOptions} from './relay-hooks/useQueryLoader';
export type {
Expand All @@ -48,6 +48,7 @@ export type {
export type {
DataID,
DeclarativeMutationConfig,
Direction,
Disposable,
// RelayRuntime has two environment exports: one interface, one concrete.
IEnvironment as Environment,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-relay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type {
MatchPointer,
} from './relay-hooks/MatchContainer';
export type {ProfilerContextType} from './relay-hooks/ProfilerContext';
export type {Direction, LoadMoreFn} from './relay-hooks/useLoadMoreFunction';
export type {LoadMoreFn} from './relay-hooks/useLoadMoreFunction';
export type {UseMutationConfig} from './relay-hooks/useMutation';
export type {UseQueryLoaderLoadQueryOptions} from './relay-hooks/useQueryLoader';
export type {
Expand All @@ -64,6 +64,7 @@ export type {
export type {
DataID,
DeclarativeMutationConfig,
Direction,
Disposable,
// RelayRuntime has two environment exports: one interface, one concrete.
IEnvironment as Environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
const React = require('react');
const Scheduler = require('scheduler');

import type {Direction} from '../useLoadMoreFunction';
import type {OperationDescriptor, Variables} from 'relay-runtime';
import type {Direction, OperationDescriptor, Variables} from 'relay-runtime';
const {useMemo, useState} = React;
const TestRenderer = require('react-test-renderer');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
const React = require('react');
const Scheduler = require('scheduler');

import type {Direction} from '../useLoadMoreFunction';
import type {OperationDescriptor, Variables} from 'relay-runtime';
import type {Direction, OperationDescriptor, Variables} from 'relay-runtime';
const {useEffect, useTransition, useMemo, useState} = React;
const TestRenderer = require('react-test-renderer');

Expand All @@ -38,7 +37,7 @@ const {
const {createMockEnvironment} = require('relay-test-utils');

describe('useBlockingPaginationFragment with useTransition', () => {
if (typeof React.useTransition !== 'function') {
if (typeof useTransition !== 'function') {
it('empty test to prevent Jest from failing', () => {
// This suite is only useful with experimental React build
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

const React = require('react');

import type {Direction} from '../useLoadMoreFunction';
import type {OperationDescriptor, Variables} from 'relay-runtime';
import type {Direction, OperationDescriptor, Variables} from 'relay-runtime';
const {useMemo, useState} = React;
const TestRenderer = require('react-test-renderer');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

'use strict';

const getPaginationMetadata = require('./getPaginationMetadata');
const invariant = require('invariant');
const useLoadMoreFunction = require('./useLoadMoreFunction');
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');

const {useCallback, useEffect, useRef, useState} = require('react');
const {getFragment, getFragmentIdentifier} = require('relay-runtime');
const {
getFragment,
getFragmentIdentifier,
getPaginationMetadata,
} = require('relay-runtime');

import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
Expand Down
7 changes: 3 additions & 4 deletions packages/react-relay/relay-hooks/useLoadMoreFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

'use strict';

const getPaginationVariables = require('./getPaginationVariables');
const getValueAtPath = require('./getValueAtPath');
const invariant = require('invariant');
const useFetchTrackingRef = require('./useFetchTrackingRef');
const useIsMountedRef = require('./useIsMountedRef');
Expand All @@ -27,11 +25,14 @@ const {
ConnectionInterface,
__internal: {fetchQuery},
createOperationDescriptor,
getPaginationVariables,
getValueAtPath,
getSelector,
} = require('relay-runtime');

import type {
ConcreteRequest,
Direction,
Disposable,
GraphQLResponse,
Observer,
Expand All @@ -41,8 +42,6 @@ import type {
VariablesOf,
} from 'relay-runtime';

export type Direction = 'forward' | 'backward';

export type LoadMoreFn<TQuery: OperationType> = (
count: number,
options?: {|
Expand Down
7 changes: 5 additions & 2 deletions packages/react-relay/relay-hooks/usePaginationFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

'use strict';

const getPaginationMetadata = require('./getPaginationMetadata');
const useLoadMoreFunction = require('./useLoadMoreFunction');
const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');

const {useCallback, useDebugValue, useState} = require('react');
const {getFragment, getFragmentIdentifier} = require('relay-runtime');
const {
getFragment,
getFragmentIdentifier,
getPaginationMetadata,
} = require('relay-runtime');

import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

const ProfilerContext = require('./ProfilerContext');

const getRefetchMetadata = require('./getRefetchMetadata');
const getValueAtPath = require('./getValueAtPath');
const invariant = require('invariant');
const useFragmentNode = require('./useFragmentNode');
const useIsMountedRef = require('./useIsMountedRef');
Expand All @@ -31,7 +29,9 @@ const {
__internal: {fetchQuery},
createOperationDescriptor,
getFragmentIdentifier,
getRefetchMetadata,
getSelector,
getValueAtPath,
} = require('relay-runtime');

import type {LoaderFn} from './useQueryLoader';
Expand Down
9 changes: 9 additions & 0 deletions packages/relay-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ const fetchQuery = require('./query/fetchQuery');
const fetchQueryInternal = require('./query/fetchQueryInternal');
const fetchQuery_DEPRECATED = require('./query/fetchQuery_DEPRECATED');
const getFragmentIdentifier = require('./util/getFragmentIdentifier');
const getPaginationMetadata = require('./util/getPaginationMetadata');
const getPaginationVariables = require('./util/getPaginationVariables');
const getRefetchMetadata = require('./util/getRefetchMetadata');
const getRelayHandleKey = require('./util/getRelayHandleKey');
const getRequestIdentifier = require('./util/getRequestIdentifier');
const getValueAtPath = require('./util/getValueAtPath');
const isPromise = require('./util/isPromise');
const isRelayModernEnvironment = require('./store/isRelayModernEnvironment');
const isScalarAndEqual = require('./util/isScalarAndEqual');
Expand Down Expand Up @@ -211,6 +215,7 @@ export type {
VariablesOf,
} from './util/RelayRuntimeTypes';
export type {Local3DPayload} from './util/createPayloadFor3DField';
export type {Direction} from './util/getPaginationVariables';
export type {RequestIdentifier} from './util/getRequestIdentifier';

// As early as possible, check for the existence of the JavaScript globals which
Expand Down Expand Up @@ -333,6 +338,10 @@ module.exports = {
recycleNodesInto: recycleNodesInto,
stableCopy: stableCopy,
getFragmentIdentifier: getFragmentIdentifier,
getRefetchMetadata: getRefetchMetadata,
getPaginationMetadata: getPaginationMetadata,
getPaginationVariables: getPaginationVariables,
getValueAtPath: getValueAtPath,
__internal: {
OperationTracker: RelayOperationTracker,
createRelayContext: createRelayContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
const invariant = require('invariant');
const warning = require('warning');

import type {Direction} from './useLoadMoreFunction';
import type {ReaderPaginationMetadata, Variables} from 'relay-runtime';
import type {ReaderPaginationMetadata} from './ReaderNode';
import type {Variables} from './RelayRuntimeTypes';

export type Direction = 'forward' | 'backward';

function getPaginationVariables(
direction: Direction,
Expand Down

0 comments on commit 3b6f70d

Please sign in to comment.