Product Catalog Quick Start | Vendia

Product Catalog Quick Start

In this Quick Start, we will walk through how to model and create a Vendia project to store product information.

By the end of the Quick Start you will have:

Pre-requisites

This Quick Start uses the Vendia share-cli, a Command Line Interface (CLI) for creating and managing projects. We will be using the share-cli to deploy and manage our product catalog.

Command Line Installation

The share-cli can be installed using the NodeJS Node Package Manager(NPM).

To install the CLI globally, run the following command:

npm install @vendia/share-cli -g

NOTE You can also install the Vendia CLI inside of a project (instead of globally).

For more information, please visit the @vendia/share-cli NPM package page or view the CLI commands list.

Register for Vendia

You will need to have a valid Vendia user in order to deploy this Quick Start. Please sign up for Vendia if you have not already done so.

Step 1 - Prepare the Deployment Files for the Project

In this Quick Start, we have provided sample files including a data model for your use that describes product catalog data.

Save the Quick Start Files

The files listed below should be saved to your computer. For simplicity, save them all to the same directory.

Sample registration file - save as registration.json

The registration.json file defines the project name, location of the schema file, and the participants in the project.

{
  "name": "test-product-catalog",
  "schema": "schema.json",
  "nodes": [
    {
      "name": "ProductCatalog",
      "userId": "me@domain.com",
      "region": "us-east-2",
      "csp": "aws"
    }
  ]
}

NOTE: You will need to provide your Vendia userId when defining your workspace.

ANOTHER NOTE: Pick a unique name for your project that begins with test-

Sample schema file - save as schema.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://vendia.net/schemas/demos/product.json",
  "title": "Product",
  "description": "Product information",
  "x-vendia-indexes": {},
  "x-vendia-acls": {
    "ProductAcl": {
      "type": "Product"
    }
  },
  "type": "object",
  "properties": {
    "Product": {
      "description": "Product information",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "description": "Product name",
            "type": "string"
          },
          "sku": {
            "description": "Product SKU",
            "type": "string"
          },
          "description": {
            "description": "Product description",
            "type": "string"
          },
          "price": {
            "description": "Product price",
            "type": "number"
          },
          "tags": {
            "description": "Product tags",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "size": {
            "description": "Product size",
            "type": "string",
            "enum": ["S", "M", "L", "XL"]
          }
        },
        "required": [],
        "x-vendia-unique": []
      }
    }
  }
}

Step 2 - Command Line Deployment

Once the files are saved, deploy the project using the share-cli.

If not already logged in to the share service do so by running share login:

share login

The share uni create command can be used to deploy our project.

share uni create --config registration.json

Check on Project Status

The project deployment will take approximately 4 minutes. The status of the project deployment can be viewed by running the share get command.

NOTE: Your project name should differ from the example. Set the value of the --uni argument accordingly to match the Name property in registration.json.

% share get --uni test-product-catalog

Run Your First Query

The easiest way to interact with data in our shopping catalog project is to use the built-in GraphQL Explorer provided by the Vendia web interface. Each workspace in a project has its own GraphQL Explorer.

query listAllProducts {
  list_ProductItems {
    _ProductItems {
      _id
      name
      description
      sku
      price
      size
      tags
    }
  }
}

Step 4 - Create a New Entry in the Product Catalog

Now that we have queried our data, let’s go ahead and add a new entry to our catalog.

mutation addNewProduct {
  add_Product(
    input: {
      name: "Awesome Product 4000"
      description: "Description for Awesome Product 4000"
      price: 19.99
      size: L
      sku: "ap4000"
      tags: ["new-release", "wait-and-see"]
    }
    syncMode: ASYNC
  ) {
    transaction {
      _id
    }
  }
}

Step 5 - Try to Create a New Catalog Entry with Invalid Data

mutation addInvalidProduct {
  add_Product(
    input: {
      name: "Awesome Product 5000"
      description: "Description for Awesome Product 5000"
      price: 29.99
      size: XXXXL
      sku: "ap5000"
      tags: ["invalid-size", "should-not-be"]
    }
    syncMode: ASYNC
  ) {
    transaction {
      _id
    }
  }
}

Step 6 - Delete a Product

query getProduct3Id {
  list_ProductItems(filter: { name: { eq: "Awesome Product 3" } }) {
    _ProductItems {
      _id
      name
    }
  }
}
mutation removeAwesomeProduct3 {
  remove_Product(id: "017d103f-f7a3-09b0-2e4d-72c074e11142", syncMode: ASYNC) {
    transaction {
      _id
    }
  }
}

Step 7 - Cleanup

share uni delete --uni test-product-catalog --force

Summary and Next Steps

This Quick Start demonstrated the ease and speed of which Vendia can be leveraged to create serverless resources from a JSON Schema representation of your data model. Without providing anything other than the underlying model, Vendia was able to provide a strongly typed interface to your underlying data.