From 0ffb76bae879d3004a29b3422c978805687db640 Mon Sep 17 00:00:00 2001 From: Keegan Mendonca Date: Thu, 1 Dec 2022 14:22:32 -0800 Subject: [PATCH] Revert D41603109: Manually add annotations in xplat to prepare for LTI Differential Revision: D41603109 (https://github.com/facebook/relay/commit/0ff0fae425529d664d5e6015107b2c0cbba734c7) Original commit changeset: 800b2e701d33 Original Phabricator Diff: D41603109 (https://github.com/facebook/relay/commit/0ff0fae425529d664d5e6015107b2c0cbba734c7) fbshipit-source-id: c63979864304d2ac15c2f00ffd3189e9f0e702ff --- .../loadQuery-store-behavior-test.js | 118 ++++++------------ .../__tests__/useLazyLoadQueryNode-test.js | 2 +- .../useSubscribeToInvalidationState-test.js | 12 +- 3 files changed, 45 insertions(+), 87 deletions(-) diff --git a/packages/react-relay/relay-hooks/__tests__/loadQuery-store-behavior-test.js b/packages/react-relay/relay-hooks/__tests__/loadQuery-store-behavior-test.js index c0fdc7c41cbe5..a956661884e26 100644 --- a/packages/react-relay/relay-hooks/__tests__/loadQuery-store-behavior-test.js +++ b/packages/react-relay/relay-hooks/__tests__/loadQuery-store-behavior-test.js @@ -15,9 +15,7 @@ import type { loadQueryStoreBehaviorTestQuery$data, loadQueryStoreBehaviorTestQuery$variables, } from './__generated__/loadQueryStoreBehaviorTestQuery.graphql'; -import type {Sink} from 'relay-runtime/network/RelayObservable'; -import type {GraphQLSingularResponse} from 'relay-runtime/network/RelayNetworkTypes'; -import type {Query, OperationType} from 'relay-runtime/util/RelayRuntimeTypes'; +import type {Query} from 'relay-runtime/util/RelayRuntimeTypes'; const {loadQuery} = require('../loadQuery'); const { @@ -54,7 +52,7 @@ const preloadableConcreteRequest = { params: query.params, }; -const response: GraphQLSingularResponse = { +const response = { data: { node: { __typename: 'User', @@ -67,7 +65,7 @@ const response: GraphQLSingularResponse = { }, }; -const updatedResponse: GraphQLSingularResponse = { +const updatedResponse = { data: { node: { __typename: 'User', @@ -94,16 +92,12 @@ let writeDataToStore; beforeEach(() => { operation = createOperationDescriptor(query, variables); - fetch = jest.fn( - (_query, _variables, _cacheConfig, _uploadables, _logRequestInfo) => { - const observableCreate = Observable.create( - (_sink: Sink) => { - sink = _sink; - }, - ); - return observableCreate; - }, - ); + fetch = jest.fn((_query, _variables, _cacheConfig) => { + const observableCreate = Observable.create(_sink => { + sink = _sink; + }); + return observableCreate; + }); environment = createMockEnvironment({network: Network.create(fetch)}); store = environment.getStore(); @@ -116,11 +110,7 @@ beforeEach(() => { .mockImplementation(() => resolvedModule); writeDataToStore = () => { - loadQuery( - environment, - preloadableConcreteRequest, - variables, - ); + loadQuery(environment, preloadableConcreteRequest, variables); sink.next(response); sink.complete(); PreloadableQueryRegistry.set(ID, query); @@ -143,11 +133,7 @@ describe('when passed a PreloadableConcreteRequest', () => { }); it('should write the data to the store after the query AST and network response are available', () => { expect(store.check(operation).status).toBe('missing'); - loadQuery( - environment, - preloadableConcreteRequest, - variables, - ); + loadQuery(environment, preloadableConcreteRequest, variables); expect(fetch).toHaveBeenCalled(); expect(store.check(operation).status).toBe('missing'); PreloadableQueryRegistry.set(ID, query); @@ -158,11 +144,7 @@ describe('when passed a PreloadableConcreteRequest', () => { it('should write the data to the store after the network response and query AST are available', () => { expect(store.check(operation).status).toBe('missing'); - loadQuery( - environment, - preloadableConcreteRequest, - variables, - ); + loadQuery(environment, preloadableConcreteRequest, variables); expect(store.check(operation).status).toBe('missing'); sink.next(response); expect(store.check(operation).status).toBe('missing'); @@ -172,7 +154,7 @@ describe('when passed a PreloadableConcreteRequest', () => { it('should not write the data to the store if dispose is called before the query AST and network response are available', () => { expect(store.check(operation).status).toBe('missing'); - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -186,7 +168,7 @@ describe('when passed a PreloadableConcreteRequest', () => { it('should not write the data to the store if dispose is called before the network response and query AST are available', () => { expect(store.check(operation).status).toBe('missing'); - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -200,7 +182,7 @@ describe('when passed a PreloadableConcreteRequest', () => { it('should not write the data to the store if dispose is called after the query AST is available, but before the network response is available', () => { expect(store.check(operation).status).toBe('missing'); - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -214,7 +196,7 @@ describe('when passed a PreloadableConcreteRequest', () => { it('should not write the data to the store if dispose is called after the network response is available, but before the query AST is available', () => { expect(store.check(operation).status).toBe('missing'); - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -230,18 +212,14 @@ describe('when passed a PreloadableConcreteRequest', () => { describe('when the query AST is available synchronously', () => { it('should write data to the store when the network response is available', () => { expect(store.check(operation).status).toBe('missing'); - loadQuery( - environment, - preloadableConcreteRequest, - variables, - ); + loadQuery(environment, preloadableConcreteRequest, variables); sink.next(response); expect(store.check(operation).status).toBe('available'); }); it('should not write data to the store if dispose is called before the network response is available', () => { expect(store.check(operation).status).toBe('missing'); - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -257,14 +235,9 @@ describe('when passed a PreloadableConcreteRequest', () => { beforeEach(() => writeDataToStore()); describe('when the query AST is available synchronously', () => { it('should write updated data to the store when the network response is available', () => { - loadQuery( - environment, - preloadableConcreteRequest, - variables, - { - fetchPolicy: 'network-only', - }, - ); + loadQuery(environment, preloadableConcreteRequest, variables, { + fetchPolicy: 'network-only', + }); expect( (store.lookup(operation.fragment): $FlowFixMe)?.data?.node?.name, @@ -276,7 +249,7 @@ describe('when passed a PreloadableConcreteRequest', () => { }); it('should not write updated data to the store if dispose is called before the network response is available', () => { - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -297,14 +270,9 @@ describe('when passed a PreloadableConcreteRequest', () => { resolvedModule = undefined; }); it('should write updated data to the store when the network response and query AST are available', () => { - loadQuery( - environment, - preloadableConcreteRequest, - variables, - { - fetchPolicy: 'network-only', - }, - ); + loadQuery(environment, preloadableConcreteRequest, variables, { + fetchPolicy: 'network-only', + }); expect( (store.lookup(operation.fragment): $FlowFixMe)?.data?.node?.name, @@ -320,14 +288,9 @@ describe('when passed a PreloadableConcreteRequest', () => { ).toEqual('Mark'); }); it('should write updated data to the store when the query AST and network response are available', () => { - loadQuery( - environment, - preloadableConcreteRequest, - variables, - { - fetchPolicy: 'network-only', - }, - ); + loadQuery(environment, preloadableConcreteRequest, variables, { + fetchPolicy: 'network-only', + }); expect( (store.lookup(operation.fragment): $FlowFixMe)?.data?.node?.name, @@ -344,7 +307,7 @@ describe('when passed a PreloadableConcreteRequest', () => { }); it('should not write updated data to the store if dispose is called before the network response and query AST are available', () => { - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -365,7 +328,7 @@ describe('when passed a PreloadableConcreteRequest', () => { }); it('should not write updated data to the store if dispose is called before the query AST and network response are available', () => { - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -386,7 +349,7 @@ describe('when passed a PreloadableConcreteRequest', () => { }); it('should not write updated data to the store if dispose is called after the query AST is available and before the network response is available', () => { - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -410,7 +373,7 @@ describe('when passed a PreloadableConcreteRequest', () => { }); it('should not write updated data to the store if dispose is called after ·the network repsonse is available and before the query AST is available', () => { - const {dispose} = loadQuery( + const {dispose} = loadQuery( environment, preloadableConcreteRequest, variables, @@ -440,14 +403,14 @@ describe('when passed a query AST', () => { describe('when data is unavailable in the store', () => { it('should write data to the store when the network response is available', () => { expect(store.check(operation).status).toBe('missing'); - loadQuery(environment, query, variables); + loadQuery(environment, query, variables); sink.next(response); expect(store.check(operation).status).toBe('available'); }); it('should not write data to the store if dispose is called before the network response is available', () => { expect(store.check(operation).status).toBe('missing'); - const {dispose} = loadQuery(environment, query, variables); + const {dispose} = loadQuery(environment, query, variables); dispose(); sink.next(response); expect(store.check(operation).status).toBe('missing'); @@ -456,7 +419,7 @@ describe('when passed a query AST', () => { describe("when data is available in the store, but the fetch policy is 'network-only'", () => { beforeEach(() => writeDataToStore()); it('should write updated data to the store when the network response is available', () => { - loadQuery(environment, query, variables, { + loadQuery(environment, query, variables, { fetchPolicy: 'network-only', }); @@ -470,14 +433,9 @@ describe('when passed a query AST', () => { }); it('should not write updated data to the store if dispose is called before the network response is available', () => { - const {dispose} = loadQuery( - environment, - query, - variables, - { - fetchPolicy: 'network-only', - }, - ); + const {dispose} = loadQuery(environment, query, variables, { + fetchPolicy: 'network-only', + }); dispose(); sink.next(updatedResponse); diff --git a/packages/react-relay/relay-hooks/__tests__/useLazyLoadQueryNode-test.js b/packages/react-relay/relay-hooks/__tests__/useLazyLoadQueryNode-test.js index 7f0c5433430c2..f1735dfa74fe2 100644 --- a/packages/react-relay/relay-hooks/__tests__/useLazyLoadQueryNode-test.js +++ b/packages/react-relay/relay-hooks/__tests__/useLazyLoadQueryNode-test.js @@ -51,7 +51,7 @@ const { const defaultFetchPolicy = 'network-only'; function expectToBeRendered( - renderFn: JestMockFn<$ReadOnlyArray, any>, + renderFn: JestMockFn, any>, readyState: ?SelectorData, ) { // Ensure useEffect is called before other timers diff --git a/packages/react-relay/relay-hooks/__tests__/useSubscribeToInvalidationState-test.js b/packages/react-relay/relay-hooks/__tests__/useSubscribeToInvalidationState-test.js index d885a39cd0bab..4b68a375b3604 100644 --- a/packages/react-relay/relay-hooks/__tests__/useSubscribeToInvalidationState-test.js +++ b/packages/react-relay/relay-hooks/__tests__/useSubscribeToInvalidationState-test.js @@ -71,8 +71,8 @@ beforeEach(() => { initialDataIDs, initialCallback, }: { - initialCallback: JestMockFn<$ReadOnlyArray, void>, - initialDataIDs: $ReadOnlyArray, + initialCallback: JestMockFn, void>, + initialDataIDs: Array, }) { const [dataIDs, _setDataIDs] = useState(initialDataIDs); const [cbState, _setCallback] = useState({callback: initialCallback}); @@ -91,8 +91,8 @@ beforeEach(() => { } function Container(props: { - callback: JestMockFn<$ReadOnlyArray, void>, - dataIDs: $ReadOnlyArray, + callback: JestMockFn, void>, + dataIDs: Array, environment: RelayMockEnvironment, }) { const [env, setEnv] = useState(props.environment); @@ -109,8 +109,8 @@ beforeEach(() => { render = ( env: RelayMockEnvironment, - dataIDs: $ReadOnlyArray, - cb: JestMockFn<$ReadOnlyArray, void>, + dataIDs: Array, + cb: JestMockFn, void>, ) => { ReactTestRenderer.act(() => { renderedInstance = ReactTestRenderer.create(