@@ -123,86 +123,98 @@ Application requests to most Azure services must be authorized. For the API for
123
123
124
124
1. Import the ` gremlin` module.
125
125
126
- ` ` ` javascript
127
- import gremlin from ' gremlin'
128
- ` ` `
126
+ :::code language=" javascript" source=" ~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id=" imports" :::
129
127
130
128
1. Create ` accountName` and ` accountKey` string variables. Store the ` COSMOS_GREMLIN_ENDPOINT` and ` COSMOS_GREMLIN_KEY` environment variables as the values for each respective variable.
131
129
132
- ` ` ` javascript
133
-
134
- ` ` `
130
+ :::code language=" javascript" source=" ~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id=" environment_variables" :::
135
131
136
132
1. Use ` PlainTextSaslAuthenticator` to create a new object for the account' s credentials.
137
133
138
- ```javascript
139
-
140
- ```
134
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="authenticate_client":::
141
135
142
- 1. Use `Client` to connect using the remote server credentials and the **GraphSON 2.0** serializer.
136
+ 1. Use `Client` to connect using the remote server credentials and the **GraphSON 2.0** serializer. Then, use `Open` to create a new connection to the server.
143
137
144
- ```javascript
145
-
146
- ```
138
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="connect_client":::
147
139
148
- 1. TODO
140
+ ## Create vertices
149
141
150
- ```javascript
151
-
152
- ```
142
+ Now that the application is connected to the account, use the standard Gremlin syntax to create vertices.
153
143
154
- 1. TODO
155
144
156
- ```javascript
157
-
158
- ```
145
+ 1. Use `submit` to run a command server-side on the API for Gremlin account. Create a **product** vertex with the following properties:
159
146
160
- 1. TODO
147
+ | | Value |
148
+ | --- | --- |
149
+ | **label** | `product` |
150
+ | **id** | `68719518371` |
151
+ | **`name`** | `Kiama classic surfboard` |
152
+ | **`price`** | `285.55` |
153
+ | **`category`** | `surfboards` |
161
154
162
- ```javascript
163
-
164
- ```
155
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_vertices_1":::
165
156
166
- 1. TODO
157
+ 1. Create a second **product** vertex with these properties:
167
158
168
- ```javascript
169
-
170
- ```
159
+ | | Value |
160
+ | --- | --- |
161
+ | **label** | `product` |
162
+ | **id** | `68719518403` |
163
+ | **`name`** | `Montau Turtle Surfboard` |
164
+ | **`price`** | `600.00` |
165
+ | **`category`** | `surfboards` |
171
166
172
- 1. TODO
167
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_vertices_2":::
173
168
174
- ```javascript
175
-
176
- ```
169
+ 1. Create a third **product** vertex with these properties:
177
170
178
- 1. TODO
171
+ | | Value |
172
+ | --- | --- |
173
+ | **label** | `product` |
174
+ | **id** | `68719518409` |
175
+ | **`name`** | `Bondi Twin Surfboard` |
176
+ | **`price`** | `585.50` |
177
+ | **`category`** | `surfboards` |
179
178
180
- ```javascript
181
-
182
- ```
179
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_vertices_3":::
183
180
184
- 1. TODO
181
+ ## Create edges
185
182
186
- ```javascript
187
-
188
- ```
183
+ Create edges using the Gremlin syntax to define relationships between vertices.
189
184
190
- 1. TODO
185
+ 1. Create an edge from the `Montau Turtle Surfboard` product named **replaces** to the `Kiama classic surfboard` product.
191
186
192
- ```javascript
193
-
194
- ```
187
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_edges_1":::
195
188
196
- 1. TODO
189
+ > [!TIP]
190
+ > This edge defintion uses the `g.V([' < partition-key> ' , ' < id> ' ])` syntax. Alternatively, you can use `g.V(' < id> ' ).has(' category' , ' < partition-key> ' )`.
197
191
198
- ```javascript
199
-
200
- ```
192
+ 1. Create another **replaces** edge from the same product to the `Bondi Twin Surfboard`.
193
+
194
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_edges_2":::
195
+
196
+ ## Query vertices & edges
197
+
198
+ Use the Gremlin syntax to traverse the graph and discover relationships between vertices.
199
+
200
+ 1. Traverse the graph and find all vertices that `Montau Turtle Surfboard` replaces.
201
+
202
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="query_vertices_edges":::
201
203
202
- 1. TODO
204
+ 1. Write to the console the result of this traversal.
203
205
204
- ```javascript
205
-
206
+ :::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="output_vertices_edges":::
207
+
208
+ ## Run the code
209
+
210
+ Validate that your application works as expected by running the application. The application should execute with no errors or warnings. The output of the application includes data about the created and queried items.
211
+
212
+ 1. Open the terminal in the Node.js project folder.
213
+
214
+ 1. Use `npm <script>` to run the application. Observe the output from the application.
215
+
216
+ ```bash
217
+ npm start
206
218
```
207
219
208
220
## Clean up resources
0 commit comments