Skip to content

Commit 5eae1aa

Browse files
committed
review suggestions
1 parent a050b3c commit 5eae1aa

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

modules/ROOT/pages/northwind-api.adoc

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[northwind-api]]
2-
= Creating an API for the Northwind data set
2+
= GraphQL modelling for the Northwind data set
33
:description: This tutorial builds an API around the Northwind sample data set with the Neo4j GraphQL Library.
44

5-
This tutorial uses the Neo4j GraphQL Library to build an API for the Northwind sample datset.
5+
This tutorial uses the Neo4j GraphQL Library to build an API for the Northwind sample dataset.
66

77
The Northwind set includes but is not limited to data about products, suppliers, orders and customers.
88
This model lends itself for a webshop API.
@@ -14,14 +14,16 @@ This model lends itself for a webshop API.
1414
Refer to link:https://neo4j.com/docs/aura/getting-started/create-instance/[Creating a Neo4j Aura instance].
1515
. Populate the instance with the Northwind data set.
1616
+
17-
[NOTE]
18-
====
1917
If you have completed the GraphQL and Aura Console getting started guide and would like to get rid of the example nodes you have created there, run the following in **Query** before populating your data base with the Northwind set:
20-
18+
+
2119
[source,cypher]
2220
----
2321
MATCH (n) DETACH DELETE n;
2422
----
23+
+
24+
[CAUTION]
25+
====
26+
This Cypher query deletes all data in your database.
2527
====
2628
+
2729
.. In Aura, select **Learning**, then **Beginner** under **Getting started**.
@@ -168,32 +170,17 @@ mutation {
168170
}
169171
----
170172

171-
To make it generic, pipe the `contactName` from an input into the query and send the request:
173+
To make it generic, you can use a link:https://graphql.org/learn/queries/#variables[GraphQL variable] to set the contactName dynamically:
172174

173175
[source, javascript, indent=0]
174176
----
175-
async function createCustomer(contactName) {
176-
const mutation = `
177-
mutation CreateCustomer($contactName: String!) {
178-
createCustomers(input: [{ contactName: $contactName }]) {
179-
customers {
180-
contactName
181-
customerID
182-
}
183-
}
177+
mutation CreateCustomer($contactName: String!) {
178+
createCustomers(input: [{ contactName: $contactName }]) {
179+
customers {
180+
contactName
181+
customerID
184182
}
185-
`;
186-
187-
const res = await fetch(API_URL, {
188-
method: 'POST',
189-
headers: {
190-
'Content-Type': 'application/json',
191-
},
192-
body: JSON.stringify({ query: mutation, variables: { contactName } }),
193-
});
194-
195-
const json = await res.json();
196-
return json;
183+
}
197184
}
198185
----
199186

@@ -225,11 +212,8 @@ mutation {
225212
}
226213
----
227214

228-
Note that the `orderID` is modeled as a UUID and therefore differs from the order IDs on orders that were already part of the Northwind data set.
229-
The data model could be extended to account for that by keeping track of the order IDs in a separate system, making sure that the IDs are unique.
230-
231-
The products, how many of each of them as well as the customer who places the order must be known.
232-
A shopping basket typically hands this information to the routine that is placing the order:
215+
To place an order, the customer and product information must already be known or collected.
216+
A shopping basket can be implemented as follows:
233217

234218
[source, javascript, indent=0]
235219
----
@@ -239,9 +223,8 @@ A shopping basket typically hands this information to the routine that is placin
239223

240224
=== Calculate prices for orders
241225

242-
Calculating the price of an order is achieved by accessing the `unitPrice` and `quantity` fields of the products that share the `ORDERS` relationship with the order.
243-
244-
Retrieve an order by its ID as well as the products associated with it:
226+
To calculate order prices, query the `order` operation field and filter the orders by using the `orderID` filter.
227+
Then access the relationship properties `quantity` and `unitPrice` from the relationships `ORDERS` that connect the `Order` and the `Product` node:
245228

246229
[source, graphql, indent=0]
247230
----

0 commit comments

Comments
 (0)