Data Sources

appsync-local supports multiple data source types that mirror AWS AppSync capabilities.

DynamoDB

Connect to local or remote DynamoDB tables.

Configuration

{
  "name": "UsersTable",
  "type": "DYNAMODB",
  "config": {
    "tableName": "Users",
    "region": "us-east-1",
    "endpoint": "http://localhost:8000"  // Optional: for DynamoDB Local
  }
}

Supported Operations

Example Resolver

export function request(ctx) {
  return {
    operation: 'Query',
    query: {
      expression: 'pk = :pk',
      expressionValues: {
        ':pk': { S: ctx.arguments.userId }
      }
    }
  };
}

export function response(ctx) {
  return ctx.result.items;
}

Lambda

Invoke Lambda functions (local JavaScript files).

Configuration

{
  "name": "UserService",
  "type": "LAMBDA",
  "config": {
    "functionName": "userService",
    "file": "lambdas/userService.js",
    "region": "us-east-1"
  }
}

Example Resolver

export function request(ctx) {
  return {
    operation: 'Invoke',
    payload: {
      action: 'getUser',
      userId: ctx.arguments.id
    }
  };
}

export function response(ctx) {
  return ctx.result;
}

Lambda Handler

// lambdas/userService.js
export async function handler(event) {
  if (event.action === 'getUser') {
    return { id: event.userId, name: 'John Doe' };
  }
}

HTTP

Make HTTP requests to external APIs.

Configuration

{
  "name": "ExternalAPI",
  "type": "HTTP",
  "config": {
    "endpoint": "https://api.example.com"
  }
}

Example Resolver

export function request(ctx) {
  return {
    method: 'GET',
    resourcePath: `/users/${ctx.arguments.id}`,
    params: {
      headers: {
        'Authorization': `Bearer ${ctx.request.headers.authorization}`
      }
    }
  };
}

export function response(ctx) {
  return JSON.parse(ctx.result.body);
}

RDS (PostgreSQL / MySQL)

Execute SQL queries against relational databases.

Configuration

{
  "name": "PostgresDB",
  "type": "RDS",
  "config": {
    "engine": "postgresql",
    "mode": "local",
    "host": "localhost",
    "port": 5432,
    "user": "postgres",
    "password": "password",
    "databaseName": "mydb",
    "ssl": false
  }
}

Supported Operations

Example Resolver

export function request(ctx) {
  return {
    operation: 'executeStatement',
    sql: 'SELECT * FROM users WHERE id = :id',
    variableMap: {
      id: ctx.arguments.id
    }
  };
}

export function response(ctx) {
  return ctx.result.records[0];
}

NONE

For resolvers that don't need a data source (local transformations).

Configuration

{
  "name": "LocalResolver",
  "type": "NONE"
}

Example Resolver

export function request(ctx) {
  return {};
}

export function response(ctx) {
  return {
    timestamp: ctx.util.time.nowISO8601(),
    requestId: ctx.util.autoId()
  };
}