Skip to content

Commit 416b037

Browse files
committed
added usage section to aura graphql getting started, adjusted toolbox tutorial
1 parent 4aca8ce commit 416b037

File tree

6 files changed

+465
-577
lines changed

6 files changed

+465
-577
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*

modules/ROOT/pages/getting-started/api-creation.adoc

Lines changed: 0 additions & 161 deletions
This file was deleted.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
6+
== Create a GraphQL Data API
7+
8+
In the Aura Console, select **Data services** > **Data APIs** from the left side navigation.
9+
Use **Create API**.
10+
11+
12+
=== Details
13+
14+
Provide a name for your new API as well the instance data for the instance you want to use under **Details**.
15+
16+
[CAUTION]
17+
====
18+
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.
19+
20+
**Enable introspection** allows you to query the schema and discover the available queries, mutations, subscriptions, types and fields in the GraphQL API.
21+
22+
**Enable field suggestions** provides suggestions that hint towards GraphQL typos.
23+
Even with just field suggestions enabled, it is possible for a malicious actor to discover your entire schema.
24+
====
25+
26+
27+
=== Type definitions
28+
29+
Write or paste your **Type definitions**, for example:
30+
+
31+
[source, graphql, indent=0]
32+
----
33+
type Product @node {
34+
productName: String
35+
category: [Category!]! @relationship(type: "PART_OF", direction: OUT)
36+
}
37+
38+
type Category @node {
39+
categoryName: String
40+
products: [Product!]! @relationship(type: "PART_OF", direction: IN)
41+
}
42+
----
43+
44+
The type definitions describe what parts of the graph database in the AuraDB are accessible by requests made via the GraphQL API.
45+
46+
If you already have data in the AuraDB, you can obtain your type definitions via the https://graphql-toolbox.neo4j.io[Neo4j GraphQL Toolbox].
47+
The toolbox can connect to the AuraDB and automatically create type definitions and allow GraphQL operations.
48+
49+
//link
50+
If you are using GraphQL Federation then make sure to select **Enable GraphQL subgraph**.
51+
52+
53+
=== Cross-Origin Resource Sharing (CORS) policy
54+
55+
To use your GraphQL API with a browser-based application, add an entry in your Cross-Origin Resource Sharing (CORS) policy.
56+
CORS is a browser-based security mechanism that prevents web pages from accessing resources from a server with a different origin.
57+
58+
Add the URL `http://localhost:4000/` to the **Origin** box to enable the use of https://studio.apollographql.com/[Apollo Studio].
59+
If you need multiple entries, select **Add allowed origin**.
60+
61+
[NOTE]
62+
====
63+
The URL entered in the CORS policy must be an exact match.
64+
`http://localhost` is not the same as `http://localhost:4000/`.
65+
Wildcards are not supported.
66+
====
67+
68+
69+
=== Authentication providers
70+
71+
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).
72+
It is possible to use these in combination and have multiples of each.
73+
74+
Select an authentication provider from the dropdown list and enter a name.
75+
76+
The API key will be shown after the GraphQL API key has been created, see below.
77+
If you are using JWKS, provide a name and the URL from your identity provider that is used to verify JWKS tokens.
78+
79+
Add more more providers via **Add authentication provider**.
80+
Remove authentication providers via the trash icon.
81+
82+
[CAUTION]
83+
====
84+
It is not recommended to use API keys with user-facing applications that are using the GraphQL API.
85+
This is due to the risk of the API key being visible to malicious users and very little control over GraphQL operations.
86+
87+
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.
88+
====
89+
90+
91+
=== Sizing
92+
93+
Sizing a GraphQL API is based on the size and complexity of the type definitions and the expected workload.
94+
Larger sizes have a higher hourly cost.
95+
If the cost is not displayed, refer to the agreement you have with Neo4j.
96+
97+
Select **Create** to proceed and create the GraphQL API.
98+
99+
100+
== API key
101+
102+
If you chose to use an API key with the GraphQL API it is now displayed.
103+
Store this information securely as it cannot be retrieved again.
104+
Select **I understand** and then **Close** once you have done this.
105+
106+
The GraphQL API will now be provisioned.
107+
You can see the status via **Data APIs** from the left side navigation.
108+
When the status changes to "Ready", the API is ready to use.
109+
If it has a status of 'Error', use the three dots icon and **Edit** from the menu to change the configuration.
110+
111+
112+
== Usage
113+
114+
When the status for the GraphQL API is "Ready" you can send GraphQL requests to it.
115+
As all requests are subject to authentication, you must include an API key or JWT token.
116+
117+
With cURL, requests have the following format:
118+
119+
[source, bash, indent=0]
120+
----
121+
curl --location <YOUR_GRAPHQL_API_URL> --header 'Content-Type: application/json' --header 'x-api-key: <YOUR_API_KEY>' --data '<YOUR_GRAPHQL_QUERY>'
122+
----
123+
124+
[source, bash, indent=0]
125+
----
126+
curl --location <YOUR_GRAPHQL_API_URL> --header 'Authorization: Bearer <YOUR_JWT>'--header 'Content-Type: application/json --data '<YOUR_GRAPHQL_QUERY>'
127+
----
128+
129+
130+
=== Create nodes in the database
131+
132+
On the command line, execute:
133+
134+
[source, bash, indent=0]
135+
----
136+
curl --location --header 'Content-Type: application/json' --header 'x-api-key: <YOUR_API_KEY>' --data '<YOUR_GRAPHQL_QUERY>'
137+
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 } } }}" }'
138+
----
139+
140+
Verify by querying the data you just added:
141+
142+
[source, bash, indent=0]
143+
----
144+
curl --location https://4ea54ef6-graphql.production-orch-0969.neo4j.io/graphql --header 'Content-Type: application/json' --header 'x-api-key: dG0K4gBjDx4XEHpP0Ca7rKzToSUE3VcU' --data '{ "query": "query { products { productName category { categoryName } }}" }'
145+
----
146+
147+
You should see this:
148+
149+
[source, bash, indent=0]
150+
----
151+
{"data":{"products":[{"productName":"New Product","category":[{"categoryName":"New Category"}]}]}}
152+
----
153+
154+
This concludes the tutorial.
155+
You now have a GraphQL Data API connected to a Neo4j AuraDB and you have added two nodes.
156+
157+
To learn more, see xref:queries-aggregations/index.adoc[Queries and aggregations] and xref:getting-started/toolbox.adoc[Neo4j GraphQL Toolbox].
158+
For more advanced database settings, refer to xref:driver-configuration.adoc[Driver configuration].
159+
160+
// Edit at: https://github.com/neo4j-graphacademy/courses/blob/main/asciidoc/courses/graphql-basics/promo.adoc
161+
include::https://raw.githubusercontent.com/neo4j-graphacademy/courses/main/asciidoc/courses/graphql-basics/promo.adoc[]

0 commit comments

Comments
 (0)