Skip to content

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

Open
wants to merge 11 commits into
base: 7.x
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions modules/ROOT/content-nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* *Getting started*

* xref:getting-started/index.adoc[]
** xref:getting-started/graphql-aura.adoc[]
** xref:getting-started/graphql-self-hosted.adoc[]
* xref:getting-started/toolbox.adoc[]

* *Reference*
Expand Down
Binary file removed modules/ROOT/images/apollo-server-landing-page.png
Binary file not shown.
Binary file removed modules/ROOT/images/neo4j-aura-dashboard.png
Binary file not shown.
Binary file modified modules/ROOT/images/toolbox-editor-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/ROOT/images/toolbox-favorite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/ROOT/images/toolbox-schema-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions modules/ROOT/pages/directives/custom-logic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ type Movie @limit(max: 100, default: 10) @node {

== `@customResolver`

[NOTE]
====
Data APIs created in Aura Console currently do not support custom resolvers.
====

The Neo4j GraphQL Library generates query and mutation resolvers, so you don't need to implement them yourself.
However, if you need additional behaviors besides the autogenerated CRUD operations, you can specify custom resolvers for these scenarios.

Expand Down Expand Up @@ -493,6 +498,11 @@ type Journal implements Publication @node {

== `@populatedBy`

[NOTE]
====
Data APIs created in Aura Console currently do not support the `@populatedBy` directive.
====

This directive is used to specify a callback function, which is executed during GraphQL query parsing,
to populate fields which have not been provided within the input.

Expand Down
5 changes: 5 additions & 0 deletions modules/ROOT/pages/directives/indexes-and-constraints.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ query {
[#_vector_index_search]
== `@vector`

[NOTE]
====
Data APIs created in Aura Console currently do not support the `@vector` directive.
====

With the `@vector` GraphQL directive you can query your database to perform a vector index search.
Queries are performed by passing in either a vector index or a query phrase.

Expand Down
229 changes: 229 additions & 0 deletions modules/ROOT/pages/getting-started/graphql-aura.adoc
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.
====

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i copied the caution box - does that suffice? :)
i'll add a sentence to make sure the user enables them both


=== 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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[]
Loading