From 068231de36daefce9e14e7a3110e2eaf14ab3d08 Mon Sep 17 00:00:00 2001 From: voxmatt Date: Sun, 10 Sep 2017 09:47:01 -1000 Subject: [PATCH] working my way through relay-runtime linting errors --- types/relay-runtime/index.d.ts | 2234 ++++++++++++++++---------------- 1 file changed, 1117 insertions(+), 1117 deletions(-) diff --git a/types/relay-runtime/index.d.ts b/types/relay-runtime/index.d.ts index 5e86ed0681..80ea0dcdea 100644 --- a/types/relay-runtime/index.d.ts +++ b/types/relay-runtime/index.d.ts @@ -4,1129 +4,1129 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 -declare namespace __Relay.Common { - /** - * SOURCE: - * Relay 1.3.0 - * https://github.com/facebook/relay/blob/b85a1d69bb72be4ace67179f55c2a54a8d761c8b/packages/react-relay/classic/environment/RelayCombinedEnvironmentTypes.js - */ - // ~~~~~~~~~~~~~~~~~~~~~ - // Util - // ~~~~~~~~~~~~~~~~~~~~~ - type Maybe = T | void; +declare namespace __Relay { + namespace Common { - // ~~~~~~~~~~~~~~~~~~~~~ - // Maybe Fix - // ~~~~~~~~~~~~~~~~~~~~~ - type RelayConcreteNode = any; - type RelayMutationTransaction = any; - type RelayMutationRequest = any; - type RelayQueryRequest = any; - type ConcreteFragment = any; - type ConcreteBatch = any; - type ConcreteFragmentDefinition = object; - type ConcreteOperationDefinition = object; - - - /** - * FIXME: RelayContainer used to be typed with ReactClass, but - * ReactClass is broken and allows for access to any property. For example - * ReactClass.getFragment('foo') is valid even though ReactClass has no - * such getFragment() type definition. When ReactClass is fixed this causes a - * lot of errors in Relay code since methods like getFragment() are used often - * but have no definition in Relay's types. Suppressing for now. - */ - export type RelayContainer = any; - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayQL - // ~~~~~~~~~~~~~~~~~~~~~ - type RelayQL = ( - strings: Array, - ...substitutions: Array - ) => Common.RelayConcreteNode; - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayModernGraphQLTag - // ~~~~~~~~~~~~~~~~~~~~~ - type GeneratedNodeMap = {[key: string]: GraphQLTaggedNode}; - type GraphQLTaggedNode = - (() => ConcreteFragment | ConcreteBatch) | - { - modern: () => ConcreteFragment | ConcreteBatch, - classic: (relayQL: RelayQL) => - | ConcreteFragmentDefinition - | ConcreteOperationDefinition, - }; - // ~~~~~~~~~~~~~~~~~~~~~ - // General Usage - // ~~~~~~~~~~~~~~~~~~~~~ - export type DataID = string; - export type Variables = {[name: string]: any}; - export type Uploadable = File | Blob; - export type UploadableMap = {[key: string]: Uploadable}; - - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayNetworkTypes - // Version: Relay 1.3.0 - // File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayNetworkTypes.js - // ~~~~~~~~~~~~~~~~~~~~~ - - export type LegacyObserver = { - onCompleted?: (() => void) | void, - onError?: ((error: Error) => void) | void, - onNext?: ((data: T) => void) | void, - }; - export type PayloadError = { - message: string, - locations?: Array<{ - line: number, - column: number, - }>, - }; - /** - * A function that executes a GraphQL operation with request/response semantics. - * - * May return an Observable or Promise of a raw server response. - */ - export function FetchFunction( - operation: ConcreteBatch, - variables: Variables, - cacheConfig: CacheConfig, - uploadables?: Common.UploadableMap, - ): Runtime.ObservableFromValue; - - /** - * A function that executes a GraphQL subscription operation, returning one or - * more raw server responses over time. - * - * May return an Observable, otherwise must call the callbacks found in the - * fourth parameter. - */ - export type SubscribeFunction = ( - operation: ConcreteBatch, - variables: Variables, - cacheConfig: CacheConfig, - observer: LegacyObserver, - ) => Runtime.RelayObservable | Disposable; - - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayStoreTypes - // Version: Relay 1.3.0 - // File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/store/RelayStoreTypes.js - // ~~~~~~~~~~~~~~~~~~~~~ - /** - * A function that receives a proxy over the store and may trigger side-effects - * (indirectly) by calling `set*` methods on the store or its record proxies. - */ - export type StoreUpdater = (store: RecordSourceProxy) => void; - - /** - * Similar to StoreUpdater, but accepts a proxy tied to a specific selector in - * order to easily access the root fields of a query/mutation as well as a - * second argument of the response object of the mutation. - */ - export type SelectorStoreUpdater = ( - store: RecordSourceSelectorProxy, - // Actually RelayCombinedEnvironmentTypes#SelectorData, but mixed is - // inconvenient to access deeply in product code. - data: any, // FLOW FIXME - ) => void; - - /** - * Extends the RecordSourceProxy interface with methods for accessing the root - * fields of a Selector. - */ - export interface RecordSourceSelectorProxy { - create(dataID: DataID, typeName: string): RecordProxy, - delete(dataID: DataID): void, - get(dataID: DataID): RecordProxy | void, - getRoot(): RecordProxy, - getRootField(fieldName: string): RecordProxy | void, - getPluralRootField(fieldName: string): RecordProxy[] | void, - } - - export interface RecordProxy { - copyFieldsFrom(source: RecordProxy): void, - getDataID(): DataID, - getLinkedRecord(name: string, args?: Variables | void): RecordProxy | void, - getLinkedRecords(name: string, args?: Variables | void): (RecordProxy | void)[] | void, - getOrCreateLinkedRecord( - name: string, - typeName: string, - args?: Variables | void, - ): RecordProxy, - getType(): string, - getValue(name: string, args?: Variables | void): any, - setLinkedRecord( - record: RecordProxy, - name: string, - args?: Variables | void, - ): RecordProxy, - setLinkedRecords( - records: (RecordProxy | void)[] | void, - name: string, - args?: Variables | void, - ): RecordProxy, - setValue(value: any, name: string, args?: Variables | void): RecordProxy, - } - - export interface RecordSourceProxy { - create(dataID: DataID, typeName: string): RecordProxy, - delete(dataID: DataID): void, - get(dataID: DataID): (RecordProxy | void)[] | void, - getRoot(): RecordProxy, - } - - export type HandleFieldPayload = { - // The arguments that were fetched. - args: Variables, - // The __id of the record containing the source/handle field. - dataID: DataID, - // The (storage) key at which the original server data was written. - fieldKey: string, - // The name of the handle. - handle: string, - // The (storage) key at which the handle's data should be written by the - // handler. - handleKey: string, - }; - interface IHandler { - update: (store: RecordSourceProxy, fieldPayload: HandleFieldPayload) => void; - [functionName: string]: Function; - } - export const Handler: IHandler; - - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayCombinedEnvironmentTypes - // Version: Relay 1.3.0 - // File: https://github.com/facebook/relay/blob/b85a1d69bb72be4ace67179f55c2a54a8d761c8b/packages/react-relay/classic/environment/RelayCombinedEnvironmentTypes.js - // ~~~~~~~~~~~~~~~~~~~~~ - /** - * Settings for how a query response may be cached. - * - * - `force`: causes a query to be issued unconditionally, irrespective of the - * state of any configured response cache. - * - `poll`: causes a query to live update by polling at the specified interval - in milliseconds. (This value will be passed to setTimeout.) - */ - export type CacheConfig = { - force?: boolean | void, - poll?: number | void, - }; - - /** - * Represents any resource that must be explicitly disposed of. The most common - * use-case is as a return value for subscriptions, where calling `dispose()` - * would cancel the subscription. - */ - export type Disposable = { - dispose(): void, - }; - - - /** - * Arbitrary data e.g. received by a container as props. - */ - export type Props = {[key: string]: any}; - - /* - * An individual cached graph object. - */ - export type Record = {[key: string]: any}; - - /** - * A collection of records keyed by id. - */ - export type RecordMap = {[dataID: string]: Record | void}; - - /** - * A selector defines the starting point for a traversal into the graph for the - * purposes of targeting a subgraph. - */ - export type CSelector = { - dataID: DataID, - node: TNode, - variables: Variables, - }; - - /** - * A representation of a selector and its results at a particular point in time. - */ - export type CSnapshot = CSelector & { - data: SelectorData | void, - seenRecords: RecordMap, - }; - - /** - * The results of a selector given a store/RecordSource. - */ - export type SelectorData = {[key: string]: any}; - - /** - * The results of reading the results of a FragmentMap given some input - * `Props`. - */ - export type FragmentSpecResults = {[key: string]: any}; - - /** - * A utility for resolving and subscribing to the results of a fragment spec - * (key -> fragment mapping) given some "props" that determine the root ID - * and variables to use when reading each fragment. When props are changed via - * `setProps()`, the resolver will update its results and subscriptions - * accordingly. Internally, the resolver: - * - Converts the fragment map & props map into a map of `Selector`s. - * - Removes any resolvers for any props that became null. - * - Creates resolvers for any props that became non-null. - * - Updates resolvers with the latest props. - */ - export interface FragmentSpecResolver { - /** - * Stop watching for changes to the results of the fragments. - */ - dispose(): void, - - /** - * Get the current results. - */ - resolve(): FragmentSpecResults, - - /** - * Update the resolver with new inputs. Call `resolve()` to get the updated - * results. - */ - setProps(props: Props): void, - - /** - * Override the variables used to read the results of the fragments. Call - * `resolve()` to get the updated results. - */ - setVariables(variables: Variables): void, - } - - export type CFragmentMap = {[key: string]: TFragment}; - - /** - * An operation selector describes a specific instance of a GraphQL operation - * with variables applied. - * - * - `root`: a selector intended for processing server results or retaining - * response data in the store. - * - `fragment`: a selector intended for use in reading or subscribing to - * the results of the the operation. - */ - export type COperationSelector = { - fragment: CSelector, - node: TOperation, - root: CSelector, - variables: Variables, - }; - - /** - * The public API of Relay core. Represents an encapsulated environment with its - * own in-memory cache. - */ - export interface CEnvironment< - TEnvironment, - TFragment, - TGraphQLTaggedNode, - TNode, - TOperation, - TPayload, - > { - /** - * Read the results of a selector from in-memory records in the store. - */ - lookup(selector: CSelector): CSnapshot, - - /** - * Subscribe to changes to the results of a selector. The callback is called - * when data has been committed to the store that would cause the results of - * the snapshot's selector to change. - */ - subscribe( - snapshot: CSnapshot, - callback: (snapshot: CSnapshot) => void, - ): Disposable, - - /** - * Ensure that all the records necessary to fulfill the given selector are - * retained in-memory. The records will not be eligible for garbage collection - * until the returned reference is disposed. - * - * Note: This is a no-op in the classic core. - */ - retain(selector: CSelector): Disposable, - - /** - * Send a query to the server with request/response semantics: the query will - * either complete successfully (calling `onNext` and `onCompleted`) or fail - * (calling `onError`). - * - * Note: Most applications should use `streamQuery` in order to - * optionally receive updated information over time, should that feature be - * supported by the network/server. A good rule of thumb is to use this method - * if you would otherwise immediately dispose the `streamQuery()` - * after receving the first `onNext` result. - */ - sendQuery(config: { - cacheConfig?: CacheConfig | void, - onCompleted?: Maybe<() => void>, - onError?: Maybe<(error: Error) => void>, - onNext?: Maybe<(payload: TPayload) => void>, - operation: COperationSelector, - }): Disposable, - - /** - * Send a query to the server with request/subscription semantics: one or more - * responses may be returned (via `onNext`) over time followed by either - * the request completing (`onCompleted`) or an error (`onError`). - * - * Networks/servers that support subscriptions may choose to hold the - * subscription open indefinitely such that `onCompleted` is not called. - */ - streamQuery(config: { - cacheConfig?: Maybe, - onCompleted?: Maybe<() => void>, - onError?: Maybe<(error: Error) => void>, - onNext?: Maybe<(payload: TPayload) => void>, - operation: COperationSelector, - }): Disposable, - - unstable_internal: CUnstableEnvironmentCore< - TEnvironment, - TFragment, - TGraphQLTaggedNode, - TNode, - TOperation - >, - } - - export interface CUnstableEnvironmentCore< - TEnvironment, - TFragment, - TGraphQLTaggedNode, - TNode, - TOperation, - > { - /** - * Create an instance of a FragmentSpecResolver. - * - * TODO: The FragmentSpecResolver *can* be implemented via the other methods - * defined here, so this could be moved out of core. It's convenient to have - * separate implementations until the experimental core is in OSS. - */ - createFragmentSpecResolver: ( - context: CRelayContext, - containerName: string, - fragments: CFragmentMap, - props: Props, - callback: () => void, - ) => FragmentSpecResolver, - - /** - * Creates an instance of an OperationSelector given an operation definition - * (see `getOperation`) and the variables to apply. The input variables are - * filtered to exclude variables that do not matche defined arguments on the - * operation, and default values are populated for null values. - */ - createOperationSelector: ( - operation: TOperation, - variables: Variables, - ) => COperationSelector, - - /** - * Given a graphql`...` tagged template, extract a fragment definition usable - * by this version of Relay core. Throws if the value is not a fragment. - */ - getFragment: (node: TGraphQLTaggedNode) => TFragment, - - /** - * Given a graphql`...` tagged template, extract an operation definition - * usable by this version of Relay core. Throws if the value is not an - * operation. - */ - getOperation: (node: TGraphQLTaggedNode) => TOperation, - - /** - * Determine if two selectors are equal (represent the same selection). Note - * that this function returns `false` when the two queries/fragments are - * different objects, even if they select the same fields. - */ - areEqualSelectors: (a: CSelector, b: CSelector) => boolean, - - /** - * Given the result `item` from a parent that fetched `fragment`, creates a - * selector that can be used to read the results of that fragment for that item. - * - * Example: - * - * Given two fragments as follows: - * - * ``` - * fragment Parent on User { - * id - * ...Child - * } - * fragment Child on User { - * name - * } - * ``` - * - * And given some object `parent` that is the results of `Parent` for id "4", - * the results of `Child` can be accessed by first getting a selector and then - * using that selector to `lookup()` the results against the environment: - * - * ``` - * const childSelector = getSelector(queryVariables, Child, parent); - * const childData = environment.lookup(childSelector).data; - * ``` - */ - getSelector: ( - operationVariables: Variables, - fragment: TFragment, - prop: any, - ) => CSelector | void, - - /** - * Given the result `items` from a parent that fetched `fragment`, creates a - * selector that can be used to read the results of that fragment on those - * items. This is similar to `getSelector` but for "plural" fragments that - * expect an array of results and therefore return an array of selectors. - */ - getSelectorList: ( - operationVariables: Variables, - fragment: TFragment, - props: Array, - ) => Array> | void, - - /** - * Given a mapping of keys -> results and a mapping of keys -> fragments, - * extracts the selectors for those fragments from the results. - * - * The canonical use-case for this function are Relay Containers, which - * use this function to convert (props, fragments) into selectors so that they - * can read the results to pass to the inner component. - */ - getSelectorsFromObject: ( - operationVariables: Variables, - fragments: CFragmentMap, - props: Props, - ) => {[key: string]: Maybe<(CSelector | Array>)>}, - - /** - * Given a mapping of keys -> results and a mapping of keys -> fragments, - * extracts a mapping of keys -> id(s) of the results. - * - * Similar to `getSelectorsFromObject()`, this function can be useful in - * determining the "identity" of the props passed to a component. - */ - getDataIDsFromObject: ( - fragments: CFragmentMap, - props: Props, - ) => {[key: string]: Maybe<(DataID | Array)>}, - - /** - * Given a mapping of keys -> results and a mapping of keys -> fragments, - * extracts the merged variables that would be in scope for those - * fragments/results. - * - * This can be useful in determing what varaibles were used to fetch the data - * for a Relay container, for example. - */ - getVariablesFromObject: ( - operationVariables: Variables, - fragments: CFragmentMap, - props: Props, - ) => Variables, - } - - /** - * The type of the `relay` property set on React context by the React/Relay - * integration layer (e.g. QueryRenderer, FragmentContainer, etc). - */ - export type CRelayContext = { - environment: TEnvironment, - variables: Variables, - }; - - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayTypes - /** - * Version: Relay 1.3.0 - * File: - * https://github.com/facebook/relay/blob/fa9f48ea209ee2402d433b59a84d1cbc046574e2/packages/react-relay/classic/tools/RelayTypes.js - */ - // ~~~~~~~~~~~~~~~~~~~~~ - export type RerunParam = { - param: string, - import: string, - max_runs: number, - }; - interface FIELDS_CHANGE { - type: 'FIELDS_CHANGE', - fieldIDs: {[fieldName: string]: DataID | Array}, - } - interface RANGE_ADD { - type: 'RANGE_ADD', - parentName?: string, - parentID?: string, - connectionInfo?: Array<{ - key: string, - filters?: Variables, - rangeBehavior: string, - }>, - connectionName?: string, - edgeName: string, - rangeBehaviors?: RangeBehaviors, - } - interface NODE_DELETE { - type: 'NODE_DELETE', - parentName?: string, - parentID?: string, - connectionName?: string, - deletedIDFieldName: string, - } - interface RANGE_DELETE { - type: 'RANGE_DELETE', - parentName?: string, - parentID?: string, - connectionKeys?: Array<{ - key: string, - filters?: Variables, - }>, - connectionName?: string, - deletedIDFieldName: string | Array, - pathToConnection: Array, - } - interface REQUIRED_CHILDREN { - type: 'REQUIRED_CHILDREN', - children: Array, - } - export type RelayMutationConfig = - FIELDS_CHANGE | - RANGE_ADD | - NODE_DELETE | - RANGE_DELETE | - REQUIRED_CHILDREN; - - export type RelayMutationTransactionCommitCallbacks = { - onFailure?: RelayMutationTransactionCommitFailureCallback, - onSuccess?: RelayMutationTransactionCommitSuccessCallback, - }; - export type RelayMutationTransactionCommitFailureCallback = ( - transaction: RelayMutationTransaction, - preventAutoRollback: () => void, - ) => void; - export type RelayMutationTransactionCommitSuccessCallback = (response: { - [key: string]: any, - }) => void; - export type NetworkLayer = { - sendMutation(request: RelayMutationRequest): Promise | void, - sendQueries(requests: Array): Promise | void, - supports(...options: Array): boolean, - }; - export type QueryResult = { - error?: Error | void, - ref_params?: {[name: string]: any} | void, - response: QueryPayload, - }; - export type ReadyState = { - aborted: boolean, - done: boolean, - error: Error | void, - events: Array, - ready: boolean, - stale: boolean, - }; - type RelayContainerErrorEventType = - | 'CACHE_RESTORE_FAILED' - | 'NETWORK_QUERY_ERROR'; - type RelayContainerLoadingEventType = - | 'ABORT' - | 'CACHE_RESTORED_REQUIRED' - | 'CACHE_RESTORE_START' - | 'NETWORK_QUERY_RECEIVED_ALL' - | 'NETWORK_QUERY_RECEIVED_REQUIRED' - | 'NETWORK_QUERY_START' - | 'STORE_FOUND_ALL' - | 'STORE_FOUND_REQUIRED'; - export type ReadyStateChangeCallback = (readyState: ReadyState) => void; - export type ReadyStateEvent = { - type: RelayContainerLoadingEventType | RelayContainerErrorEventType, - error?: Error, - }; - export type Abortable = { - abort(): void, - }; - - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayInternalTypes - /** - * Version: Relay 1.3.0 - * File: - * https://github.com/facebook/relay/blob/master/packages/react-relay/classic/tools/RelayInternalTypes.js - */ - // ~~~~~~~~~~~~~~~~~~~~~ - export type QueryPayload = {[key: string]: any}; - export type RelayQuerySet = {[queryName: string]: any}; - type RangeBehaviorsFunction = (connectionArgs: { - [argName: string]: any, - }) => 'APPEND' | 'IGNORE' | 'PREPEND' | 'REFETCH' | 'REMOVE'; - type RangeBehaviorsObject = { - [key: string]: 'APPEND' | 'IGNORE' | 'PREPEND' | 'REFETCH' | 'REMOVE'; - }; - export type RangeBehaviors = RangeBehaviorsFunction | RangeBehaviorsObject; - } - - - - -declare namespace __Relay.Runtime { - // ~~~~~~~~~~~~~~~~~~~~~ - // Maybe Fix - // ~~~~~~~~~~~~~~~~~~~~~ - type RelayDebugger = any; - type OptimisticUpdate = any; - type OperationSelector = Common.COperationSelector; - type Selector = Common.CSelector; - type PayloadData = any; - type Snapshot = Common.CSnapshot; - type RelayResponsePayload = any; - type MutableRecordSource = RecordSource; - - /** - * A function that returns an Observable representing the response of executing - * a GraphQL operation. - */ - type ExecuteFunction = ( - operation: object, - variables: Common.Variables, - cacheConfig: Common.CacheConfig, - uploadables?: Common.UploadableMap | void, - ) => Promise; - type RelayNetwork = { - execute: ExecuteFunction, - }; - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayDefaultHandlerProvider - // ~~~~~~~~~~~~~~~~~~~~~ - export function HandlerProvider(name: string): typeof Common.Handler | void; - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayModernEnvironment - // ~~~~~~~~~~~~~~~~~~~~~ - type EnvironmentConfig = { - configName?: string, - handlerProvider?: typeof HandlerProvider, - network: Network, - store: Store, - }; - class Environment { - constructor (config: EnvironmentConfig); - getStore(): Store; - getDebugger(): RelayDebugger; - applyUpdate(optimisticUpdate: OptimisticUpdate): Common.Disposable; - revertUpdate(update: OptimisticUpdate): void; - replaceUpdate(update: OptimisticUpdate, newUpdate: OptimisticUpdate): void; - applyMutation(config: { - operation: OperationSelector, - optimisticUpdater?: Common.SelectorStoreUpdater, - optimisticResponse?: object, - }): Common.Disposable; - check(readSelector: Selector): boolean; - commitPayload( - operationSelector: OperationSelector, - payload: PayloadData, - ): void; - commitUpdate(updater: Common.StoreUpdater): void; - lookup(readSelector: Selector): Snapshot; - subscribe( - snapshot: Snapshot, - callback: (snapshot: Snapshot) => void, - ): Common.Disposable; - retain(selector: Selector): Common.Disposable; - execute(config: { - operation: OperationSelector, - cacheConfig?: Common.CacheConfig | void, - updater?: Common.SelectorStoreUpdater | void, - }): RelayObservable; - executeMutation(config: { - operation: OperationSelector, - optimisticUpdater?: Common.SelectorStoreUpdater | void, - optimisticResponse?: object | void, - updater?: Common.SelectorStoreUpdater | void, - uploadables?: Common.UploadableMap | void, - }): RelayObservable; - } - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayInMemoryRecordSource - // ~~~~~~~~~~~~~~~~~~~~~ - type Record = {[key: string]: any}; - type RecordMap = {[dataID: string]: Record | void}; - - // ~~~~~~~~~~~~~~~~~~~~~ - // Network - // ~~~~~~~~~~~~~~~~~~~~~ - class Network { /** - * Creates an implementation of the `Network` interface defined in - * `RelayNetworkTypes` given `fetch` and `subscribe` functions. + * SOURCE: + * Relay 1.3.0 + * https://github.com/facebook/relay/blob/b85a1d69bb72be4ace67179f55c2a54a8d761c8b/packages/react-relay/classic/environment/RelayCombinedEnvironmentTypes.js + */ + // ~~~~~~~~~~~~~~~~~~~~~ + // Util + // ~~~~~~~~~~~~~~~~~~~~~ + type Maybe = T | void; + + // ~~~~~~~~~~~~~~~~~~~~~ + // Maybe Fix + // ~~~~~~~~~~~~~~~~~~~~~ + type RelayConcreteNode = any; + type RelayMutationTransaction = any; + type RelayMutationRequest = any; + type RelayQueryRequest = any; + type ConcreteFragment = any; + type ConcreteBatch = any; + type ConcreteFragmentDefinition = object; + type ConcreteOperationDefinition = object; + + + /** + * FIXME: RelayContainer used to be typed with ReactClass, but + * ReactClass is broken and allows for access to any property. For example + * ReactClass.getFragment('foo') is valid even though ReactClass has no + * such getFragment() type definition. When ReactClass is fixed this causes a + * lot of errors in Relay code since methods like getFragment() are used often + * but have no definition in Relay's types. Suppressing for now. */ - static create(fetchFn: typeof Common.FetchFunction, subscribeFn?: Common.SubscribeFunction): RelayNetwork; + export type RelayContainer = any; + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayQL + // ~~~~~~~~~~~~~~~~~~~~~ + type RelayQL = ( + strings: string[], + ...substitutions: any[] + ) => Common.RelayConcreteNode; + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayModernGraphQLTag + // ~~~~~~~~~~~~~~~~~~~~~ + type GeneratedNodeMap = { [key: string]: GraphQLTaggedNode }; + type GraphQLTaggedNode = + (() => ConcreteFragment | ConcreteBatch) | + { + modern: () => ConcreteFragment | ConcreteBatch, + classic: (relayQL: RelayQL) => + | ConcreteFragmentDefinition + | ConcreteOperationDefinition, + }; + // ~~~~~~~~~~~~~~~~~~~~~ + // General Usage + // ~~~~~~~~~~~~~~~~~~~~~ + export type DataID = string; + export type Variables = { [name: string]: any }; + export type Uploadable = File | Blob; + export type UploadableMap = { [key: string]: Uploadable }; + + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayNetworkTypes + // Version: Relay 1.3.0 + // File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/network/RelayNetworkTypes.js + // ~~~~~~~~~~~~~~~~~~~~~ + + export type LegacyObserver = { + onCompleted?: (() => void) | void, + onError?: ((error: Error) => void) | void, + onNext?: ((data: T) => void) | void, + }; + export type PayloadError = { + message: string, + locations?: Array<{ + line: number, + column: number, + }>, + }; + /** + * A function that executes a GraphQL operation with request/response semantics. + * + * May return an Observable or Promise of a raw server response. + */ + export function FetchFunction( + operation: ConcreteBatch, + variables: Variables, + cacheConfig: CacheConfig, + uploadables?: Common.UploadableMap, + ): Runtime.ObservableFromValue; + + /** + * A function that executes a GraphQL subscription operation, returning one or + * more raw server responses over time. + * + * May return an Observable, otherwise must call the callbacks found in the + * fourth parameter. + */ + export type SubscribeFunction = ( + operation: ConcreteBatch, + variables: Variables, + cacheConfig: CacheConfig, + observer: LegacyObserver, + ) => Runtime.RelayObservable | Disposable; + + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayStoreTypes + // Version: Relay 1.3.0 + // File: https://github.com/facebook/relay/blob/master/packages/relay-runtime/store/RelayStoreTypes.js + // ~~~~~~~~~~~~~~~~~~~~~ + /** + * A function that receives a proxy over the store and may trigger side-effects + * (indirectly) by calling `set*` methods on the store or its record proxies. + */ + export type StoreUpdater = (store: RecordSourceProxy) => void; + + /** + * Similar to StoreUpdater, but accepts a proxy tied to a specific selector in + * order to easily access the root fields of a query/mutation as well as a + * second argument of the response object of the mutation. + */ + export type SelectorStoreUpdater = ( + store: RecordSourceSelectorProxy, + // Actually RelayCombinedEnvironmentTypes#SelectorData, but mixed is + // inconvenient to access deeply in product code. + data: any, // FLOW FIXME + ) => void; + + /** + * Extends the RecordSourceProxy interface with methods for accessing the root + * fields of a Selector. + */ + export interface RecordSourceSelectorProxy { + create(dataID: DataID, typeName: string): RecordProxy, + delete(dataID: DataID): void, + get(dataID: DataID): RecordProxy | void, + getRoot(): RecordProxy, + getRootField(fieldName: string): RecordProxy | void, + getPluralRootField(fieldName: string): RecordProxy[] | void, + } + + export interface RecordProxy { + copyFieldsFrom(source: RecordProxy): void, + getDataID(): DataID, + getLinkedRecord(name: string, args?: Variables | void): RecordProxy | void, + getLinkedRecords(name: string, args?: Variables | void): Array | void, + getOrCreateLinkedRecord( + name: string, + typeName: string, + args?: Variables | void, + ): RecordProxy, + getType(): string, + getValue(name: string, args?: Variables | void): any, + setLinkedRecord( + record: RecordProxy, + name: string, + args?: Variables | void, + ): RecordProxy, + setLinkedRecords( + records: (RecordProxy | void)[] | void, + name: string, + args?: Variables | void, + ): RecordProxy, + setValue(value: any, name: string, args?: Variables | void): RecordProxy, + } + + export interface RecordSourceProxy { + create(dataID: DataID, typeName: string): RecordProxy, + delete(dataID: DataID): void, + get(dataID: DataID): (RecordProxy | void)[] | void, + getRoot(): RecordProxy, + } + + export type HandleFieldPayload = { + // The arguments that were fetched. + args: Variables, + // The __id of the record containing the source/handle field. + dataID: DataID, + // The (storage) key at which the original server data was written. + fieldKey: string, + // The name of the handle. + handle: string, + // The (storage) key at which the handle's data should be written by the + // handler. + handleKey: string, + }; + interface IHandler { + update: (store: RecordSourceProxy, fieldPayload: HandleFieldPayload) => void; + [functionName: string]: (...args: any[]) => any; + } + export const Handler: IHandler; + + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayCombinedEnvironmentTypes + // Version: Relay 1.3.0 + // File: https://github.com/facebook/relay/blob/b85a1d69bb72be4ace67179f55c2a54a8d761c8b/packages/react-relay/classic/environment/RelayCombinedEnvironmentTypes.js + // ~~~~~~~~~~~~~~~~~~~~~ + /** + * Settings for how a query response may be cached. + * + * - `force`: causes a query to be issued unconditionally, irrespective of the + * state of any configured response cache. + * - `poll`: causes a query to live update by polling at the specified interval + in milliseconds. (This value will be passed to setTimeout.) + */ + export type CacheConfig = { + force?: boolean | void, + poll?: number | void, + }; + + /** + * Represents any resource that must be explicitly disposed of. The most common + * use-case is as a return value for subscriptions, where calling `dispose()` + * would cancel the subscription. + */ + export type Disposable = { + dispose(): void, + }; + + + /** + * Arbitrary data e.g. received by a container as props. + */ + export type Props = { [key: string]: any }; + + /* + * An individual cached graph object. + */ + export type Record = { [key: string]: any }; + + /** + * A collection of records keyed by id. + */ + export type RecordMap = { [dataID: string]: Record | void }; + + /** + * A selector defines the starting point for a traversal into the graph for the + * purposes of targeting a subgraph. + */ + export type CSelector = { + dataID: DataID, + node: TNode, + variables: Variables, + }; + + /** + * A representation of a selector and its results at a particular point in time. + */ + export type CSnapshot = CSelector & { + data: SelectorData | void, + seenRecords: RecordMap, + }; + + /** + * The results of a selector given a store/RecordSource. + */ + export type SelectorData = { [key: string]: any }; + + /** + * The results of reading the results of a FragmentMap given some input + * `Props`. + */ + export type FragmentSpecResults = { [key: string]: any }; + + /** + * A utility for resolving and subscribing to the results of a fragment spec + * (key -> fragment mapping) given some "props" that determine the root ID + * and variables to use when reading each fragment. When props are changed via + * `setProps()`, the resolver will update its results and subscriptions + * accordingly. Internally, the resolver: + * - Converts the fragment map & props map into a map of `Selector`s. + * - Removes any resolvers for any props that became null. + * - Creates resolvers for any props that became non-null. + * - Updates resolvers with the latest props. + */ + export interface FragmentSpecResolver { + /** + * Stop watching for changes to the results of the fragments. + */ + dispose(): void, + + /** + * Get the current results. + */ + resolve(): FragmentSpecResults, + + /** + * Update the resolver with new inputs. Call `resolve()` to get the updated + * results. + */ + setProps(props: Props): void, + + /** + * Override the variables used to read the results of the fragments. Call + * `resolve()` to get the updated results. + */ + setVariables(variables: Variables): void, + } + + export type CFragmentMap = { [key: string]: TFragment }; + + /** + * An operation selector describes a specific instance of a GraphQL operation + * with variables applied. + * + * - `root`: a selector intended for processing server results or retaining + * response data in the store. + * - `fragment`: a selector intended for use in reading or subscribing to + * the results of the the operation. + */ + export type COperationSelector = { + fragment: CSelector, + node: TOperation, + root: CSelector, + variables: Variables, + }; + + /** + * The public API of Relay core. Represents an encapsulated environment with its + * own in-memory cache. + */ + export interface CEnvironment< + TEnvironment, + TFragment, + TGraphQLTaggedNode, + TNode, + TOperation, + TPayload, + > { + /** + * Read the results of a selector from in-memory records in the store. + */ + lookup(selector: CSelector): CSnapshot, + + /** + * Subscribe to changes to the results of a selector. The callback is called + * when data has been committed to the store that would cause the results of + * the snapshot's selector to change. + */ + subscribe( + snapshot: CSnapshot, + callback: (snapshot: CSnapshot) => void, + ): Disposable, + + /** + * Ensure that all the records necessary to fulfill the given selector are + * retained in-memory. The records will not be eligible for garbage collection + * until the returned reference is disposed. + * + * Note: This is a no-op in the classic core. + */ + retain(selector: CSelector): Disposable, + + /** + * Send a query to the server with request/response semantics: the query will + * either complete successfully (calling `onNext` and `onCompleted`) or fail + * (calling `onError`). + * + * Note: Most applications should use `streamQuery` in order to + * optionally receive updated information over time, should that feature be + * supported by the network/server. A good rule of thumb is to use this method + * if you would otherwise immediately dispose the `streamQuery()` + * after receving the first `onNext` result. + */ + sendQuery(config: { + cacheConfig?: CacheConfig | void, + onCompleted?: Maybe<() => void>, + onError?: Maybe<(error: Error) => void>, + onNext?: Maybe<(payload: TPayload) => void>, + operation: COperationSelector, + }): Disposable, + + /** + * Send a query to the server with request/subscription semantics: one or more + * responses may be returned (via `onNext`) over time followed by either + * the request completing (`onCompleted`) or an error (`onError`). + * + * Networks/servers that support subscriptions may choose to hold the + * subscription open indefinitely such that `onCompleted` is not called. + */ + streamQuery(config: { + cacheConfig?: Maybe, + onCompleted?: Maybe<() => void>, + onError?: Maybe<(error: Error) => void>, + onNext?: Maybe<(payload: TPayload) => void>, + operation: COperationSelector, + }): Disposable, + + unstable_internal: CUnstableEnvironmentCore< + TEnvironment, + TFragment, + TGraphQLTaggedNode, + TNode, + TOperation + >, + } + + export interface CUnstableEnvironmentCore< + TEnvironment, + TFragment, + TGraphQLTaggedNode, + TNode, + TOperation, + > { + /** + * Create an instance of a FragmentSpecResolver. + * + * TODO: The FragmentSpecResolver *can* be implemented via the other methods + * defined here, so this could be moved out of core. It's convenient to have + * separate implementations until the experimental core is in OSS. + */ + createFragmentSpecResolver: ( + context: CRelayContext, + containerName: string, + fragments: CFragmentMap, + props: Props, + callback: () => void, + ) => FragmentSpecResolver, + + /** + * Creates an instance of an OperationSelector given an operation definition + * (see `getOperation`) and the variables to apply. The input variables are + * filtered to exclude variables that do not matche defined arguments on the + * operation, and default values are populated for null values. + */ + createOperationSelector: ( + operation: TOperation, + variables: Variables, + ) => COperationSelector, + + /** + * Given a graphql`...` tagged template, extract a fragment definition usable + * by this version of Relay core. Throws if the value is not a fragment. + */ + getFragment: (node: TGraphQLTaggedNode) => TFragment, + + /** + * Given a graphql`...` tagged template, extract an operation definition + * usable by this version of Relay core. Throws if the value is not an + * operation. + */ + getOperation: (node: TGraphQLTaggedNode) => TOperation, + + /** + * Determine if two selectors are equal (represent the same selection). Note + * that this function returns `false` when the two queries/fragments are + * different objects, even if they select the same fields. + */ + areEqualSelectors: (a: CSelector, b: CSelector) => boolean, + + /** + * Given the result `item` from a parent that fetched `fragment`, creates a + * selector that can be used to read the results of that fragment for that item. + * + * Example: + * + * Given two fragments as follows: + * + * ``` + * fragment Parent on User { + * id + * ...Child + * } + * fragment Child on User { + * name + * } + * ``` + * + * And given some object `parent` that is the results of `Parent` for id "4", + * the results of `Child` can be accessed by first getting a selector and then + * using that selector to `lookup()` the results against the environment: + * + * ``` + * const childSelector = getSelector(queryVariables, Child, parent); + * const childData = environment.lookup(childSelector).data; + * ``` + */ + getSelector: ( + operationVariables: Variables, + fragment: TFragment, + prop: any, + ) => CSelector | void, + + /** + * Given the result `items` from a parent that fetched `fragment`, creates a + * selector that can be used to read the results of that fragment on those + * items. This is similar to `getSelector` but for "plural" fragments that + * expect an array of results and therefore return an array of selectors. + */ + getSelectorList: ( + operationVariables: Variables, + fragment: TFragment, + props: any[], + ) => Array> | void, + + /** + * Given a mapping of keys -> results and a mapping of keys -> fragments, + * extracts the selectors for those fragments from the results. + * + * The canonical use-case for this function are Relay Containers, which + * use this function to convert (props, fragments) into selectors so that they + * can read the results to pass to the inner component. + */ + getSelectorsFromObject: ( + operationVariables: Variables, + fragments: CFragmentMap, + props: Props, + ) => { [key: string]: Maybe<(CSelector | Array>)> }, + + /** + * Given a mapping of keys -> results and a mapping of keys -> fragments, + * extracts a mapping of keys -> id(s) of the results. + * + * Similar to `getSelectorsFromObject()`, this function can be useful in + * determining the "identity" of the props passed to a component. + */ + getDataIDsFromObject: ( + fragments: CFragmentMap, + props: Props, + ) => { [key: string]: Maybe<(DataID | Array)> }, + + /** + * Given a mapping of keys -> results and a mapping of keys -> fragments, + * extracts the merged variables that would be in scope for those + * fragments/results. + * + * This can be useful in determing what varaibles were used to fetch the data + * for a Relay container, for example. + */ + getVariablesFromObject: ( + operationVariables: Variables, + fragments: CFragmentMap, + props: Props, + ) => Variables, + } + + /** + * The type of the `relay` property set on React context by the React/Relay + * integration layer (e.g. QueryRenderer, FragmentContainer, etc). + */ + export type CRelayContext = { + environment: TEnvironment, + variables: Variables, + }; + + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayTypes + /** + * Version: Relay 1.3.0 + * File: + * https://github.com/facebook/relay/blob/fa9f48ea209ee2402d433b59a84d1cbc046574e2/packages/react-relay/classic/tools/RelayTypes.js + */ + // ~~~~~~~~~~~~~~~~~~~~~ + export type RerunParam = { + param: string, + import: string, + max_runs: number, + }; + interface FIELDS_CHANGE { + type: 'FIELDS_CHANGE', + fieldIDs: { [fieldName: string]: DataID | Array }, + } + interface RANGE_ADD { + type: 'RANGE_ADD', + parentName?: string, + parentID?: string, + connectionInfo?: Array<{ + key: string, + filters?: Variables, + rangeBehavior: string, + }>, + connectionName?: string, + edgeName: string, + rangeBehaviors?: RangeBehaviors, + } + interface NODE_DELETE { + type: 'NODE_DELETE', + parentName?: string, + parentID?: string, + connectionName?: string, + deletedIDFieldName: string, + } + interface RANGE_DELETE { + type: 'RANGE_DELETE', + parentName?: string, + parentID?: string, + connectionKeys?: Array<{ + key: string, + filters?: Variables, + }>, + connectionName?: string, + deletedIDFieldName: string | string[], + pathToConnection: string[], + } + interface REQUIRED_CHILDREN { + type: 'REQUIRED_CHILDREN', + children: Array, + } + export type RelayMutationConfig = + FIELDS_CHANGE | + RANGE_ADD | + NODE_DELETE | + RANGE_DELETE | + REQUIRED_CHILDREN; + + export type RelayMutationTransactionCommitCallbacks = { + onFailure?: RelayMutationTransactionCommitFailureCallback, + onSuccess?: RelayMutationTransactionCommitSuccessCallback, + }; + export type RelayMutationTransactionCommitFailureCallback = ( + transaction: RelayMutationTransaction, + preventAutoRollback: () => void, + ) => void; + export type RelayMutationTransactionCommitSuccessCallback = (response: { + [key: string]: any, + }) => void; + export type NetworkLayer = { + sendMutation(request: RelayMutationRequest): Promise | void, + sendQueries(requests: Array): Promise | void, + supports(...options: string[]): boolean, + }; + export type QueryResult = { + error?: Error | void, + ref_params?: { [name: string]: any } | void, + response: QueryPayload, + }; + export type ReadyState = { + aborted: boolean, + done: boolean, + error: Error | void, + events: Array, + ready: boolean, + stale: boolean, + }; + type RelayContainerErrorEventType = + | 'CACHE_RESTORE_FAILED' + | 'NETWORK_QUERY_ERROR'; + type RelayContainerLoadingEventType = + | 'ABORT' + | 'CACHE_RESTORED_REQUIRED' + | 'CACHE_RESTORE_START' + | 'NETWORK_QUERY_RECEIVED_ALL' + | 'NETWORK_QUERY_RECEIVED_REQUIRED' + | 'NETWORK_QUERY_START' + | 'STORE_FOUND_ALL' + | 'STORE_FOUND_REQUIRED'; + export type ReadyStateChangeCallback = (readyState: ReadyState) => void; + export type ReadyStateEvent = { + type: RelayContainerLoadingEventType | RelayContainerErrorEventType, + error?: Error, + }; + export type Abortable = { + abort(): void, + }; + + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayInternalTypes + /** + * Version: Relay 1.3.0 + * File: + * https://github.com/facebook/relay/blob/master/packages/react-relay/classic/tools/RelayInternalTypes.js + */ + // ~~~~~~~~~~~~~~~~~~~~~ + export type QueryPayload = { [key: string]: any }; + export type RelayQuerySet = { [queryName: string]: any }; + type RangeBehaviorsFunction = (connectionArgs: { + [argName: string]: any, + }) => 'APPEND' | 'IGNORE' | 'PREPEND' | 'REFETCH' | 'REMOVE'; + type RangeBehaviorsObject = { + [key: string]: 'APPEND' | 'IGNORE' | 'PREPEND' | 'REFETCH' | 'REMOVE'; + }; + export type RangeBehaviors = RangeBehaviorsFunction | RangeBehaviorsObject; } - // ~~~~~~~~~~~~~~~~~~~~~ - // Network - // ~~~~~~~~~~~~~~~~~~~~~ - class RecordSource { - constructor(records?: RecordMap); - clear(): void; - delete(dataID: Common.DataID): void; - get(dataID: Common.DataID): Record | void; - getRecordIDs(): Common.DataID[]; - getStatus(dataID: Common.DataID): 'EXISTENT' | 'NONEXISTENT' | 'UNKNOWN'; - has(dataID: Common.DataID): boolean; - load( - dataID: Common.DataID, - callback: (error: Error | void, record: Record | void) => void, - ): void; - remove(dataID: Common.DataID): void; - set(dataID: Common.DataID, record: Record): void; - size(): number; - toJSON(): RecordMap; + namespace Runtime { + // ~~~~~~~~~~~~~~~~~~~~~ + // Maybe Fix + // ~~~~~~~~~~~~~~~~~~~~~ + type RelayDebugger = any; + type OptimisticUpdate = any; + type OperationSelector = Common.COperationSelector; + type Selector = Common.CSelector; + type PayloadData = any; + type Snapshot = Common.CSnapshot; + type RelayResponsePayload = any; + type MutableRecordSource = RecordSource; + + /** + * A function that returns an Observable representing the response of executing + * a GraphQL operation. + */ + type ExecuteFunction = ( + operation: object, + variables: Common.Variables, + cacheConfig: Common.CacheConfig, + uploadables?: Common.UploadableMap | void, + ) => Promise; + type RelayNetwork = { + execute: ExecuteFunction, + }; + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayDefaultHandlerProvider + // ~~~~~~~~~~~~~~~~~~~~~ + export function HandlerProvider(name: string): typeof Common.Handler | void; + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayModernEnvironment + // ~~~~~~~~~~~~~~~~~~~~~ + type EnvironmentConfig = { + configName?: string, + handlerProvider?: typeof HandlerProvider, + network: Network, + store: Store, + }; + class Environment { + constructor(config: EnvironmentConfig); + getStore(): Store; + getDebugger(): RelayDebugger; + applyUpdate(optimisticUpdate: OptimisticUpdate): Common.Disposable; + revertUpdate(update: OptimisticUpdate): void; + replaceUpdate(update: OptimisticUpdate, newUpdate: OptimisticUpdate): void; + applyMutation(config: { + operation: OperationSelector, + optimisticUpdater?: Common.SelectorStoreUpdater, + optimisticResponse?: object, + }): Common.Disposable; + check(readSelector: Selector): boolean; + commitPayload( + operationSelector: OperationSelector, + payload: PayloadData, + ): void; + commitUpdate(updater: Common.StoreUpdater): void; + lookup(readSelector: Selector): Snapshot; + subscribe( + snapshot: Snapshot, + callback: (snapshot: Snapshot) => void, + ): Common.Disposable; + retain(selector: Selector): Common.Disposable; + execute(config: { + operation: OperationSelector, + cacheConfig?: Common.CacheConfig | void, + updater?: Common.SelectorStoreUpdater | void, + }): RelayObservable; + executeMutation(config: { + operation: OperationSelector, + optimisticUpdater?: Common.SelectorStoreUpdater | void, + optimisticResponse?: object | void, + updater?: Common.SelectorStoreUpdater | void, + uploadables?: Common.UploadableMap | void, + }): RelayObservable; + } + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayInMemoryRecordSource + // ~~~~~~~~~~~~~~~~~~~~~ + type Record = { [key: string]: any }; + type RecordMap = { [dataID: string]: Record | void }; + + // ~~~~~~~~~~~~~~~~~~~~~ + // Network + // ~~~~~~~~~~~~~~~~~~~~~ + class Network { + /** + * Creates an implementation of the `Network` interface defined in + * `RelayNetworkTypes` given `fetch` and `subscribe` functions. + */ + static create(fetchFn: typeof Common.FetchFunction, subscribeFn?: Common.SubscribeFunction): RelayNetwork; + } + + // ~~~~~~~~~~~~~~~~~~~~~ + // Network + // ~~~~~~~~~~~~~~~~~~~~~ + class RecordSource { + constructor(records?: RecordMap); + clear(): void; + delete(dataID: Common.DataID): void; + get(dataID: Common.DataID): Record | void; + getRecordIDs(): Common.DataID[]; + getStatus(dataID: Common.DataID): 'EXISTENT' | 'NONEXISTENT' | 'UNKNOWN'; + has(dataID: Common.DataID): boolean; + load( + dataID: Common.DataID, + callback: (error: Error | void, record: Record | void) => void, + ): void; + remove(dataID: Common.DataID): void; + set(dataID: Common.DataID, record: Record): void; + size(): number; + toJSON(): RecordMap; + } + + // ~~~~~~~~~~~~~~~~~~~~~ + // ModernStore + // ~~~~~~~~~~~~~~~~~~~~~ + class Store { + constructor(source: RecordSource); + getSource(): MutableRecordSource; + check(selector: Selector): boolean; + retain(selector: Selector): Common.Disposable; + lookup(selector: Selector): Snapshot; + notify(): void; + publish(source: RecordSource): void; + subscribe( + snapshot: Snapshot, + callback: (snapshot: Snapshot) => void, + ): Common.Disposable; + } + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayRecordSourceInspector + // ~~~~~~~~~~~~~~~~~~~~~ + /** + * An internal class to provide a console-friendly string representation of a + * Record. + */ + class RecordSummary { + id: Common.DataID; + type: string | void; + static createFromRecord(id: Common.DataID, record: any): RecordSummary; + constructor(id: Common.DataID, type: string | void); + toString(): string; + } + /** + * Internal class for inspecting a single Record. + */ + class RecordInspector { + constructor(sourceInspector: RelayRecordSourceInspector, record: Record); + /** + * Get the cache id of the given record. For types that implement the `Node` + * interface (or that have an `id`) this will be `id`, for other types it will be + * a synthesized identifier based on the field path from the nearest ancestor + * record that does have an `id`. + */ + getDataID(): Common.DataID; + + /** + * Returns a list of the fields that have been fetched on the current record. + */ + getFields(): string[]; + + /** + * Returns the type of the record. + */ + getType(): string; + + /** + * Returns a copy of the internal representation of the record. + */ + inspect(): any; + + /** + * Returns the value of a scalar field. May throw if the given field is + * present but not actually scalar. + */ + getValue(name: string, args?: Common.Variables | void): any; + + /** + * Returns an inspector for the given scalar "linked" field (a field whose + * value is another Record instead of a scalar). May throw if the field is + * present but not a scalar linked record. + */ + getLinkedRecord(name: string, args?: Common.Variables | void): RecordInspector | void; + + /** + * Returns an array of inspectors for the given plural "linked" field (a field + * whose value is an array of Records instead of a scalar). May throw if the + * field is present but not a plural linked record. + */ + getLinkedRecords(name: string, args?: Common.Variables | void): RecordInspector[] | void; + } + + class RelayRecordSourceInspector { + constructor(source: RecordSource); + static getForEnvironment(environment: Environment): RelayRecordSourceInspector; + /** + * Returns an inspector for the record with the given id, or null/undefined if + * that record is deleted/unfetched. + */ + get(dataID: Common.DataID): RecordInspector | void; + /** + * Returns a list of ": " for each record in the store that has an + * `id`. + */ + getNodes(): Array; + /** + * Returns a list of ": " for all records in the store including + * those that do not have an `id`. + */ + getRecords(): Array; + + /** + * Returns an inspector for the synthesized "root" object, allowing access to + * e.g. the `viewer` object or the results of other fields on the "Query" + * type. + */ + getRoot(): RecordInspector; + } + + + // ~~~~~~~~~~~~~~~~~~~~~ + // RelayObservable + // ~~~~~~~~~~~~~~~~~~~~~ + type Subscription = { + unsubscribe: () => void, + readonly closed: boolean, + }; + type Observer = { + start?: ((subscription: Subscription) => any) | void, + next?: ((nextThing: T) => any) | void, + error?: ((error: Error) => any) | void, + complete?: (() => any) | void, + unsubscribe?: ((subscription: Subscription) => any) | void, + }; + type Source = () => any; + interface Subscribable { + subscribe(observer: Observer): Subscription, + } + type ObservableFromValue = RelayObservable | Promise | T; + class RelayObservable implements Subscribable { + _source: Source; + + constructor(source: Source); + + /** + * When an unhandled error is detected, it is reported to the host environment + * (the ESObservable spec refers to this method as "HostReportErrors()"). + * + * The default implementation in development builds re-throws errors in a + * separate frame, and from production builds does nothing (swallowing + * uncaught errors). + * + * Called during application initialization, this method allows + * application-specific handling of uncaught errors. Allowing, for example, + * integration with error logging or developer tools. + */ + static onUnhandledError(callback: (error: Error) => any): void; + + /** + * Accepts various kinds of data sources, and always returns a RelayObservable + * useful for accepting the result of a user-provided FetchFunction. + */ + static from(obj: ObservableFromValue): RelayObservable; + + /** + * Creates a RelayObservable, given a function which expects a legacy + * Relay Observer as the last argument and which returns a Disposable. + * + * To support migration to Observable, the function may ignore the + * legacy Relay observer and directly return an Observable instead. + */ + static fromLegacy( + callback: (legacyObserver: Common.LegacyObserver) => Common.Disposable | RelayObservable, + ): RelayObservable; + + /** + * Returns a new Observable which returns the same values as this one, but + * modified so that the provided Observer is called to perform a side-effects + * for all events emitted by the source. + * + * Any errors that are thrown in the side-effect Observer are unhandled, and + * do not affect the source Observable or its Observer. + * + * This is useful for when debugging your Observables or performing other + * side-effects such as logging or performance monitoring. + */ + do(observer: Observer): RelayObservable; + + /** + * Returns a new Observable which returns the same values as this one, but + * modified so that the finally callback is performed after completion, + * whether normal or due to error or unsubscription. + * + * This is useful for cleanup such as resource finalization. + */ + finally(fn: () => any): RelayObservable; + + /** + * Returns a new Observable which is identical to this one, unless this + * Observable completes before yielding any values, in which case the new + * Observable will yield the values from the alternate Observable. + * + * If this Observable does yield values, the alternate is never subscribed to. + * + * This is useful for scenarios where values may come from multiple sources + * which should be tried in order, i.e. from a cache before a network. + */ + ifEmpty(alternate: RelayObservable): RelayObservable; + + /** + * Observable's primary API: returns an unsubscribable Subscription to the + * source of this Observable. + */ + subscribe(observer: Observer): Subscription; + + /** + * Supports subscription of a legacy Relay Observer, returning a Disposable. + */ + subscribeLegacy(legacyObserver: Common.LegacyObserver): Common.Disposable; + + /** + * Returns a new Observerable where each value has been transformed by + * the mapping function. + */ + map(fn: (thing: T) => U): RelayObservable; + + /** + * Returns a new Observable where each value is replaced with a new Observable + * by the mapping function, the results of which returned as a single + * concattenated Observable. + */ + concatMap(fn: (thing: T) => ObservableFromValue): RelayObservable; + + /** + * Returns a new Observable which first mirrors this Observable, then when it + * completes, waits for `pollInterval` milliseconds before re-subscribing to + * this Observable again, looping in this manner until unsubscribed. + * + * The returned Observable never completes. + */ + poll(pollInterval: number): RelayObservable; + + /** + * Returns a Promise which resolves when this Observable yields a first value + * or when it completes with no value. + */ + toPromise(): Promise; + } + + + // ~~~~~~~~~~~~~~~~~~~~~ + // commitLocalUpdate + // ~~~~~~~~~~~~~~~~~~~~~ + // exposed through RelayModern, not Runtime directly + type commitLocalUpdate = ( + environment: Environment, + updater: Common.StoreUpdater, + ) => void; + + // ~~~~~~~~~~~~~~~~~~~~~ + // commitRelayModernMutation + // ~~~~~~~~~~~~~~~~~~~~~ + // exposed through RelayModern, not Runtime directly + type MutationConfig = { + configs?: Array, + mutation: Common.GraphQLTaggedNode, + variables: Common.Variables, + uploadables?: Common.UploadableMap, + onCompleted?: (response: T, errors: Array | void) => void, + onError?: (error?: Error) => void, + optimisticUpdater?: Common.SelectorStoreUpdater | void, + optimisticResponse?: object, + updater?: Common.SelectorStoreUpdater | void, + }; + function commitRelayModernMutation( + environment: Environment, + config: MutationConfig, + ): Common.Disposable; + + // ~~~~~~~~~~~~~~~~~~~~~ + // applyRelayModernOptimisticMutation + // ~~~~~~~~~~~~~~~~~~~~~ + // exposed through RelayModern, not Runtime directly + type OptimisticMutationConfig = { + configs?: Array, + mutation: Common.GraphQLTaggedNode, + variables: Common.Variables, + optimisticUpdater?: Common.SelectorStoreUpdater, + optimisticResponse?: object, + }; + + // ~~~~~~~~~~~~~~~~~~~~~ + // fetchRelayModernQuery + // ~~~~~~~~~~~~~~~~~~~~~ + // exposed through RelayModern, not Runtime directly + /** + * A helper function to fetch the results of a query. Note that results for + * fragment spreads are masked: fields must be explicitly listed in the query in + * order to be accessible in the result object. + * + * NOTE: This module is primarily intended for integrating with classic APIs. + * Most product code should use a Renderer or Container. + * + * TODO(t16875667): The return type should be `Promise`, but + * that's not really helpful as `SelectorData` is essentially just `mixed`. We + * can probably leverage generated flow types here to return the real expected + * shape. + */ + function fetchRelayModernQuery( + environment: any, // FIXME - $FlowFixMe in facebook source code + taggedNode: Common.GraphQLTaggedNode, + variables: Common.Variables, + cacheConfig?: Common.CacheConfig | void, + ): Promise; // FIXME - $FlowFixMe in facebook source code + + + // ~~~~~~~~~~~~~~~~~~~~~ + // requestRelaySubscription + // ~~~~~~~~~~~~~~~~~~~~~ + // exposed through RelayModern, not Runtime directly + export type GraphQLSubscriptionConfig = { + configs?: Array, + subscription: Common.GraphQLTaggedNode, + variables: Common.Variables, + onCompleted?: () => void, + onError?: (error: Error) => void, + onNext?: (response: object | void) => void, + updater?: (store: Common.RecordSourceSelectorProxy) => void, + }; + export function requestRelaySubscription( + environment: Environment, + config: GraphQLSubscriptionConfig, + ): Common.Disposable; } +} - // ~~~~~~~~~~~~~~~~~~~~~ - // ModernStore - // ~~~~~~~~~~~~~~~~~~~~~ - class Store { - constructor(source: RecordSource); - getSource(): MutableRecordSource; - check(selector: Selector): boolean; - retain(selector: Selector): Common.Disposable; - lookup(selector: Selector): Snapshot; - notify(): void; - publish(source: RecordSource): void; - subscribe( - snapshot: Snapshot, - callback: (snapshot: Snapshot) => void, - ): Common.Disposable; - } - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayRecordSourceInspector - // ~~~~~~~~~~~~~~~~~~~~~ - /** - * An internal class to provide a console-friendly string representation of a - * Record. - */ - class RecordSummary { - id: Common.DataID; - type: string | void; - static createFromRecord(id: Common.DataID, record: any): RecordSummary; - constructor(id: Common.DataID, type: string | void); - toString(): string; - } - /** - * Internal class for inspecting a single Record. - */ - class RecordInspector { - constructor(sourceInspector: RelayRecordSourceInspector, record: Record); - /** - * Get the cache id of the given record. For types that implement the `Node` - * interface (or that have an `id`) this will be `id`, for other types it will be - * a synthesized identifier based on the field path from the nearest ancestor - * record that does have an `id`. - */ - getDataID(): Common.DataID; - - /** - * Returns a list of the fields that have been fetched on the current record. - */ - getFields(): Array; - - /** - * Returns the type of the record. - */ - getType(): string; - - /** - * Returns a copy of the internal representation of the record. - */ - inspect(): any; - - /** - * Returns the value of a scalar field. May throw if the given field is - * present but not actually scalar. - */ - getValue(name: string, args?: Common.Variables | void): any; - - /** - * Returns an inspector for the given scalar "linked" field (a field whose - * value is another Record instead of a scalar). May throw if the field is - * present but not a scalar linked record. - */ - getLinkedRecord(name: string, args?: Common.Variables | void): RecordInspector | void; - - /** - * Returns an array of inspectors for the given plural "linked" field (a field - * whose value is an array of Records instead of a scalar). May throw if the - * field is present but not a plural linked record. - */ - getLinkedRecords(name: string, args?: Common.Variables | void): RecordInspector[] | void; - } - - class RelayRecordSourceInspector { - constructor(source: RecordSource); - static getForEnvironment(environment: Environment): RelayRecordSourceInspector; - /** - * Returns an inspector for the record with the given id, or null/undefined if - * that record is deleted/unfetched. - */ - get(dataID: Common.DataID): RecordInspector | void; - /** - * Returns a list of ": " for each record in the store that has an - * `id`. - */ - getNodes(): Array; - /** - * Returns a list of ": " for all records in the store including - * those that do not have an `id`. - */ - getRecords(): Array; - - /** - * Returns an inspector for the synthesized "root" object, allowing access to - * e.g. the `viewer` object or the results of other fields on the "Query" - * type. - */ - getRoot(): RecordInspector; - } - - - // ~~~~~~~~~~~~~~~~~~~~~ - // RelayObservable - // ~~~~~~~~~~~~~~~~~~~~~ - type Subscription = { - unsubscribe: () => void, - readonly closed: boolean, - }; - type Observer = { - start?: ((subscription: Subscription) => any) | void, - next?: ((nextThing: T) => any) | void, - error?: ((error: Error) => any) | void, - complete?: (() => any) | void, - unsubscribe?: ((subscription: Subscription) => any) | void, - }; - type Source = () => any; - interface Subscribable { - subscribe(observer: Observer): Subscription, - } - type ObservableFromValue = RelayObservable | Promise | T; - class RelayObservable implements Subscribable { - _source: Source; - - constructor(source: Source); - - /** - * When an unhandled error is detected, it is reported to the host environment - * (the ESObservable spec refers to this method as "HostReportErrors()"). - * - * The default implementation in development builds re-throws errors in a - * separate frame, and from production builds does nothing (swallowing - * uncaught errors). - * - * Called during application initialization, this method allows - * application-specific handling of uncaught errors. Allowing, for example, - * integration with error logging or developer tools. - */ - static onUnhandledError(callback: (error: Error) => any): void; - - /** - * Accepts various kinds of data sources, and always returns a RelayObservable - * useful for accepting the result of a user-provided FetchFunction. - */ - static from(obj: ObservableFromValue): RelayObservable; - - /** - * Creates a RelayObservable, given a function which expects a legacy - * Relay Observer as the last argument and which returns a Disposable. - * - * To support migration to Observable, the function may ignore the - * legacy Relay observer and directly return an Observable instead. - */ - static fromLegacy( - callback: (legacyObserver: Common.LegacyObserver) => Common.Disposable | RelayObservable, - ): RelayObservable; - - /** - * Returns a new Observable which returns the same values as this one, but - * modified so that the provided Observer is called to perform a side-effects - * for all events emitted by the source. - * - * Any errors that are thrown in the side-effect Observer are unhandled, and - * do not affect the source Observable or its Observer. - * - * This is useful for when debugging your Observables or performing other - * side-effects such as logging or performance monitoring. - */ - do(observer: Observer): RelayObservable; - - /** - * Returns a new Observable which returns the same values as this one, but - * modified so that the finally callback is performed after completion, - * whether normal or due to error or unsubscription. - * - * This is useful for cleanup such as resource finalization. - */ - finally(fn: () => any): RelayObservable; - - /** - * Returns a new Observable which is identical to this one, unless this - * Observable completes before yielding any values, in which case the new - * Observable will yield the values from the alternate Observable. - * - * If this Observable does yield values, the alternate is never subscribed to. - * - * This is useful for scenarios where values may come from multiple sources - * which should be tried in order, i.e. from a cache before a network. - */ - ifEmpty(alternate: RelayObservable): RelayObservable; - - /** - * Observable's primary API: returns an unsubscribable Subscription to the - * source of this Observable. - */ - subscribe(observer: Observer): Subscription; - - /** - * Supports subscription of a legacy Relay Observer, returning a Disposable. - */ - subscribeLegacy(legacyObserver: Common.LegacyObserver): Common.Disposable; - - /** - * Returns a new Observerable where each value has been transformed by - * the mapping function. - */ - map(fn: (thing: T) => U): RelayObservable; - - /** - * Returns a new Observable where each value is replaced with a new Observable - * by the mapping function, the results of which returned as a single - * concattenated Observable. - */ - concatMap(fn: (thing: T) => ObservableFromValue): RelayObservable; - - /** - * Returns a new Observable which first mirrors this Observable, then when it - * completes, waits for `pollInterval` milliseconds before re-subscribing to - * this Observable again, looping in this manner until unsubscribed. - * - * The returned Observable never completes. - */ - poll(pollInterval: number): RelayObservable; - - /** - * Returns a Promise which resolves when this Observable yields a first value - * or when it completes with no value. - */ - toPromise(): Promise; - } - - - // ~~~~~~~~~~~~~~~~~~~~~ - // commitLocalUpdate - // ~~~~~~~~~~~~~~~~~~~~~ - // exposed through RelayModern, not Runtime directly - type commitLocalUpdate = ( - environment: Environment, - updater: Common.StoreUpdater, - ) => void; - - // ~~~~~~~~~~~~~~~~~~~~~ - // commitRelayModernMutation - // ~~~~~~~~~~~~~~~~~~~~~ - // exposed through RelayModern, not Runtime directly - type MutationConfig = { - configs?: Array, - mutation: Common.GraphQLTaggedNode, - variables: Common.Variables, - uploadables?: Common.UploadableMap, - onCompleted?: (response: T, errors: Array | void) => void, - onError?: (error?: Error) => void, - optimisticUpdater?: Common.SelectorStoreUpdater | void, - optimisticResponse?: object, - updater?: Common.SelectorStoreUpdater | void, - }; - function commitRelayModernMutation( - environment: Environment, - config: MutationConfig, - ): Common.Disposable; - - // ~~~~~~~~~~~~~~~~~~~~~ - // applyRelayModernOptimisticMutation - // ~~~~~~~~~~~~~~~~~~~~~ - // exposed through RelayModern, not Runtime directly - type OptimisticMutationConfig = { - configs?: Array, - mutation: Common.GraphQLTaggedNode, - variables: Common.Variables, - optimisticUpdater?: Common.SelectorStoreUpdater, - optimisticResponse?: object, - }; - - // ~~~~~~~~~~~~~~~~~~~~~ - // fetchRelayModernQuery - // ~~~~~~~~~~~~~~~~~~~~~ - // exposed through RelayModern, not Runtime directly - /** - * A helper function to fetch the results of a query. Note that results for - * fragment spreads are masked: fields must be explicitly listed in the query in - * order to be accessible in the result object. - * - * NOTE: This module is primarily intended for integrating with classic APIs. - * Most product code should use a Renderer or Container. - * - * TODO(t16875667): The return type should be `Promise`, but - * that's not really helpful as `SelectorData` is essentially just `mixed`. We - * can probably leverage generated flow types here to return the real expected - * shape. - */ - function fetchRelayModernQuery( - environment: any, // FIXME - $FlowFixMe in facebook source code - taggedNode: Common.GraphQLTaggedNode, - variables: Common.Variables, - cacheConfig?: Common.CacheConfig | void, - ): Promise; // FIXME - $FlowFixMe in facebook source code - - - // ~~~~~~~~~~~~~~~~~~~~~ - // requestRelaySubscription - // ~~~~~~~~~~~~~~~~~~~~~ - // exposed through RelayModern, not Runtime directly - export type GraphQLSubscriptionConfig = { - configs?: Array, - subscription: Common.GraphQLTaggedNode, - variables: Common.Variables, - onCompleted?: () => void, - onError?: (error: Error) => void, - onNext?: (response: object | void) => void, - updater?: (store: Common.RecordSourceSelectorProxy) => void, - }; - export function requestRelaySubscription( - environment: Environment, - config: GraphQLSubscriptionConfig, - ): Common.Disposable; - } - - declare module 'relay-runtime' { +declare module 'relay-runtime' { export import Environment = __Relay.Runtime.Environment; export import Network = __Relay.Runtime.Network; export import RecordSource = __Relay.Runtime.RecordSource; @@ -1136,4 +1136,4 @@ declare namespace __Relay.Runtime { export import RecordSourceInspector = __Relay.Runtime.RelayRecordSourceInspector; export import ConnectionHandler = __Relay.Common.Handler; export import ViewerHandler = __Relay.Common.Handler; - } +}