/** * This file exports types related specifically to GraphQL execution, most * notably `GraphQLRequest` and `GraphQLResponse`, used most heavily by * `executeHTTPGraphQLRequest` and `executeOperation`. The * `responseForOperation` plugin hook also returns a `GraphQLResponse`. */ import type { ExecutionArgs, ExecutionResult, FormattedExecutionResult, } from 'graphql'; import type { BaseContext } from './context.js'; import type { HTTPGraphQLHead, HTTPGraphQLRequest } from './http.js'; import type { WithRequired } from '@apollo/utils.withrequired'; import type { GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha2, GraphQLExperimentalFormattedSubsequentIncrementalExecutionResultAlpha2, } from './incrementalDeliveryPolyfillAlpha2.js'; import type { GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha9, GraphQLExperimentalFormattedSubsequentIncrementalExecutionResultAlpha9, } from './incrementalDeliveryPolyfillAlpha9.js'; import { type GraphQLExperimentalIncrementalExecutionResultsAlpha2 } from '../incrementalDeliveryPolyfill.js'; export interface GraphQLRequest< TVariables extends VariableValues = VariableValues, > { query?: string; operationName?: string; variables?: TVariables; extensions?: Record; http?: HTTPGraphQLRequest; } export type VariableValues = { [name: string]: any }; // A GraphQL response can either be a single result, or an initial result // followed by a stream of subsequent results. The latter occurs when the // GraphQL operation uses incremental delivery directives such as `@defer` or // `@stream`. Note that incremental delivery currently requires using a // pre-release of graphql-js v17. export type GraphQLResponseBody> = | { kind: 'single'; singleResult: FormattedExecutionResult; } | { kind: 'incremental'; initialResult: GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha2; subsequentResults: AsyncIterable; } | { kind: 'incremental'; initialResult: GraphQLExperimentalFormattedInitialIncrementalExecutionResultAlpha9; subsequentResults: AsyncIterable; }; export type GraphQLInProgressResponse> = { http: HTTPGraphQLHead; body?: GraphQLResponseBody; }; export type GraphQLResponse> = WithRequired< GraphQLInProgressResponse, 'body' >; export interface ExecuteOperationOptions { contextValue?: TContext; } type PromiseOrValue = Promise | T; export type LegacyExperimentalExecuteIncrementally< TData = Record, TExtensions = Record, > = ( args: ExecutionArgs, ) => PromiseOrValue< | ExecutionResult | GraphQLExperimentalIncrementalExecutionResultsAlpha2 >;