# 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:

- Created a Vendia **project** with a pre-defined data model with strong data typing
- Used GraphQL queries and mutations to both read from and write to your product catalog

## 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)](https://www.npmjs.com/get-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](https://www.npmjs.com/package/@vendia/share-cli) or view the [CLI commands list](https://docs.vendia.com/platform/cli).

### Register for Vendia

You will need to have a valid Vendia user in order to deploy this Quick Start. Please sign up for [Vendia](https://share.vendia.net/signup) 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-`](https://docs.vendia.com/platform/limits-and-quotas#project-and-workspace-names)

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`](https://docs.vendia.com/platform/cli/commands/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](https://share.vendia.net/). 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.
