-
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.
Fix suspense for client-only fragments that contains suspensible live…
… resolvers Reviewed By: rbalicki2 Differential Revision: D39219336 fbshipit-source-id: 2d23cfc2b8141f901a0e48af38f31600927d8222
- Loading branch information
1 parent
cdbacef
commit 68b6846
Showing
5 changed files
with
338 additions
and
2 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
69 changes: 69 additions & 0 deletions
69
packages/react-relay/__tests__/__generated__/LiveResolversTestCounterUserFragment.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
146 changes: 146 additions & 0 deletions
146
...react-relay/__tests__/__generated__/LiveResolversTestLiveResolverSuspenseQuery.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
48 changes: 48 additions & 0 deletions
48
packages/relay-runtime/store/__tests__/resolvers/CounterSuspendsWhenOddOnUser.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,48 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow strict-local | ||
* @emails oncall+relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore'; | ||
|
||
const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore'); | ||
const { | ||
suspenseSentinel, | ||
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel'); | ||
|
||
/** | ||
* @RelayResolver | ||
* @fieldName counter_suspends_when_odd | ||
* @onType User | ||
* @live | ||
* | ||
* A Relay Resolver that returns an object implementing the External State | ||
* Resolver interface. | ||
*/ | ||
function CounterSuspendsWhenOddOnUser(): LiveState<number> { | ||
return { | ||
read() { | ||
const number = Selectors.getNumber(GLOBAL_STORE.getState()); | ||
if (number % 2 !== 0) { | ||
return suspenseSentinel(); | ||
} else { | ||
return number; | ||
} | ||
}, | ||
subscribe(cb): () => void { | ||
// Here we could try to run the selector and short-circuit if | ||
// the value has not changed, but for now we'll over-notify. | ||
return GLOBAL_STORE.subscribe(cb); | ||
}, | ||
}; | ||
} | ||
|
||
module.exports = CounterSuspendsWhenOddOnUser; |