-
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.
Expose datachecker to the network layer
Reviewed By: lynnshaoyu Differential Revision: D69814081 fbshipit-source-id: b1203bf2aee0c06f9ecbb69596f12d5c997bceb1
- Loading branch information
1 parent
2e41a45
commit 7b68e1f
Showing
5 changed files
with
281 additions
and
4 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
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
97 changes: 97 additions & 0 deletions
97
packages/relay-runtime/store/__tests__/RelayModernEnvironment-ExecuteWithCheck-test.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,97 @@ | ||
/** | ||
* 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 {GraphQLResponse} from '../../network/RelayNetworkTypes'; | ||
|
||
const RelayObservable = require('../../network/RelayObservable'); | ||
const {graphql} = require('../../query/GraphQLTag'); | ||
const RelayModernEnvironment = require('../RelayModernEnvironment'); | ||
const { | ||
createOperationDescriptor, | ||
} = require('../RelayModernOperationDescriptor'); | ||
const RelayModernStore = require('../RelayModernStore'); | ||
const RelayRecordSource = require('../RelayRecordSource'); | ||
const {disallowWarnings} = require('relay-test-utils-internal'); | ||
|
||
disallowWarnings(); | ||
|
||
describe('execute() provides a `check` function for the network layer to determine availability of data in store', () => { | ||
let callbacks; | ||
let complete; | ||
let environment; | ||
let error; | ||
let next; | ||
let operation; | ||
let query; | ||
let source; | ||
let store; | ||
let subject; | ||
let variables; | ||
let network; | ||
let check; | ||
beforeEach(() => { | ||
query = graphql` | ||
query RelayModernEnvironmentExecuteWithCheckTestQuery( | ||
$fetchSize: Boolean! | ||
) { | ||
me { | ||
name | ||
profilePicture(size: 42) @include(if: $fetchSize) { | ||
uri | ||
} | ||
} | ||
} | ||
`; | ||
variables = {fetchSize: false}; | ||
operation = createOperationDescriptor(query, variables); | ||
|
||
complete = jest.fn<[], mixed>(); | ||
error = jest.fn<[Error], mixed>(); | ||
next = jest.fn<[GraphQLResponse], mixed>(); | ||
callbacks = {complete, error, next}; | ||
|
||
network = { | ||
execute: jest.fn( | ||
(_query, _variables, _cacheConfig, _1, _2, _3, _4, _check) => { | ||
check = _check; | ||
return RelayObservable.create(sink => { | ||
subject = sink; | ||
}); | ||
}, | ||
), | ||
}; | ||
source = RelayRecordSource.create(); | ||
store = new RelayModernStore(source); | ||
environment = new RelayModernEnvironment({ | ||
network, | ||
store, | ||
}); | ||
}); | ||
|
||
it('returns the correct availability in the check function', () => { | ||
environment.execute({operation}).subscribe(callbacks); | ||
expect(check().status).toBe('missing'); | ||
subject.next({ | ||
data: { | ||
me: { | ||
id: '842472', | ||
__typename: 'User', | ||
name: 'Joe', | ||
}, | ||
}, | ||
}); | ||
jest.runAllTimers(); | ||
|
||
environment.execute({operation}).subscribe(callbacks); | ||
expect(check().status).toBe('available'); | ||
}); | ||
}); |
154 changes: 154 additions & 0 deletions
154
.../store/__tests__/__generated__/RelayModernEnvironmentExecuteWithCheckTestQuery.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.