Skip to content

Commit

Permalink
update Relay's types to use $fragmentSpreads and $fragmentType
Browse files Browse the repository at this point in the history
Reviewed By: alunyov

Differential Revision: D32476625

fbshipit-source-id: a88b320de26ab4a1f6ccce1bff5145fcfb6bad08
  • Loading branch information
kassens authored and facebook-github-bot committed Nov 17, 2021
1 parent 9ceafd7 commit 0a487b6
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 66 deletions.
18 changes: 9 additions & 9 deletions packages/react-relay/ReactRelayTypes.js
Expand Up @@ -94,7 +94,7 @@ export type RefetchOptions = {|
*
*/
export type $FragmentRef<T> = {
+$fragmentRefs: T['$refType'],
+$fragmentSpreads: T['$fragmentType'],
...
};

Expand All @@ -105,14 +105,14 @@ export type $FragmentRef<T> = {
// prettier-ignore
export type $RelayProps<Props, RelayPropT = RelayProp> = $ObjMap<
$Diff<Props, { relay: RelayPropT | void, ... }>,
& (<T: { +$refType: empty, ... }>( T) => T)
& (<T: { +$refType: empty, ... }>(?T) => ?T)
& (<TFragmentType: FragmentType, T: { +$refType: TFragmentType, ... }>( T ) => $FragmentRef<T> )
& (<TFragmentType: FragmentType, T: { +$refType: TFragmentType, ... }>(? T ) => ? $FragmentRef<T> )
& (<TFragmentType: FragmentType, T: { +$refType: TFragmentType, ... }>( $ReadOnlyArray< T>) => $ReadOnlyArray< $FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$refType: TFragmentType, ... }>(?$ReadOnlyArray< T>) => ?$ReadOnlyArray< $FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$refType: TFragmentType, ... }>( $ReadOnlyArray<?T>) => $ReadOnlyArray<?$FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$refType: TFragmentType, ... }>(?$ReadOnlyArray<?T>) => ?$ReadOnlyArray<?$FragmentRef<T>>)
& (<T: { +$fragmentType: empty, ... }>( T) => T)
& (<T: { +$fragmentType: empty, ... }>(?T) => ?T)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( T ) => $FragmentRef<T> )
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(? T ) => ? $FragmentRef<T> )
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray< T>) => $ReadOnlyArray< $FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray< T>) => ?$ReadOnlyArray< $FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray<?T>) => $ReadOnlyArray<?$FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray<?T>) => ?$ReadOnlyArray<?$FragmentRef<T>>)
& (<T>(T) => T),
>;

Expand Down
10 changes: 5 additions & 5 deletions packages/react-relay/__flowtests__/RelayModern-flowtest.js
Expand Up @@ -128,22 +128,22 @@ const PluralTestFragment = createFragmentContainer(PluralTest, {
});

declare var aUserRef: {
+$fragmentRefs: RelayModernFlowtest_user$ref,
+$fragmentSpreads: RelayModernFlowtest_user$ref,
...
};

declare var oneOfUsersRef: {
+$fragmentRefs: RelayModernFlowtest_users$ref,
+$fragmentSpreads: RelayModernFlowtest_users$ref,
...
};

declare var usersRef: $ReadOnlyArray<{
+$fragmentRefs: RelayModernFlowtest_users$ref,
+$fragmentSpreads: RelayModernFlowtest_users$ref,
...
}>;

declare var nonUserRef: {
+$fragmentRefs: {thing: true, ...},
+$fragmentSpreads: {thing: true, ...},
...
};

Expand Down Expand Up @@ -210,7 +210,7 @@ function cb(): void {}
/>;

