Skip to content

Commit

Permalink
Make LiveState and suspenseSentinel top level exports of Relay
Browse files Browse the repository at this point in the history
Reviewed By: voideanvalue

Differential Revision: D51287170

fbshipit-source-id: a08b0091b68c084f89da281630b854867a09aebf
  • Loading branch information
captbaritone authored and facebook-github-bot committed Nov 14, 2023
1 parent 59f5d60 commit 400090b
Show file tree
Hide file tree
Showing 31 changed files with 67 additions and 68 deletions.
5 changes: 5 additions & 0 deletions packages/relay-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const {
} = require('./store/ClientID');
const createFragmentSpecResolver = require('./store/createFragmentSpecResolver');
const createRelayContext = require('./store/createRelayContext');
const {
suspenseSentinel,
} = require('./store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const isRelayModernEnvironment = require('./store/isRelayModernEnvironment');
const normalizeResponse = require('./store/normalizeResponse');
const readInlineData = require('./store/readInlineData');
Expand Down Expand Up @@ -162,6 +165,7 @@ export type {
StoreUpdater,
UpdatableData,
TaskScheduler,
LiveState,
} from './store/RelayStoreTypes';
export type {
GraphQLSubscriptionConfig,
Expand Down Expand Up @@ -300,6 +304,7 @@ module.exports = {
graphql: GraphQLTag.graphql,
isFragment: GraphQLTag.isFragment,
isInlineDataFragment: GraphQLTag.isInlineDataFragment,
suspenseSentinel,
isRequest: GraphQLTag.isRequest,
readInlineData,

Expand Down
22 changes: 22 additions & 0 deletions packages/relay-runtime/store/RelayStoreTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,3 +1290,25 @@ export interface PublishQueue {
export type ConcreteClientEdgeResolverReturnType<T = any> = {
+id: T & DataID,
};

/**
* The return type of a Live Resolver. Models an external value which can
* be read lazily and which might change over time. The subscribe method
* returns a callback which should be called when the value _may_ have changed.
*
* While over-notification (subscription notifications when the read value has
* not actually changed) is suported, for performance reasons, it is recommended
* that the provider of the LiveState value confirms that the value has indeed
* change before notifying Relay of the change.
*/
export type LiveState<+T> = {
/**
* Returns the current value of the live state.
*/
read(): T,
/**
* Subscribes to changes in the live state. The state provider should
* call the callback when the value of the live state changes.
*/
subscribe(cb: () => void): () => void,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
'use strict';

import type {CounterSuspendsWhenOdd$key} from './__generated__/CounterSuspendsWhenOdd.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {graphql} = require('relay-runtime');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {graphql, suspenseSentinel} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

'use strict';

import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {suspenseSentinel} = require('relay-runtime');

/**
* @RelayResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

import type {InnerResolver$key} from './__generated__/InnerResolver.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {graphql} = require('relay-runtime');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

import type {ConcreteClientEdgeResolverReturnType} from 'relay-runtime';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

/**
* @RelayResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

'use strict';

import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

'use strict';

import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

import type {LiveCounterResolver$key} from './__generated__/LiveCounterResolver.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {graphql} = require('relay-runtime');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

import type {LiveCounterWithPossibleMissingFragmentDataResolverFragment$key} from './__generated__/LiveCounterWithPossibleMissingFragmentDataResolverFragment.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {graphql} = require('relay-runtime');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
'use strict';

import type {LiveExternalGreetingFragment$key} from './__generated__/LiveExternalGreetingFragment.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {graphql} = require('relay-runtime');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {graphql, suspenseSentinel} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

import type {LivePingPongResolver$key} from './__generated__/LivePingPongResolver.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {graphql} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ import type {Snapshot} from '../../RelayStoreTypes';
const {
live_external_greeting: LiveExternalGreeting,
} = require('./LiveExternalGreeting');
const {RelayFeatureFlags} = require('relay-runtime');
const {RelayFeatureFlags, suspenseSentinel} = require('relay-runtime');
const RelayNetwork = require('relay-runtime/network/RelayNetwork');
const {graphql} = require('relay-runtime/query/GraphQLTag');
const {
GLOBAL_STORE,
resetStore,
} = require('relay-runtime/store/__tests__/resolvers/ExampleExternalStateStore');
const LiveResolverStore = require('relay-runtime/store/experimental-live-resolvers/LiveResolverStore');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const RelayModernEnvironment = require('relay-runtime/store/RelayModernEnvironment');
const {
createOperationDescriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
'use strict';

import type {ConcreteClientEdgeResolverReturnType} from 'relay-runtime';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {suspenseSentinel} = require('relay-runtime');

/**
* @RelayResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
'use strict';

import type {DataID} from 'relay-runtime';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {suspenseSentinel} = require('relay-runtime');

/**
* @RelayResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

'use strict';

import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

type Entity = {
name: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

'use strict';

import type {LiveState} from 'relay-runtime';

/**
* @RelayResolver
* @fieldName live_resolver_return_undefined
Expand All @@ -19,8 +21,6 @@
*
* A @live resolver that throws
*/
import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';

// $FlowFixMe - this resolver returns undefined, but should return LiveState
function live_resolver_return_undefined(): LiveState<$FlowFixMe> {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

'use strict';

import type {LiveState} from 'relay-runtime';

/**
* @RelayResolver
* @fieldName live_resolver_throws
Expand All @@ -19,8 +21,6 @@
*
* A @live resolver that throws
*/
import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';

function live_resolver_throws(): LiveState<null> {
throw new Error('What?');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

'use strict';

import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

'use strict';
import type {LiveState} from 'relay-runtime';

/**
* @RelayResolver
Expand All @@ -19,8 +20,6 @@
*
* A @live resolver that does not return a LiveObject
*/
import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';

function live_resolver_with_bad_return_value(): LiveState<string> {
// $FlowFixMe The purpose of this resolver is to test a bad return value.
return 'Oops!';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
*/

'use strict';

import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {
Selectors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

'use strict';
import type {LiveState} from 'relay-runtime';

/**
* @RelayResolver
Expand All @@ -18,8 +19,6 @@
*
* A non-@live resolver that returns a LiveObject
*/
import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';

function non_live_resolver_with_live_return_value(): LiveState<string> {
return {
read() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

'use strict';

import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';
import type {Query__todo$normalization as ReturnType} from './__generated__/Query__todo$normalization.graphql';
import type {LiveState} from 'relay-runtime';

const {
Selectors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

'use strict';

import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';
import type {Query__todos$normalization as ReturnType} from './__generated__/Query__todos$normalization.graphql';
import type {LiveState} from 'relay-runtime';

const {
Selectors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
'use strict';

import type {AstrologicalSignID} from './AstrologicalSignUtils';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {suspenseSentinel} = require('relay-runtime');

/**
* @RelayResolver Query.virgo_suspends_when_counter_is_odd: AstrologicalSign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

import type {ResolverThatThrows$key} from './__generated__/ResolverThatThrows.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {graphql} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');
Expand Down
7 changes: 2 additions & 5 deletions packages/relay-runtime/store/__tests__/resolvers/TodoModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ import type {TodoModelCapitalizedID$key} from './__generated__/TodoModelCapitali
import type {TodoModelCapitalizedIDLegacy$key} from './__generated__/TodoModelCapitalizedIDLegacy.graphql';
import type {TodoDescription} from './TodoDescription';
import type {ConcreteClientEdgeResolverReturnType} from 'relay-runtime';
import type {LiveState} from 'relay-runtime';
import type {TodoItem} from 'relay-runtime/store/__tests__/resolvers/ExampleTodoStore';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';

const {readFragment} = require('../../ResolverFragments');
const {createTodoDescription} = require('./TodoDescription');
const {graphql} = require('relay-runtime');
const {graphql, suspenseSentinel} = require('relay-runtime');
const {
Selectors,
TODO_STORE,
} = require('relay-runtime/store/__tests__/resolvers/ExampleTodoStore');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');

type TodoModelType = ?TodoItem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

'use strict';

import type {LiveState} from '../../experimental-live-resolvers/LiveResolverStore';
import type {TodoSelfResolverFragment$key} from './__generated__/TodoSelfResolverFragment.graphql';
import type {LiveState} from 'relay-runtime';
import type {TodoItem} from 'relay-runtime/store/__tests__/resolvers/ExampleTodoStore';

const {graphql} = require('relay-runtime');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
'use strict';

import type {UserProfilePictureUriSuspendsWhenTheCounterIsOdd$key} from './__generated__/UserProfilePictureUriSuspendsWhenTheCounterIsOdd.graphql';
import type {LiveState} from 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore';
import type {LiveState} from 'relay-runtime';

const {GLOBAL_STORE, Selectors} = require('./ExampleExternalStateStore');
const {graphql} = require('relay-runtime');
const {
suspenseSentinel,
} = require('relay-runtime/store/experimental-live-resolvers/LiveResolverSuspenseSentinel');
const {graphql, suspenseSentinel} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');

/**
Expand Down
Loading

0 comments on commit 400090b

Please sign in to comment.