diff --git a/content/dql-syntax/dql-rdf.md b/content/dql-syntax/dql-rdf.md index 56837622..63f4e554 100644 --- a/content/dql-syntax/dql-rdf.md +++ b/content/dql-syntax/dql-rdf.md @@ -78,7 +78,7 @@ The supported [RDF datatypes](https://www.w3.org/TR/rdf11-concepts/#section-Data | <http://www.w3.org/2001/XMLSchema#float> | `float` | -<<<<<<<< HEAD:content/dql-syntax/dql-rdf.md + ### Facets @@ -125,6 +125,3 @@ Result: } } ``` -======== -See the section on [RDF schema types]({{< relref "predicate-types.md#rdf-types" >}}) to understand how RDF types affect mutations and storage. ->>>>>>>> main:content/mutations/language-rdf-types.md diff --git a/content/graphql/_index.md b/content/graphql/_index.md index 39855681..f4fc330a 100644 --- a/content/graphql/_index.md +++ b/content/graphql/_index.md @@ -24,7 +24,7 @@ description = "Generate a GraphQL API and a graph backend from a single GraphQL
All the things that you can put in your input GraphQL schema @@ -33,7 +33,7 @@ description = "Generate a GraphQL API and a graph backend from a single GraphQL
How to use the GraphQL API
diff --git a/content/graphql/api/_index.md b/content/graphql/api/_index.md
index 1ef32458..777f3ddf 100644
--- a/content/graphql/api/_index.md
+++ b/content/graphql/api/_index.md
@@ -1,7 +1,23 @@
+++
-title = "API"
+title = "Client API"
[menu.main]
identifier = "api"
parent = "graphql"
- weight = 5
-+++
\ No newline at end of file
+ weight = 8
++++
+
+How to use the GraphQL API.
+
+Dgraph serves [spec-compliant
+GraphQL](https://graphql.github.io/graphql-spec/June2018/) over HTTP to two endpoints: `/graphql` and `/admin`.
+
+
+In Dgraph Cloud `/graphql` and `/admin` are served from the domain of your backend, which will be something like `https://YOUR-SUBDOMAIN.REGION.aws.cloud.dgraph.io`. If you are running a self-hosted Dgraph instance that will be at the alpha port and url (which defaults to `http://localhost:8080` if you aren't changing any settings).
+
+In each case, both GET and POST requests are served.
+
+- `/graphql` is where you'll find the GraphQL API for the types you've added. That is the single GraphQL entry point for your apps to Dgraph.
+
+- `/admin` is where you'll find an admin API for administering your GraphQL instance. That's where you can update your GraphQL schema, perform health checks of your backend, and more.
+
+This section covers the API served at `/graphql`. See [Admin](/graphql/admin) to learn more about the admin API.
diff --git a/content/graphql/api/api-overview.md b/content/graphql/api/api-overview.md
deleted file mode 100644
index f3699260..00000000
--- a/content/graphql/api/api-overview.md
+++ /dev/null
@@ -1,24 +0,0 @@
-+++
-title = "Overview"
-description = "The documentation in this section covers the API served at /graphql. This is where you’ll find the GraphQL API for the types you’ve added."
-weight = 1
-[menu.main]
- parent = "api"
- identifier = "api-overview"
-+++
-
-How to use the GraphQL API.
-
-Dgraph serves [spec-compliant
-GraphQL](https://graphql.github.io/graphql-spec/June2018/) over HTTP to two endpoints: `/graphql` and `/admin`.
-
-
-In Dgraph Cloud `/graphql` and `/admin` are served from the domain of your backend, which will be something like `https://YOUR-SUBDOMAIN.REGION.aws.cloud.dgraph.io`. If you are running a self-hosted Dgraph instance that will be at the alpha port and url (which defaults to `http://localhost:8080` if you aren't changing any settings).
-
-In each case, both GET and POST requests are served.
-
-- `/graphql` is where you'll find the GraphQL API for the types you've added. That is the single GraphQL entry point for your apps to Dgraph.
-
-- `/admin` is where you'll find an admin API for administering your GraphQL instance. That's where you can update your GraphQL schema, perform health checks of your backend, and more.
-
-This section covers the API served at `/graphql`. See [Admin](/graphql/admin) to learn more about the admin API.
diff --git a/content/graphql/authorization/_index.md b/content/graphql/authorization/_index.md
deleted file mode 100644
index d37fd7fc..00000000
--- a/content/graphql/authorization/_index.md
+++ /dev/null
@@ -1,7 +0,0 @@
-+++
-title = "Authorization"
-weight = 4
-[menu.main]
- identifier = "authorization"
- parent = "graphql"
-+++
\ No newline at end of file
diff --git a/content/graphql/custom/_index.md b/content/graphql/custom/_index.md
index a35aeab2..fae83c2a 100644
--- a/content/graphql/custom/_index.md
+++ b/content/graphql/custom/_index.md
@@ -1,6 +1,6 @@
+++
title = "Custom Resolvers"
-weight = 9
+weight = 6
[menu.main]
identifier = "custom"
parent = "graphql"
diff --git a/content/graphql/federation/index.md b/content/graphql/federation/index.md
index eafe8029..e7c633dd 100644
--- a/content/graphql/federation/index.md
+++ b/content/graphql/federation/index.md
@@ -1,7 +1,7 @@
+++
title = "Apollo Federation"
description = "Dgraph now supports Apollo federation so that you can create a gateway GraphQL service that includes the Dgraph GraphQL API and other GraphQL services."
-weight = 14
+weight = 12
[menu.main]
name = "Apollo Federation"
identifier = "federation"
diff --git a/content/graphql/how-dgraph-graphql-works/index.md b/content/graphql/how-dgraph-graphql-works/index.md
deleted file mode 100644
index bbed9415..00000000
--- a/content/graphql/how-dgraph-graphql-works/index.md
+++ /dev/null
@@ -1,79 +0,0 @@
-+++
-title = "How GraphQL works in Dgraph"
-description = "Dgraph is a GraphQL database. But what does that mean? You design, iterate, and scale your application - all with GraphQL."
-weight = 3
-[menu.main]
- name = "How GraphQL works in Dgraph"
- identifier = "how-dgraph-graphql-works"
- parent = "graphql"
-+++
-
-Dgraph is a GraphQL database. That means, with Dgraph, you design your application in GraphQL, you iterate on your app in GraphQL and, when you need it, you scale with GraphQL.
-
-You design a set of GraphQL types that describes your requirements. Dgraph takes those types, prepares graph storage for them and generates a GraphQL API with queries and mutations.
-
-You design a graph, store a graph and query a graph. You think and design in terms of the graph that your app is based around.
-
-Let's look at how that might work a simple Twitter clone.
-
-## The app building process
-
-You'll have an idea for your app, maybe you've sketched out the basic UI, or maybe you've worked out the basic things in your app and their relationships. From that, you can derive a first version of your schema.
-
-```graphql
-type User {
- username: String! @id
- tweets: [Tweet]
-}
-
-type Tweet {
- text: String!
-}
-```
-
-Load that into Dgraph, and you'll have a working GraphQL API. You can start doing example queries and mutations with a tool like GraphQL Playground or Insomnia, you can even jump straight in and start building a UI with, say, Apollo Client. That's how quickly you can get started.
-
-Soon, you'll need to iterate while you are developing, or need to produce the next version of your idea. Either way, Dgraph makes it easy to iterate on your app. Add extra fields, add search, and Dgraph adjusts.
-
-```graphql
-type User {
- username: String! @id
- tweets: [Tweet]
-}
-
-type Tweet {
- text: String! @search(by: [fulltext])
- datePosted: DateTime
-}
-```
-
-You can even do data migrations in GraphQL, so you never have to think about anything other than GraphQL.
-
-Eventually, you'll need custom business logic and bespoke code to enhance your GraphQL server. You can write that code however works best for your app and then integrate it directly into your GraphQL schema.
-
-```graphql
-type User {
- ...
-}
-
-type Tweet {
- ...
- myCustomField @custom(...)
-}
-
-type Query {
- MyCustomQuery @custom(...)
-}
-```
-
-Again, Dgraph adjusts, and you keep working on your app, not on translating another data format into a graph.
-
-## GraphQL, Dgraph and Graphs
-
-You might be familiar with GraphQL types, fields and resolvers. Perhaps you've written an app that adds GraphQL over a REST endpoint or maybe over a relational database. If so, you know how GraphQL sits over those sources and issues many queries to translate the REST/relational data into something that looks like a graph.
-
-There's a cognitive jump in that process because your app is about a graph, but you've got to design a relational schema and work out how that translates as a graph. You'll be thinking about the app in terms of the graph, but have to mentally translate back and forth between the relational and graph models. There are engineering challenges around the translation as well as the efficiency of the queries.
-
-There's none of that with Dgraph.
-
-Dgraph GraphQL is part of Dgraph, which stores a graph - it's a database of nodes and edges. So it's efficient to store, query and traverse as a graph. Your data will get stored just like you design it in the schema, and the queries are a single graph query that does just what the GraphQL query says.
diff --git a/content/graphql/lambda/_index.md b/content/graphql/lambda/_index.md
index f0a8342c..24c518db 100644
--- a/content/graphql/lambda/_index.md
+++ b/content/graphql/lambda/_index.md
@@ -1,6 +1,6 @@
+++
title = "Lambda Resolvers"
-weight = 9
+weight = 7
[menu.main]
identifier = "lambda"
parent = "graphql"
diff --git a/content/graphql/mutations/_index.md b/content/graphql/mutations/_index.md
index 0c457869..004e084b 100644
--- a/content/graphql/mutations/_index.md
+++ b/content/graphql/mutations/_index.md
@@ -1,6 +1,6 @@
+++
title = "Mutations"
-weight = 8
+weight = 4
[menu.main]
identifier = "graphql-mutations"
parent = "graphql"
diff --git a/content/graphql/queries/_index.md b/content/graphql/queries/_index.md
index fb4d21c2..f6814075 100644
--- a/content/graphql/queries/_index.md
+++ b/content/graphql/queries/_index.md
@@ -1,6 +1,6 @@
+++
title = "Queries"
-weight = 7
+weight = 3
[menu.main]
identifier = "graphql-queries"
parent = "graphql"
diff --git a/content/graphql/quick-start/index.md b/content/graphql/quick-start/index.md
index 6561811a..4c17b9a8 100644
--- a/content/graphql/quick-start/index.md
+++ b/content/graphql/quick-start/index.md
@@ -8,8 +8,10 @@ weight = 2
parent = "graphql"
+++
-Go from an empty Dgraph database to a running GraphQL API in just one step!
-Just define the schema of your graph and how you’d like to search it; Dgraph does the rest.
+You might be familiar with GraphQL types, fields and resolvers. Perhaps you've written an app that adds GraphQL over a REST endpoint or maybe over a relational database. If so, you know how GraphQL sits over those sources and issues many queries to translate the REST/relational data into something that looks like a graph.
+
+There's none of that with Dgraph : you can generate a running GraphQL API with the associated graph backend just by dpeloying the GraphQL schema of your API; Dgraph does the rest.
+
## Prerequisite : Run Dgraph
diff --git a/content/graphql/schema/_index.md b/content/graphql/schema/_index.md
index 57e3bb5d..62566edb 100644
--- a/content/graphql/schema/_index.md
+++ b/content/graphql/schema/_index.md
@@ -3,5 +3,13 @@ title = "Schema"
[menu.main]
identifier = "schema"
parent = "graphql"
- weight = 6
-+++
\ No newline at end of file
+ weight = 2
++++
+
+This section describes all the things you can put in your input GraphQL schema, and what gets generated from that.
+
+The process for serving GraphQL with Dgraph is to add a set of GraphQL type definitions using the `/admin` endpoint. Dgraph takes those definitions, generates queries and mutations, and serves the generated GraphQL schema.
+
+The input schema may contain interfaces, types and enums that follow the usual GraphQL syntax and validation rules.
+
+If you want to make your schema editing experience nicer, you should use an editor that does syntax highlighting for GraphQL. With that, you may also want to include the definitions [here](/graphql/schema/dgraph-schema) as an import.
diff --git a/content/graphql/schema/authorization/_index.md b/content/graphql/schema/authorization/_index.md
new file mode 100644
index 00000000..b8400d5d
--- /dev/null
+++ b/content/graphql/schema/authorization/_index.md
@@ -0,0 +1,172 @@
++++
+title = "Authorization"
+weight = 5
+[menu.main]
+ identifier = "authorization"
+ parent = "schema"
++++
+
+Dgraph's GraphQL implementation comes with built-in authorization. This lets you annotate your schema with rules that determine who can query and mutate your data.
+
+First, let's get some concepts defined. There are two important concepts included in what's often called *auth*:
+
+* Authorization: access permissions (what are you allowed to do)
+* Authentication: establishment of identity (who you are)
+
+Dgraph lets you use your GraphQL schema to manage both authorization and authentication:
+* You set authorization rules by annotating your schema with the `@auth` directive
+* You configure authentication methods by providing those settings to Dgraph in the last
+line of your schema, in a commented-out `Dgraph.Authorization` object.
+
+Establishing identity and managing identity-based permissions are closely related,
+so this page covers both Dgraph's authorization capabilities, and how Dgraph works with
+various authentication methods.
+
+## Authorization
+
+You can add authorization rules to your schema using the `@auth` directive. But,
+you also need to configure the `Dgraph.Authorization` object (which handles
+authentication) on the last line of your schema for the `@auth` directive to
+work (as described below).
+
+When authentication and authorization are complete, your schema should look similar to the following:
+
+```graphql
+type A @auth(...) {
+ ...
+}
+
+type B @auth(...) {
+ ...
+}
+
+# Dgraph.Authorization {"VerificationKey":"","Header":"","Namespace":"","Algo":"","Audience":[]}
+```
+
+
+## Authentication
+
+You can authenticate your users using the following methods:
+* A cloud service like OneGraph, Firebase, or Auth0
+* Social sign-in options (such as Google authentication)
+* Your own custom authentication code
+
+Dgraph's GraphQL implementation is completely flexible about how your app does
+authentication; instead, Dgraph focuses on authorization.
+
+Dgraph's GraphQL endpoint supports both symmetric (secret-based) and asymmetric (public key)
+encryption. The connection between Dgraph and your authentication mechanism can
+be a JSON Web Key (JWK) URL or a signed JSON Web Token (JWT). So, you can provide
+Dgraph with the public key of the JWT signer (such as Firebase or Auth0) and
+Dgraph trusts JWTs signed by the corresponding private key.
+
+{{% notice "tip" %}}
+To learn more about adding JWTs from a third-party JWT signer to your app, see
+[Auth0 Authentication]({{< relref "graphql/todo-app-tutorial/todo-auth0-jwt" >}}) or [Firebase Authentication]({{< relref "graphql/todo-app-tutorial/todo-firebase-jwt" >}}). {{% /notice %}}
+
+### `Dgraph.Authorization` parameters
+
+To define the authentication connection method, Dgraph uses a commented-out
+`Dgraph.Authorization` object that you should add as the last line of your schema.
+You can only use one authentication connection method, either JWT, a single JWK
+URL, or multiple JWK URLs.
+
+The `Dgraph.Authorization` object uses the following syntax:
+
+```json
+{"Header":"", "Namespace":"", "Algo":"", "VerificationKey":"", "JWKURL":"", "Audience":[], "ClosedByDefault": false}
+```
+
+This object contains the following values:
+* `Header` is the header that requests use to store the signed JWT.
+* `Namespace` is the key inside the JWT that contains the claims relevant to Dgraph authorization.
+* `Algo` is the JWT verification algorithm which can be either `HS256` or `RS256`.
+* `VerificationKey` is the string value of the key, with newlines replaced with `\n` and the key string wrapped in `""`:
+ * **For asymmetric encryption**: `VerificationKey` contains the public key string
+ * **For symmetric (secret-based) encryption**: `VerificationKey` is the secret key; this can be any secret string you choose, such as one that you generate using a tool like OpenSSL
+* `JWKURL`/`JWKURLs` is the URL for the JSON Web Key sets. If you want to pass multiple URLs, use `JWKURLs` as an array of multiple JWK URLs for the JSON Web Key sets.
+* `Audience` is used to verify the `aud` field of a JWT, which is used by certain providers to indicate the intended audience for the JWT. When doing authentication with `JWKURL`, this field is mandatory as identity providers share JWKs among multiple tenants.
+* `ClosedByDefault`, if set to `true`, requires authorization for all requests even if the type does not specify the [`@auth`]({{< relref "directive.md" >}}) directive. If omitted, the default setting is `false`.
+
+{{% notice "tip" %}}
+To pass multiple URLs, use `JWKURLs` as an array of multiple JWK URLs for the JSON Web Key sets.
+{{% /notice %}}
+
+To set the authentication connection method, do the following:
+
+* **To use a JWT**: On the last line of your schema, specify a verification key (`VerificationKey`) and encryption algorithm (`Algo`) in the `Dgraph.Authorization` object. Dgraph verifies the JWT against the provided `VerificationKey`. So, your schema should end with a line like the following:
+
+```
+# Dgraph.Authorization {"VerificationKey":"