declare var aComplexUserRef: {
+$fragmentRefs: {thing1: true, ...} & RelayModernFlowtest_user$ref & {
+$fragmentSpreads: {thing1: true, ...} & RelayModernFlowtest_user$ref & {
thing2: true,
...
},
Expand Down
Expand Up @@ -13,11 +13,11 @@
'use strict';

import type {RelayModernFlowtest_user$ref} from './RelayModernFlowtest_user.graphql';
import type {FragmentReference} from 'relay-runtime';
import type {FragmentType} from 'relay-runtime';

declare export opaque type RelayModernFlowtest_badref$ref: FragmentReference;
declare export opaque type RelayModernFlowtest_badref$ref: FragmentType;
export type RelayModernFlowtest_badref = {|
+id: string,
+$fragmentRefs: RelayModernFlowtest_user$ref,
+$refType: RelayModernFlowtest_badref$ref,
+$fragmentSpreads: RelayModernFlowtest_user$ref,
+$fragmentType: RelayModernFlowtest_badref$ref,
|};
Expand Up @@ -13,11 +13,11 @@
'use strict';

import type {RelayModernFlowtest_user$ref} from './RelayModernFlowtest_user.graphql';
import type {FragmentReference} from 'relay-runtime';
import type {FragmentType} from 'relay-runtime';

declare export opaque type RelayModernFlowtest_notref$ref: FragmentReference;
declare export opaque type RelayModernFlowtest_notref$ref: FragmentType;
export type RelayModernFlowtest_notref = {|
+id: string,
+$fragmentRefs: RelayModernFlowtest_user$ref,
+$refType: RelayModernFlowtest_notref$ref,
+$fragmentSpreads: RelayModernFlowtest_user$ref,
+$fragmentType: RelayModernFlowtest_notref$ref,
|};
Expand Up @@ -12,10 +12,10 @@

'use strict';

import type {FragmentReference} from 'relay-runtime';
import type {FragmentType} from 'relay-runtime';

declare export opaque type RelayModernFlowtest_user$ref: FragmentReference;
declare export opaque type RelayModernFlowtest_user$ref: FragmentType;
export type RelayModernFlowtest_user = {|
+name: ?string,
+$refType: RelayModernFlowtest_user$ref,
+$fragmentType: RelayModernFlowtest_user$ref,
|};
Expand Up @@ -12,10 +12,10 @@

'use strict';

import type {FragmentReference} from 'relay-runtime';
import type {FragmentType} from 'relay-runtime';

declare export opaque type RelayModernFlowtest_users$ref: FragmentReference;
declare export opaque type RelayModernFlowtest_users$ref: FragmentType;
export type RelayModernFlowtest_users = $ReadOnlyArray<{|
+name: ?string,
+$refType: RelayModernFlowtest_users$ref,
+$fragmentType: RelayModernFlowtest_users$ref,
|}>;
4 changes: 2 additions & 2 deletions packages/react-relay/relay-hooks/MatchContainer.js
Expand Up @@ -91,7 +91,7 @@ type TypenameOnlyPointer = {|+__typename: string|};
export type MatchPointer = {
+__fragmentPropName?: ?string,
+__module_component?: mixed,
+$fragmentRefs: mixed,
+$fragmentSpreads: mixed,
...
};

Expand All @@ -116,7 +116,7 @@ function MatchContainer<TProps: {...}, TFallback: React.Node | null>({
'MatchContainer: Expected `match` value to be an object or null/undefined.',
);
}
// NOTE: the MatchPointer type has a $fragmentRefs field to ensure that only
// NOTE: the MatchPointer type has a $fragmentSpreads field to ensure that only
// an object that contains a FragmentSpread can be passed. If the fragment
// spread matches, then the metadata fields below (__id, __fragments, etc.)
// will be present. But they can be missing if all the fragment spreads use
Expand Down
20 changes: 8 additions & 12 deletions packages/react-relay/relay-hooks/__flowtests__/utils.js
Expand Up @@ -13,11 +13,7 @@

'use strict';

import type {
Disposable,
FragmentReference,
GraphQLTaggedNode,
} from 'relay-runtime';
import type {Disposable, FragmentType, GraphQLTaggedNode} from 'relay-runtime';

declare export var fragmentInput: GraphQLTaggedNode;

Expand All @@ -38,42 +34,42 @@ export type AnotherNonNullableData = {|

declare export var keyNonNullable: {
+$data?: NonNullableData,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
};

declare export var keyNonNullablePlural: $ReadOnlyArray<{
+$data?: NonNullablePluralData,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
}>;

declare export var keyNullablePlural: ?$ReadOnlyArray<{
+$data?: NonNullablePluralData,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
}>;

declare export var keyNullable: ?{
+$data?: NonNullableData,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
};

declare export var keyAnotherNonNullable: {
+$data: AnotherNonNullableData,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
};

declare export var keyAnotherNullable: ?{
+$data: AnotherNonNullableData,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
};

declare export var fragmentData: {
+$refType: FragmentReference,
+$fragmentType: FragmentType,
...
};

Expand Down
Expand Up @@ -28,7 +28,7 @@ function createMatchPointer({
module,
}): MatchPointer {
const pointer = {
$fragmentRefs: {},
$fragmentSpreads: {},
[ID_KEY]: id,
[FRAGMENTS_KEY]: {},
[FRAGMENT_OWNER_KEY]: null,
Expand Down
Expand Up @@ -43,6 +43,7 @@ describe('useRefetchableFragment', () => {
function useRefetchableFragment(fragmentNode, fragmentRef) {
const [data, refetch] = useRefetchableFragmentOriginal(
fragmentNode,
// $FlowFixMe[incompatible-call]
// $FlowFixMe[prop-missing]
fragmentRef,
);
Expand Down
Expand Up @@ -16,7 +16,7 @@
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
import type {
FragmentReference,
FragmentType,
GraphQLResponse,
GraphQLTaggedNode,
Observer,
Expand Down Expand Up @@ -45,7 +45,7 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|

function useBlockingPaginationFragment<
TQuery: OperationType,
TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
parentFragmentRef: TKey,
Expand Down
10 changes: 5 additions & 5 deletions packages/react-relay/relay-hooks/useFragment.js
Expand Up @@ -13,7 +13,7 @@

'use strict';

import type {FragmentReference, GraphQLTaggedNode} from 'relay-runtime';
import type {FragmentType, GraphQLTaggedNode} from 'relay-runtime';

const {useTrackLoadQueryInRender} = require('./loadQuery');
const useFragmentNode = require('./useFragmentNode');
Expand All @@ -29,14 +29,14 @@ const {getFragment} = require('relay-runtime');
// - array of nullable if the privoided ref type is an array of nullable refs

declare function useFragment<
TKey: {+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
TKey: {+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
fragmentRef: TKey,
): $Call<<TFragmentData>({+$data?: TFragmentData, ...}) => TFragmentData, TKey>;

declare function useFragment<
TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
fragmentRef: TKey,
Expand All @@ -48,7 +48,7 @@ declare function useFragment<
declare function useFragment<
TKey: $ReadOnlyArray<{
+$data?: mixed,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
}>,
>(
Expand All @@ -64,7 +64,7 @@ declare function useFragment<
declare function useFragment<
TKey: ?$ReadOnlyArray<{
+$data?: mixed,
+$fragmentRefs: FragmentReference,
+$fragmentSpreads: FragmentType,
...
}>,
>(
Expand Down
4 changes: 2 additions & 2 deletions packages/react-relay/relay-hooks/useIsParentQueryActive.js
Expand Up @@ -11,14 +11,14 @@

'use strict';

import type {FragmentReference, GraphQLTaggedNode} from 'relay-runtime';
import type {FragmentType, GraphQLTaggedNode} from 'relay-runtime';

const useIsOperationNodeActive = require('./useIsOperationNodeActive');
const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
const {getFragment} = require('relay-runtime');

function useIsParentQueryActive<
TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): boolean {
const fragmentNode = getFragment(fragmentInput);
useStaticFragmentNodeWarning(
Expand Down
4 changes: 2 additions & 2 deletions packages/react-relay/relay-hooks/usePaginationFragment.js
Expand Up @@ -16,7 +16,7 @@
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
import type {
FragmentReference,
FragmentType,
GraphQLResponse,
GraphQLTaggedNode,
Observer,
Expand Down Expand Up @@ -46,7 +46,7 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|

function usePaginationFragment<
TQuery: OperationType,
TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
parentFragmentRef: TKey,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-relay/relay-hooks/useRefetchableFragment.js
Expand Up @@ -15,7 +15,7 @@

import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
import type {
FragmentReference,
FragmentType,
GraphQLTaggedNode,
OperationType,
} from 'relay-runtime';
Expand All @@ -40,7 +40,7 @@ type ReturnType<TQuery: OperationType, TKey: ?{+$data?: mixed, ...}> = [

function useRefetchableFragment<
TQuery: OperationType,
TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
fragmentRef: TKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/relay-runtime/store/RelayStoreTypes.js
Expand Up @@ -805,7 +805,7 @@ export interface IEnvironment {
export type ModuleImportPointer = {
+__fragmentPropName: ?string,
+__module_component: mixed,
+$fragmentRefs: mixed,
+$fragmentSpreads: mixed,
...
};

Expand Down
8 changes: 4 additions & 4 deletions packages/relay-runtime/store/ResolverFragments.js
Expand Up @@ -47,14 +47,14 @@ function withResolverContext<T>(context: ResolverContext, cb: () => T): T {
// - array of nullable if the privoided ref type is an array of nullable refs

declare function readFragment<
TKey: {+$data?: mixed, +$fragmentRefs: FragmentType, ...},
TKey: {+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
fragmentKey: TKey,
): $Call<<TFragmentData>({+$data?: TFragmentData, ...}) => TFragmentData, TKey>;

declare function readFragment<
TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentType, ...},
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
>(
fragmentInput: GraphQLTaggedNode,
fragmentKey: TKey,
Expand All @@ -66,7 +66,7 @@ declare function readFragment<
declare function readFragment<
TKey: $ReadOnlyArray<{
+$data?: mixed,
+$fragmentRefs: FragmentType,
+$fragmentSpreads: FragmentType,
...
}>,
>(
Expand All @@ -82,7 +82,7 @@ declare function readFragment<
declare function readFragment<
TKey: ?$ReadOnlyArray<{
+$data?: mixed,
+$fragmentRefs: FragmentType,
+$fragmentSpreads: FragmentType,
...
}>,
>(
Expand Down

0 comments on commit 0a487b6

Please sign in to comment.