-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using opaque type trick to enforce nested relay entry point safety
Reviewed By: josephsavona Differential Revision: D45799755 fbshipit-source-id: c2e49731319e1250746e7cb858d49f56d9993ae7
- Loading branch information
1 parent
ce74006
commit de6594b
Showing
3 changed files
with
67 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/react-relay/relay-hooks/NestedRelayEntryPointBuilderUtils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { | ||
InternalEntryPointRepresentation, | ||
ThinNestedEntryPointParams, | ||
} from './EntryPointTypes.flow'; | ||
|
||
/** | ||
* This is an identity function to construct a type safe nested entrypoint. | ||
* By calling this function, we ensure that the type of entryPointParams matches | ||
* exactly the type of preloadProps of the entrypoint. | ||
* | ||
* We make the type of `ThinNestedEntryPointParams` opaque, so that the only way | ||
* to construct a `ThinNestedEntryPointParams` is by calling this function. | ||
*/ | ||
declare function NestedRelayEntryPoint< | ||
TEntryPointParams, | ||
TPreloadedQueries, | ||
TPreloadedEntryPoints, | ||
TRuntimeProps, | ||
TExtraProps, | ||
>( | ||
$ReadOnly<{ | ||
entryPoint: InternalEntryPointRepresentation< | ||
TEntryPointParams, | ||
TPreloadedQueries, | ||
TPreloadedEntryPoints, | ||
TRuntimeProps, | ||
TExtraProps, | ||
>, | ||
entryPointParams: TEntryPointParams, | ||
}>, | ||
): ThinNestedEntryPointParams; | ||
|
||
// eslint-disable-next-line no-redeclare | ||
function NestedRelayEntryPoint<P>(params: P): P { | ||
return params; | ||
} | ||
|
||
export {NestedRelayEntryPoint}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters