-
Notifications
You must be signed in to change notification settings - Fork 13
Rework getting started pages #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.x
Are you sure you want to change the base?
Changes from all commits
a4cc094
4aca8ce
416b037
6307df8
8d6d090
e184522
70ec2db
2f8b79b
f6f0b67
c1e6c05
29b26eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
= GraphQL and Aura Console | ||
|
||
This tutorial shows you how to create and use a GraphQL Data API in Aura Console. | ||
|
||
|
||
== Create a GraphQL Data API | ||
|
||
In the Aura Console, select **Data services** > **Data APIs** from the left side navigation and then **Create API**. | ||
|
||
|
||
=== Details | ||
|
||
Provide a name for your new API as well the instance data for the instance you want to use under **Details**. | ||
Also do **Enable introspection** and **Enable field suggestions** for use with xref:#_via_apollo_server[Apollo Server]. | ||
|
||
[CAUTION] | ||
==== | ||
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. | ||
|
||
**Enable introspection** allows you to query the schema and discover the available queries, mutations, subscriptions, types and fields in the GraphQL API. | ||
|
||
**Enable field suggestions** provides suggestions that hint towards GraphQL typos. | ||
Even with just field suggestions enabled, it is possible for a malicious actor to discover your entire schema. | ||
==== | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing as you describe how to use apollo studio later on in this guide it might also be good to tell users to create the API with introspection & field suggestions enabled (this then means they can see other queries/filters they can use within apollo studio and will get corrected if they make a typo) There are security risks to consider when these are enabled in production so it would also be good to include a warning. There should be something like that in the existing docs that you can borrow from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah looks like there's a warning here: https://neo4j.com/docs/graphql/current/aura-graphql/api-creation/#_console There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i copied the caution box - does that suffice? :) |
||
|
||
=== Type definitions | ||
|
||
Paste these **Type definitions**: | ||
[source, graphql, indent=0] | ||
---- | ||
type Product @node { | ||
productName: String | ||
category: [Category!]! @relationship(type: "PART_OF", direction: OUT) | ||
} | ||
|
||
type Category @node { | ||
categoryName: String | ||
products: [Product!]! @relationship(type: "PART_OF", direction: IN) | ||
} | ||
---- | ||
|
||
The type definitions describe what parts of the graph database in the AuraDB are accessible by requests made via the GraphQL API. | ||
|
||
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]. | ||
The toolbox can connect to the AuraDB and automatically create type definitions and allow GraphQL operations. | ||
Comment on lines
+45
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to note we want to have the introspection feature in the Aura console soon, so this will need to be updated to reflect that when it's added. |
||
|
||
If you are using link:https://graphql.org/learn/federation/[GraphQL Federation] then make sure to select **Enable GraphQL subgraph**. | ||
|
||
|
||
=== Cross-Origin Resource Sharing (CORS) policy | ||
|
||
To use your GraphQL API with a browser-based application, add an entry in your Cross-Origin Resource Sharing (CORS) policy. | ||
CORS is a browser-based security mechanism that prevents web pages from accessing resources from a server with a different origin. | ||
|
||
Add the URL `https://studio.apollographql.com` to the **Origin** box to enable the use of https://studio.apollographql.com/[Apollo Studio]. | ||
If you need more entries, **Add allowed origin** for those. | ||
|
||
[NOTE] | ||
==== | ||
The URL entered in the CORS policy must be an exact match. | ||
Wildcards are not supported. | ||
==== | ||
|
||
|
||
=== Authentication providers | ||
|
||
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). | ||
It is possible to set up multiple authentication providers and select a different one for each request. | ||
|
||
For the purpose of this tutorial, avoid setting up a JWKS endpoint, select **API Key** from the dropdown list and enter a name. | ||
The API key will be shown after the GraphQL API key has been created. | ||
|
||
[CAUTION] | ||
==== | ||
It is not recommended to use API keys with user-facing applications that are using the GraphQL API. | ||
This is due to the risk of the API key being visible to malicious users and very little control over GraphQL operations. | ||
|
||
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. | ||
==== | ||
|
||
|
||
=== Sizing | ||
|
||
Sizing a GraphQL API is based on the size and complexity of the type definitions and the expected workload. | ||
Larger sizes have a higher hourly cost. | ||
If the cost is not displayed, refer to the agreement you have with Neo4j. | ||
|
||
|
||
== API key | ||
|
||
**Create** the GraphQL API. | ||
|
||
Your API key is now displayed. | ||
Store this information securely as it cannot be retrieved again. | ||
Confirm with **I understand** and **Close**. | ||
|
||
The GraphQL API will be provisioned. | ||
You can see the status via **Data APIs** from the left side navigation. | ||
|
||
|
||
== Create nodes in the database | ||
|
||
When the status for the GraphQL API is **Ready** you can send GraphQL requests to it. | ||
|
||
|
||
=== Via cURL | ||
|
||
[source, bash, indent=0] | ||
---- | ||
curl --location <YOUR_GRAPHQL_API_URL> --header 'Content-Type: application/json' --header 'x-api-key: <YOUR_API_KEY>' --data '{ "query": "<YOUR_GRAPHQL_QUERY>" }' | ||
---- | ||
|
||
On the command line, execute: | ||
|
||
[source, bash, indent=0] | ||
---- | ||
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 } } } }" }' | ||
---- | ||
|
||
Verify by querying the data you just added: | ||
|
||
[source, bash, indent=0] | ||
---- | ||
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 } } }" }' | ||
---- | ||
|
||
You should see this: | ||
|
||
[source, bash, indent=0] | ||
---- | ||
{ "data": { "products": [ { "productName": "New Product", "category": [{ "categoryName": "New Category" }] } ] } } | ||
---- | ||
|
||
|
||
=== Via Apollo Server | ||
|
||
. On the https://studio.apollographql.com/sandbox/explorer[Apollo Studio] website, paste your GraphQL Data API URL to the **Sandbox** input. | ||
. Use the cog icon and add `x-api-key` and the API key for your data API under **Shared headers** and **Save**. | ||
. To start adding data, copy and paste the following mutation to the **Operation** panel to create a product and category in that product: | ||
+ | ||
[source, graphql, indent=0] | ||
---- | ||
mutation { | ||
createProducts( | ||
input: [ | ||
{ | ||
productName: "New Product" | ||
category: { create: [{ node: { categoryName: "New Category" } }] } | ||
} | ||
] | ||
) { | ||
products { | ||
productName | ||
category { | ||
categoryName | ||
} | ||
} | ||
} | ||
} | ||
---- | ||
|
||
. Use **Run** on the top right. | ||
You should get the following confirmation that the data has been created in the database in the **Response** panel: | ||
+ | ||
[source, json, indent=0] | ||
---- | ||
{ | ||
"data": { | ||
"createProducts": { | ||
"products": [ | ||
{ | ||
"productName": "New Product", | ||
"category": [ | ||
{ | ||
"categoryName": "New Category" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
---- | ||
|
||
. Query the data you just added. | ||
Copy and paste the following query to the **Operations** panel: | ||
+ | ||
[source, graphql, indent=0] | ||
---- | ||
query { | ||
products { | ||
productName | ||
category { | ||
categoryName | ||
} | ||
} | ||
} | ||
---- | ||
+ | ||
Since you only created one "Product" node and one "Category" node, the **Response** panel shows the following: | ||
+ | ||
[source, json, indent=0] | ||
---- | ||
{ | ||
"data": { | ||
"products": [ | ||
{ | ||
"productName": "New Product", | ||
"category": [ | ||
{ | ||
"categoryName": "New Category" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
---- | ||
|
||
|
||
This concludes the tutorial. | ||
You now have a GraphQL Data API connected to a Neo4j AuraDB and you have added two nodes. | ||
|
||
To learn more, see xref:queries-aggregations/index.adoc[Queries and aggregations] and xref:getting-started/toolbox.adoc[Neo4j GraphQL Toolbox]. | ||
For more advanced database settings, refer to xref:driver-configuration.adoc[Driver configuration]. | ||
|
||
// Edit at: https://github.com/neo4j-graphacademy/courses/blob/main/asciidoc/courses/graphql-basics/promo.adoc | ||
include::https://raw.githubusercontent.com/neo4j-graphacademy/courses/main/asciidoc/courses/graphql-basics/promo.adoc[] |
Uh oh!
There was an error while loading. Please reload this page.