Skip to main content
Version: PromptQL

Lambda Connector Types

Lambda connectors written in TypeScript, Python, or Go can accept and return native types that map to NDC data model types. Below are examples of supported types in each language.

For information about setting up your lambda connectors, see Add a Lambda Connector.

When creating TypeScript lambda functions, you can use the following types for parameters and return values:

Basic scalar types

  • string - Maps to NDC scalar type: String
  • number - Maps to NDC scalar type: Float
  • boolean - Maps to NDC scalar type: Boolean
  • bigint - Maps to NDC scalar type: BigInt (represented as a string in JSON)
  • Date - Maps to NDC scalar type: DateTime (represented as an ISO formatted string in JSON)
/**
* Example of basic scalar types
* @readonly
*/
export function calculateAge(birthDate: Date, currentYear: number): number {
return currentYear - birthDate.getFullYear();
}

Object types and interfaces

You can define custom object types and interfaces:

type User = {
id: string;
name: string;
age: number;
};

interface Response {
success: boolean;
data: string;
}

/**
* Example using custom types
* @readonly
*/
export function processUser(user: User): Response {
return {
success: true,
data: `User ${user.name} is ${user.age} years old`,
};
}

Arrays

Arrays of a single type are supported:

/**
* Example using array types
* @readonly
*/
export function sumNumbers(numbers: number[]): number {
return numbers.reduce((sum, num) => sum + num, 0);
}

Null, undefined, and optional properties

You can use null, undefined, or make properties optional:

/**
* Example with optional and nullable parameters
* @readonly
*/
export function formatName(firstName: string, lastName?: string, title: string | null = null): string {
const formattedTitle = title ? `${title} ` : "";
const formattedLastName = lastName ? ` ${lastName}` : "";
return `${formattedTitle}${firstName}${formattedLastName}`;
}

Arbitrary JSON

You can import JSONValue from the SDK to accept and return arbitrary JSON:

import * as sdk from "@hasura/ndc-lambda-sdk";

/**
* Example using JSONValue for arbitrary JSON
* @readonly
*/
export function transformData(data: sdk.JSONValue): sdk.JSONValue {
// Process the JSON data
return new sdk.JSONValue({ processed: true, original: data.value });
}

Error handling

You can throw custom errors for better error handling:

import * as sdk from "@hasura/ndc-lambda-sdk";

/**
* Example with error handling
* @readonly
*/
export function divide(a: number, b: number): number {
if (b === 0) {
throw new sdk.UnprocessableContent("Cannot divide by zero", { a, b });
}
return a / b;
}