From 3f4bd27be43601acbb3e29497eb778a73968ae2d Mon Sep 17 00:00:00 2001 From: Lyndon Maydwell Date: Mon, 19 Aug 2024 15:11:07 +1000 Subject: [PATCH] New type for representing the Supergraph connection details: Supergraph; Added toJSON method to JSONValue to have JSON.stringify work correctly. --- ndc-lambda-sdk/src/execution.ts | 7 +++++++ ndc-lambda-sdk/src/schema.ts | 4 ++++ ndc-lambda-sdk/src/sdk.ts | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ndc-lambda-sdk/src/execution.ts b/ndc-lambda-sdk/src/execution.ts index c3e2964..ee4b5fc 100644 --- a/ndc-lambda-sdk/src/execution.ts +++ b/ndc-lambda-sdk/src/execution.ts @@ -202,6 +202,13 @@ export function getErrorDetails(error: Error): ErrorDetails { } } +// NOTE: This should be provided by the NDC SDK types at some point +// then this can be replaced and won't have to be kept in sync +// manually with the engine changes. +export type Supergraph = { + endpoint: string +} + function buildCausalStackTrace(error: Error): string { let seenErrs: Error[] = []; let currErr: Error | undefined = error; diff --git a/ndc-lambda-sdk/src/schema.ts b/ndc-lambda-sdk/src/schema.ts index cb9f018..0f5f0a0 100644 --- a/ndc-lambda-sdk/src/schema.ts +++ b/ndc-lambda-sdk/src/schema.ts @@ -189,6 +189,10 @@ export class JSONValue { return this.#value; } + get toJSON(): unknown { + return this.#value; + } + /** * @internal */ diff --git a/ndc-lambda-sdk/src/sdk.ts b/ndc-lambda-sdk/src/sdk.ts index 4328082..4b7807e 100644 --- a/ndc-lambda-sdk/src/sdk.ts +++ b/ndc-lambda-sdk/src/sdk.ts @@ -1,4 +1,4 @@ export { JSONValue } from "./schema"; export { ConnectorError, BadRequest, Forbidden, Conflict, UnprocessableContent, InternalServerError, NotSupported, BadGateway } from "@hasura/ndc-sdk-typescript"; export { withActiveSpan, USER_VISIBLE_SPAN_ATTRIBUTE } from "@hasura/ndc-sdk-typescript/instrumentation" -export { ErrorDetails, getErrorDetails } from "./execution"; +export { ErrorDetails, getErrorDetails, Supergraph } from "./execution";