/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format * @oncall relay */ 'use strict'; export type {FragmentState} from './store/observeFragmentExperimental'; import type {DataID} from './util/RelayRuntimeTypes'; const resolverDataInjector = require('./store/live-resolvers/resolverDataInjector'); const {observeFragment} = require('./store/observeFragmentExperimental'); const {observeQuery} = require('./store/observeQueryExperimental'); const {waitForFragmentData} = require('./store/waitForFragmentExperimental'); // Annotates a strong object return type, where `A` is the GraphQL typename and `Typename` is the // `__typename` field for returning an interface // eslint-disable-next-line no-unused-vars export type IdOf = [ Typename, ] extends [void] ? {id: DataID} : {id: DataID, __typename: Typename}; /** * Annotates a `RelayResolverValue` GraphQL return type. Using this type in the * return position of a Relay Resolver informs Relay that it should model this * field as returning a `RelayResolverValue` type. See the docs for more * information: * * https://relay.dev/docs/next/guides/relay-resolvers/return-types/#javascript-values * * Note: This type forces the value to be non-maybe. This is required in order * to allow the Relay compiler to to "see", via static analysis, if the field * can return null or not. If the field is nullable, you can type it as * returning `?RelayResolverValue`. */ export type RelayResolverValue = $NonMaybeType; type ErrorResult = { +ok: false, +errors: $ReadOnlyArray, }; type OkayResult = { +ok: true, +value: T, }; export type Result = OkayResult | ErrorResult; function isValueResult( input: Result, ): input is OkayResult { return input.ok === (true as const); } function isErrorResult( input: Result, ): input is ErrorResult { return input.ok === (false as const); } module.exports = { resolverDataInjector, isValueResult, isErrorResult, observeQuery, observeFragment, waitForFragmentData, };