| 1 | import type * as appsync from "@distilled.cloud/aws/appsync"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { GraphqlApi } from "./GraphqlApi.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Runtime binding for `appsync:GetIntrospectionSchema` — read a |
| 8 | * {@link GraphqlApi}'s live schema (SDL or introspection JSON) from a Lambda |
| 9 | * (or other AWS runtime), e.g. for schema registries, codegen services, or |
| 10 | * federation gateways that discover the schema at runtime. |
| 11 | * |
| 12 | * The response `schema` is a streaming body — collect it with |
| 13 | * `Stream.mkString(Stream.decodeText(response.schema!))`. Provide |
| 14 | * `AppSync.GetIntrospectionSchemaHttp` on the hosting function's Effect to |
| 15 | * implement the binding. |
| 16 | * |
| 17 | * ### Reading the Schema |
| 18 | * **Example:** Fetch the API's SDL at runtime |
| 19 | * ```typescript |
| 20 | * const getSchema = yield* AppSync.GetIntrospectionSchema(api); |
| 21 | * |
| 22 | * const response = yield* getSchema({ format: "SDL" }); |
| 23 | * const sdl = yield* Stream.mkString(Stream.decodeText(response.schema!)); |
| 24 | * ``` |
| 25 | * |
| 26 | * @binding |
| 27 | */ |
| 28 | export interface GetIntrospectionSchema extends Binding.Service< |
| 29 | GetIntrospectionSchema, |
| 30 | "AWS.AppSync.GetIntrospectionSchema", |
| 31 | ( |
| 32 | api: GraphqlApi, |
| 33 | ) => Effect.Effect< |
| 34 | ( |
| 35 | request: Omit<appsync.GetIntrospectionSchemaRequest, "apiId">, |
| 36 | ) => Effect.Effect< |
| 37 | appsync.GetIntrospectionSchemaResponse, |
| 38 | appsync.GetIntrospectionSchemaError |
| 39 | > |
| 40 | > |
| 41 | > {} |
| 42 | export const GetIntrospectionSchema = Binding.Service<GetIntrospectionSchema>( |
| 43 | "AWS.AppSync.GetIntrospectionSchema", |
| 44 | ); |