-
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.
Reviewed By: josephsavona Differential Revision: D46500160 fbshipit-source-id: 958d87878faa941bc790500362a4e52f5ca651a0
- Loading branch information
1 parent
161b5ec
commit fca7a9c
Showing
6 changed files
with
417 additions
and
21 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
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
46 changes: 46 additions & 0 deletions
46
packages/relay-runtime/store/__tests__/resolvers/QueryLiveResolverThrowsOnRead.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,46 @@ | ||
/** | ||
* 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 {LiveState} from '../../experimental-live-resolvers/LiveResolverStore'; | ||
|
||
const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore'); | ||
|
||
/** | ||
* @RelayResolver Query.counter_throws_when_odd: Int | ||
* @live | ||
* | ||
* A @live resolver that throws when counter is odd. Useful for testing | ||
* behavior of live resolvers that throw on read. | ||
*/ | ||
|
||
function counter_throws_when_odd(): LiveState<number> { | ||
return { | ||
read() { | ||
const number = Selectors.getNumber(GLOBAL_STORE.getState()); | ||
if (number % 2 !== 0) { | ||
throw new Error('What?'); | ||
} 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 = { | ||
counter_throws_when_odd, | ||
}; |
99 changes: 99 additions & 0 deletions
99
...ore/__tests__/resolvers/__generated__/LiveResolversTestHandlesErrorOnReadQuery.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.