/** * 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. */ import {ArrayKeyType, ArrayKeyTypeData, KeyType, KeyTypeData} from './ReactRelayTypes'; import { GraphQLTaggedNode, IEnvironment, OperationType, ServerOperationType, ServerRequest, } from 'relay-runtime'; export interface PreloadedQueryResponse { readonly data: TData; readonly errors?: ReadonlyArray<{ readonly message: string }>; } export interface PreloadedQueryRef { readonly kind: 'PreloadedQueryRef'; readonly queryId: string; readonly variables: TVariables; readonly _response: Promise>; readonly fetchedAt: number; } export interface ServerEnvironment { readonly getEnvironment: () => IEnvironment; readonly serverFetchQuery: ( query: GraphQLTaggedNode, variables: T['variables'], ) => Promise; readonly serverPreloadQuery: ( query: GraphQLTaggedNode, variables: T['variables'], ) => PreloadedQueryRef; readonly serverReadFragment: { ( fragment: GraphQLTaggedNode, fragmentRef: TKey, ): Promise>; ( fragment: GraphQLTaggedNode, fragmentRef: TKey, ): Promise>; }; /** * Executes a `@server` query in this request's server environment and * resolves with its data once the first payload has arrived. Client * fragment references in the data carry their data to client components. */ readonly serverQuery: { ( query: ServerRequest, variables: NoInfer, options?: ServerQueryOptions, ): Promise; ( query: GraphQLTaggedNode, variables: [T] extends [never] ? never : NoInfer, options?: ServerQueryOptions, ): Promise; }; /** * Reads a `@server` fragment in a server component. Returns synchronously * when the data is present; suspends until it arrives otherwise. */ readonly useServerFragment: { ( fragment: GraphQLTaggedNode, fragmentRef: TKey, ): KeyTypeData; ( fragment: GraphQLTaggedNode, fragmentRef: TKey, ): ArrayKeyTypeData; }; } type ServerKeyType = KeyType & Readonly<{ ' $serverFragment': true; }>; type ServerArrayKeyType = ReadonlyArray< ServerKeyType | null | undefined >; export interface ServerQueryOptions { readonly signal?: AbortSignal; } export function createServerEnvironment( create: () => IEnvironment, ): ServerEnvironment;