|
1 | 1 | import { describe, it, expect } from "@effect/vitest"; |
2 | | -import { Effect } from "effect"; |
3 | | -import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"; |
| 2 | +import { Effect, Layer } from "effect"; |
| 3 | +import { |
| 4 | + HttpClient, |
| 5 | + HttpClientRequest, |
| 6 | + HttpClientResponse, |
| 7 | + HttpServerRequest, |
| 8 | + HttpServerResponse, |
| 9 | +} from "effect/unstable/http"; |
4 | 10 |
|
5 | 11 | import { |
6 | 12 | AuthTemplateSlug, |
@@ -318,6 +324,48 @@ describe("graphqlPlugin real protocol server", () => { |
318 | 324 | }), |
319 | 325 | ); |
320 | 326 |
|
| 327 | + it.effect("uses the executor HttpClient layer for connection-time introspection", () => |
| 328 | + Effect.gen(function* () { |
| 329 | + const seen: string[] = []; |
| 330 | + const httpClientLayer = Layer.succeed(HttpClient.HttpClient)( |
| 331 | + HttpClient.make((request: HttpClientRequest.HttpClientRequest) => { |
| 332 | + seen.push(request.url); |
| 333 | + return Effect.succeed( |
| 334 | + HttpClientResponse.fromWeb( |
| 335 | + request, |
| 336 | + new Response(JSON.stringify({ data: introspectionResult }), { |
| 337 | + status: 200, |
| 338 | + headers: { "content-type": "application/json" }, |
| 339 | + }), |
| 340 | + ), |
| 341 | + ); |
| 342 | + }), |
| 343 | + ); |
| 344 | + const config = makeTestConfig({ |
| 345 | + plugins: [memoryCredentialsPlugin(), graphqlPlugin()] as const, |
| 346 | + }); |
| 347 | + const executor = yield* createExecutor({ ...config, httpClientLayer }); |
| 348 | + |
| 349 | + yield* executor.graphql.addIntegration({ |
| 350 | + endpoint: "https://internal.example/graphql", |
| 351 | + slug: "guarded_graph", |
| 352 | + name: "Guarded Graph", |
| 353 | + }); |
| 354 | + yield* createOrgConnection(executor, { |
| 355 | + integration: "guarded_graph", |
| 356 | + name: "default", |
| 357 | + template: "none", |
| 358 | + value: "unused", |
| 359 | + }); |
| 360 | + |
| 361 | + const tools = yield* executor.tools.list(); |
| 362 | + expect(seen).toEqual(["https://internal.example/graphql"]); |
| 363 | + expect(tools.map((tool) => String(tool.name))).toEqual( |
| 364 | + expect.arrayContaining(["query.hello", "mutation.setGreeting"]), |
| 365 | + ); |
| 366 | + }), |
| 367 | + ); |
| 368 | + |
321 | 369 | it.effect("invokes a live query through an apiKey header template", () => |
322 | 370 | Effect.gen(function* () { |
323 | 371 | const server = yield* serveGreetingServer; |
|
0 commit comments