( operation: Op, chain: MiddlewareChain<Op>, protocol: GraphQLProtocol["Service"], retryPolicy: Schedule.Schedule<unknown, unknown> )
| 344 | options?.context ?? (Context.empty() as Context.Context<R2>) |
| 345 | |
| 346 | const makeMethod = <Op extends GraphQL.Any>( |
| 347 | operation: Op, |
| 348 | chain: MiddlewareChain<Op>, |
| 349 | protocol: GraphQLProtocol["Service"], |
| 350 | retryPolicy: Schedule.Schedule<unknown, unknown> |
| 351 | ): OperationMethod<Op> | SubscriptionMethod<Op> => { |
| 352 | const { decodePartial, decodeStrict, encodeVariables, fail, schemaFail } = internalGraphQL.makeCodec(operation) |
| 353 | |
| 354 | const notGraphQL = schemaFail((description) => |
| 355 | new DecodeError({ description: `Not a GraphQL response: ${description}` }) |
| 356 | ) |
| 357 | |
| 358 | const buildRequest = (variables: GraphQL.Variables<Op> | undefined, options: CallOptions | undefined) => |
| 359 | encodeVariables(variables).pipe( |
| 360 | Effect.map((encoded): GraphQLRequest => ({ |
| 361 | kind: operation.kind, |
| 362 | query: operation.document, |
| 363 | operationName: operation.name, |
| 364 | variables: encoded, |
| 365 | headers: Headers.fromInput(options?.headers), |
| 366 | urlParams: options?.urlParams === undefined ? UrlParams.empty : UrlParams.fromInput(options.urlParams) |
| 367 | })) |
| 368 | ) |
| 369 | |
| 370 | const decodeResponse = ({ body, ...metadata }: { |
| 371 | readonly body: unknown |
| 372 | readonly status?: number | undefined |
| 373 | readonly headers?: Headers.Headers | undefined |
| 374 | }) => |
| 375 | decodeExecutionResult(body).pipe( |
| 376 | Effect.map((result): ExecutionResult => ({ ...result, ...metadata })), |
| 377 | Effect.catch(notGraphQL) |
| 378 | ) |
| 379 | |
| 380 | // Type boundary: a middleware sees the errors of the middleware further in |
| 381 | // as `Types.unhandled` (as in `RpcMiddleware`), and none of their |
| 382 | // requirements. Those errors are part of `GraphQL.Error<Op>`, so the chain |
| 383 | // restates its type here. Force POST and the resolved URL apply only at the |
| 384 | // transport boundary. |
| 385 | const execute = ( |
| 386 | index: number, |
| 387 | request: GraphQLRequest, |
| 388 | forcePost: boolean, |
| 389 | resolvedUrl: internalGraphQL.ResolvedUrl |
| 390 | ): Effect.Effect<ExecutionResult, GraphQL.Error<Op>, GraphQLMiddleware.Requires<GraphQL.Middleware<Op>>> => |
| 391 | index === chain.length |
| 392 | ? protocol.execute(request).pipe( |
| 393 | forcePost ? Effect.provideService(internalGraphQL.ForcePost, true) : identity, |
| 394 | resolvedUrl === undefined ? identity : Effect.provideService(internalGraphQL.ResolvedUrl, resolvedUrl), |
| 395 | Effect.mapError(fail), |
| 396 | Effect.flatMap(decodeResponse) |
| 397 | ) |
| 398 | : chain[index].execute({ |
| 399 | operation, |
| 400 | request, |
| 401 | next: (request) => |
| 402 | execute(index + 1, request, forcePost, resolvedUrl) as Effect.Effect< |
| 403 | ExecutionResult, |
no test coverage detected