Skip to main content

Depot-Local

Depot supports running its Connector component locally, in order to perform tests in isolation with any deployed database (on locations where feasible). And by using lambda or GQL apis, operations can be run on it. To run depot locally, you need to have Docker installed and running.

Setup

To run depot-local install @stage-tech/depot-local as dependency in your project.

Depot-local can be configured with the following options:

import {DepotLocal} from "@stage-tech/depot-local";

const depot = new DepotLocal({
depot: {}, //required and is used to pass additional configuration to depot
dynamodb: {}, //required and is used to pass additional configuration to dynamodb
postgres: {}, //Optional and is used to pass additional configuration to postgres
snowflake: {} //Optional and is used to pass additional configuration to snowflake
});

after configuring depot-local, you can start it with depot.start() and stop it with depot.stop()

beforeAll(async () => {
await depot.start();
});

afterAll(async () => {
await depot.stop();
});

Usage

Once started, you can deploy a new Environment to your Depot local instance, to do so you need to use depot.deploy() method. Use a helper method to easily construct an environment, for example from a namespace.

const namespace = Schemas.fromYamlFiles("test/schema/pet.yml");// Usually this is done in depot package and imported from there
const environment = new EnvironmentBuilder(namespace)
.location(LocationBuilder.postgresDb(depotLocal))
.build();
const deployedEnv = depot.deploy(environment);

APIs

Depot local supports two types of APIs, lambda and GQL.

lambda API

To get lambda api you need to call const api = deployedEnv.api(0)

when you have the api you can use it to make requests to your environment either by unstructured request

const create = await api.create({
schema: "pet",
table: "pet",
data: {
name: "dog",
age: 1
}
});

or by using depot lambda client

GQL API

To get GQL api you need to call const gqlApi = deployedEnv.gqlApi(0)

when you have the api you can use it to make requests to your environment by using Apollo client

const create = await gqlApi.mutate<PetStore, PetStore>({
mutation: gql`
mutation createPet($name: String!, $age: Int!) {
createPetPet(id: "0987", data: { name: $name, age: $age }, expressions: {}) {
id
created
updated
schema
version
hash
name
}
}
`,
variables: {
name: "ren",
age: 2
},
context: {
headers: {Authorization: "Bearer token1"}
}
});

FIXME: complete this with samples showcasing the "borrow pattern" + update the admonitions in the leaf pages