|
| 1 | +[[northwind-api]] |
| 2 | += Creating an API for the Northwind dataset |
| 3 | +:description: This tutorial builds an API around the Northwind sample dataset with the Neo4j GraphQL Library. |
| 4 | + |
| 5 | +This tutorial uses the Neo4j GraphQL Library to build an API for the Northwind sample datset. |
| 6 | + |
| 7 | +The Northwind set includes but is not limited to data about products, suppliers, orders and customers. |
| 8 | +This model lends itself for a webshop API. |
| 9 | + |
| 10 | + |
| 11 | +== Prerequisites |
| 12 | + |
| 13 | +. Set up a new AuraDB instance. |
| 14 | +Refer to link:https://neo4j.com/docs/aura/getting-started/create-instance/[Creating a Neo4j Aura instance]. |
| 15 | +. Populate the instance with the Northwind dataset. |
| 16 | +.. In Aura, select **Learning**, then **Beginner** under **Getting started**. |
| 17 | +.. Select the **Learn the basics** tile and scroll to page 4/11 in the left side menu. |
| 18 | +.. Trigger the import with **Get the Northwind datset** and then **Run import** on the right hand side. |
| 19 | + |
| 20 | +[NOTE] |
| 21 | +==== |
| 22 | +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**: |
| 23 | +
|
| 24 | +[source,cypher] |
| 25 | +---- |
| 26 | +MATCH (n) DETACH DELETE n; |
| 27 | +---- |
| 28 | +==== |
| 29 | + |
| 30 | + |
| 31 | +== Goal |
| 32 | + |
| 33 | +A webshop API which connects to the Northwind dataset should be able to: |
| 34 | + |
| 35 | +* Create new customers |
| 36 | +* Place orders |
| 37 | +* Calculate prices for orders |
| 38 | +* Filter products by supplier and category |
| 39 | + |
| 40 | + |
| 41 | +== Type definitions |
| 42 | + |
| 43 | +First, make the nodes and relationships from xref:#_goal[] available: |
| 44 | + |
| 45 | +[source, graphql, indent=0] |
| 46 | +---- |
| 47 | +type Customer @node { |
| 48 | + contactName: String! |
| 49 | + orders: [Order!]! @relationship(type: "PURCHASED", direction: OUT) |
| 50 | +} |
| 51 | +
|
| 52 | +type Order @node { |
| 53 | + orderID: Int! |
| 54 | + customer: [Customer!]! @relationship(type: "PURCHASED", direction: IN) |
| 55 | + products: [Product!]! @relationship(type: "ORDERS", direction: OUT) |
| 56 | +} |
| 57 | +
|
| 58 | +type Product @node { |
| 59 | + productName: String! |
| 60 | + category: [Category!]! @relationship(type: "PART_OF", direction: OUT) |
| 61 | + orders: [Product!]! @relationship(type: "ORDERS", direction: IN) |
| 62 | + supplier: [Supplier!]! @relationship(type: "SUPPLIES", direction: IN) |
| 63 | +} |
| 64 | +
|
| 65 | +type Category @node { |
| 66 | + categoryName: String! |
| 67 | + products: [Product!]! @relationship(type: "PART_OF", direction: IN) |
| 68 | +} |
| 69 | +
|
| 70 | +type Supplier @node { |
| 71 | + supplierID: Int! |
| 72 | + companyName: String! |
| 73 | + products: [Product!]! @relationship(type: "SUPPLIES", direction: OUT) |
| 74 | +} |
| 75 | +
|
| 76 | +type ordersProperties @relationshipProperties { |
| 77 | + unitPrice: Float! |
| 78 | + quantity: Int! |
| 79 | +} |
| 80 | +---- |
| 81 | + |
0 commit comments