Skip to content

Commit b7b3453

Browse files
authored
Merge pull request #273 from neo4j/rework-getting-started-pages
Rework getting started pages
2 parents eef3ac0 + c298ef5 commit b7b3453

14 files changed

+595
-325
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* *Getting started*
44
55
* xref:getting-started/index.adoc[]
6+
** xref:getting-started/graphql-aura.adoc[]
7+
** xref:getting-started/graphql-self-hosted.adoc[]
68
* xref:getting-started/toolbox.adoc[]
79
810
* *Reference*
Binary file not shown.
-73.8 KB
Binary file not shown.
-1023 Bytes
Loading
-198 KB
Loading
-151 KB
Loading

modules/ROOT/pages/directives/custom-logic.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ type Movie @limit(max: 100, default: 10) @node {
334334

335335
== `@customResolver`
336336

337+
[NOTE]
338+
====
339+
Data APIs created in Aura Console currently do not support custom resolvers.
340+
====
341+
337342
The Neo4j GraphQL Library generates query and mutation resolvers, so you don't need to implement them yourself.
338343
However, if you need additional behaviors besides the autogenerated CRUD operations, you can specify custom resolvers for these scenarios.
339344

@@ -493,6 +498,11 @@ type Journal implements Publication @node {
493498

494499
== `@populatedBy`
495500

501+
[NOTE]
502+
====
503+
Data APIs created in Aura Console currently do not support the `@populatedBy` directive.
504+
====
505+
496506
This directive is used to specify a callback function, which is executed during GraphQL query parsing,
497507
to populate fields which have not been provided within the input.
498508

modules/ROOT/pages/directives/indexes-and-constraints.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ query {
168168
[#_vector_index_search]
169169
== `@vector`
170170

171+
[NOTE]
172+
====
173+
Data APIs created in Aura Console currently do not support the `@vector` directive.
174+
====
175+
171176
With the `@vector` GraphQL directive you can query your database to perform a vector index search.
172177
Queries are performed by passing in either a vector index or a query phrase.
173178

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
= GraphQL and Aura Console
2+
3+
This tutorial shows you how to create and use a GraphQL Data API in Aura Console.
4+
5+
== Prerequisites
6+
7+
Set up an AuraDB instance.
8+
Refer to link:https://neo4j.com/docs/aura/getting-started/create-instance/[Creating a Neo4j Aura instance].
9+
10+
11+
== Create a GraphQL Data API
12+
13+
In the Aura Console, select **Data services** > **Data APIs** from the left side navigation and then **Create API**.
14+
15+
16+
=== Details
17+
18+
Provide a name for your new API as well the instance data for the instance you want to use under **Details**.
19+
Also do **Enable introspection** and **Enable field suggestions** for use with xref:#_via_apollo_server[Apollo Server].
20+
21+
[CAUTION]
22+
====
23+
If you set **Enable introspection** and **Enable field suggestions** for production systems the information they provide can be used by malicious actors to reverse-engineer your GraphQL schema and execute arbitrary operations.
24+
25+
**Enable introspection** allows you to query the schema and discover the available queries, mutations, subscriptions, types and fields in the GraphQL API.
26+
27+
**Enable field suggestions** provides suggestions that hint towards GraphQL typos.
28+
Even with just field suggestions enabled, it is possible for a malicious actor to discover your entire schema.
29+
====
30+
31+
32+
=== Type definitions
33+
34+
Paste these **Type definitions**:
35+
[source, graphql, indent=0]
36+
----
37+
type Product @node {
38+
productName: String
39+
category: [Category!]! @relationship(type: "PART_OF", direction: OUT)
40+
}
41+
42+
type Category @node {
43+
categoryName: String
44+
products: [Product!]! @relationship(type: "PART_OF", direction: IN)
45+
}
46+
----
47+
48+
The type definitions describe what parts of the graph database in the AuraDB are accessible by requests made via the GraphQL API.
49+
50+
Alternatively, if you already have data in the AuraDB, you can obtain your type definitions via the https://graphql-toolbox.neo4j.io[Neo4j GraphQL Toolbox].
51+
The toolbox can connect to the AuraDB and automatically create type definitions and allow GraphQL operations.
52+
53+
If you are using link:https://graphql.org/learn/federation/[GraphQL Federation] then make sure to select **Enable GraphQL subgraph**.
54+
55+
56+
=== Cross-Origin Resource Sharing (CORS) policy
57+
58+
To use your GraphQL API with a browser-based application, add an entry in your Cross-Origin Resource Sharing (CORS) policy.
59+
CORS is a browser-based security mechanism that prevents web pages from accessing resources from a server with a different origin.
60+
61+
Add the URL `https://studio.apollographql.com` to the **Origin** box to enable the use of https://studio.apollographql.com/[Apollo Studio].
62+
If you need more entries, **Add allowed origin** for those.
63+
64+
[NOTE]
65+
====
66+
The URL entered in the CORS policy must be an exact match.
67+
Wildcards are not supported.
68+
====
69+
70+
71+
=== Authentication providers
72+
73+
All requests to the GraphQL API are authenticated and there are two options for the type of authentication: API key or JSON Web Key Set (JWKS).
74+
It is possible to set up multiple authentication providers and select a different one for each request.
75+
76+
For the purpose of this tutorial, avoid setting up a JWKS endpoint, select **API Key** from the dropdown list and enter a name.
77+
The API key will be shown after the GraphQL API key has been created.
78+
79+
[CAUTION]
80+
====
81+
It is not recommended to use API keys with user-facing applications that are using the GraphQL API.
82+
This is due to the risk of the API key being visible to malicious users and very little control over GraphQL operations.
83+
84+
A 3rd party identity provider with JWKS provides better security and allows for granular security rules, based on information within the JWKS token, to be defined within the type definitions to control GraphQL operations.
85+
====
86+
87+
88+
=== Sizing
89+
90+
Sizing a GraphQL API is based on the size and complexity of the type definitions and the expected workload.
91+
Larger sizes have a higher hourly cost.
92+
If the cost is not displayed, refer to the agreement you have with Neo4j.
93+
94+
95+
== API key
96+
97+
**Create** the GraphQL API.
98+
99+
Your API key is now displayed.
100+
Store this information securely as it cannot be retrieved again.
101+
Confirm with **I understand** and **Close**.
102+
103+
The GraphQL API will be provisioned.
104+
You can see the status via **Data APIs** from the left side navigation.
105+
106+
107+
== Create nodes in the database
108+
109+
When the status for the GraphQL API is **Ready** you can send GraphQL requests to it.
110+
111+
112+
=== Via cURL
113+
114+
[source, bash, indent=0]
115+
----
116+
curl --location <YOUR_GRAPHQL_API_URL> --header 'Content-Type: application/json' --header 'x-api-key: <YOUR_API_KEY>' --data '{ "query": "<YOUR_GRAPHQL_QUERY>" }'
117+
----
118+
119+
On the command line, execute:
120+
121+
[source, bash, indent=0]
122+
----
123+
curl --location <YOUR_GRAPHQL_API_URL> --header 'Content-Type: application/json' --header 'x-api-key: <YOUR_API_KEY>' --data '{ "query": "mutation { createProducts( input: [ { productName: \"New Product\" category: { create: [ { node: { categoryName: \"New Category\" } } ] } } ] ) { products { productName category { categoryName } } } }" }'
124+
----
125+
126+
Verify by querying the data you just added:
127+
128+
[source, bash, indent=0]
129+
----
130+
curl --location <YOUR_GRAPHQL_API_URL> --header 'Content-Type: application/json' --header 'x-api-key: <YOUR_API_KEY>' --data '{ "query": "query { products { productName category { categoryName } } }" }'
131+
----
132+
133+
You should see this:
134+
135+
[source, bash, indent=0]
136+
----
137+
{ "data": { "products": [ { "productName": "New Product", "category": [{ "categoryName": "New Category" }] } ] } }
138+
----
139+
140+
141+
=== Via Apollo Server
142+
143+
. On the https://studio.apollographql.com/sandbox/explorer[Apollo Studio] website, paste your GraphQL Data API URL to the **Sandbox** input.
144+
. Use the cog icon and add `x-api-key` and the API key for your data API under **Shared headers** and **Save**.
145+
. To start adding data, copy and paste the following mutation to the **Operation** panel to create a product and category in that product:
146+
+
147+
[source, graphql, indent=0]
148+
----
149+
mutation {
150+
createProducts(
151+
input: [
152+
{
153+
productName: "New Product"
154+
category: { create: [{ node: { categoryName: "New Category" } }] }
155+
}
156+
]
157+
) {
158+
products {
159+
productName
160+
category {
161+
categoryName
162+
}
163+
}
164+
}
165+
}
166+
----
167+
168+
. Use **Run** on the top right.
169+
You should get the following confirmation that the data has been created in the database in the **Response** panel:
170+
+
171+
[source, json, indent=0]
172+
----
173+
{
174+
"data": {
175+
"createProducts": {
176+
"products": [
177+
{
178+
"productName": "New Product",
179+
"category": [
180+
{
181+
"categoryName": "New Category"
182+
}
183+
]
184+
}
185+
]
186+
}
187+
}
188+
}
189+
----
190+
191+
. Query the data you just added.
192+
Copy and paste the following query to the **Operations** panel:
193+
+
194+
[source, graphql, indent=0]
195+
----
196+
query {
197+
products {
198+
productName
199+
category {
200+
categoryName
201+
}
202+
}
203+
}
204+
----
205+
+
206+
Since you only created one "Product" node and one "Category" node, the **Response** panel shows the following:
207+
+
208+
[source, json, indent=0]
209+
----
210+
{
211+
"data": {
212+
"products": [
213+
{
214+
"productName": "New Product",
215+
"category": [
216+
{
217+
"categoryName": "New Category"
218+
}
219+
]
220+
}
221+
]
222+
}
223+
}
224+
----
225+
226+
227+
This concludes the tutorial.
228+
You now have a GraphQL Data API connected to a Neo4j AuraDB and you have added two nodes.
229+
230+
To learn more, see xref:queries-aggregations/index.adoc[Queries and aggregations] and xref:getting-started/toolbox.adoc[Neo4j GraphQL Toolbox].
231+
For more advanced database settings, refer to xref:driver-configuration.adoc[Driver configuration].
232+
233+
// Edit at: https://github.com/neo4j-graphacademy/courses/blob/main/asciidoc/courses/graphql-basics/promo.adoc
234+
include::https://raw.githubusercontent.com/neo4j-graphacademy/courses/main/asciidoc/courses/graphql-basics/promo.adoc[]

0 commit comments

Comments
 (0)