Skip to content

Commit cd0bce9

Browse files
Merge pull request #19 from appwrite/feat-tutorials
feat: tutorials
2 parents f63225d + 329ceb5 commit cd0bce9

59 files changed

Lines changed: 2684 additions & 669 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/partials/account-vs-user.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
{% info title="Account vs Users API" %}
3+
Appwrite provides two APIs to manager user accounts.
4+
5+
The Account API is the API you should use in your **client applications** like web, Flutter, mobile, and native apps.
6+
Account API creates sessions, which represent an authenticated user and is attached to a user's [account](/docs/products/auth/account).
7+
Sessions respect [permissions](/docs/advanced/platform/permissions), which means users can only access resources if they have been granted the correct permissions.
8+
9+
You'll notice that the Account API doesn't allow you to view or make changes to other users.
10+
This is by design and for **security reasons**.
11+
12+
[Account API references](/docs/references/cloud/client-web/account)
13+
14+
The Users API is a dedicated API for managing users from an admin's perspective. **Do not use the Users API on client applications**.
15+
It should be used with backend or server-side applications with the [Server SDK](#).
16+
17+
Users API uses API keys instead of sessions.
18+
This means they're not resticted by permissions, but by the scopes granted to the API key used.
19+
20+
[Users API references](/docs/references/cloud/server-nodejs/users)
21+
{% /info %}

src/routes/docs/advanced/platform/webhooks/+page.markdoc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ title: Webhooks
44
description: Placeholder SEO.
55
---
66

7-
Certainly! Below is the content converted to Markdown format:
8-
9-
```md
10-
```php
11-
<?php
12-
13-
$events = $this->getParam('events', []);
14-
15-
?>
16-
```
17-
187
Webhooks allow you to build or set up integrations which subscribe to certain events on Appwrite. When one of those events is triggered, we'll send an HTTP POST payload to the webhook's configured URL. Webhooks can be used to purge cache from CDN, calculate data or send a Slack notification. You're only limited by your imagination.
198

209
## Add your webhook {% #addWebhook %}

src/routes/docs/advanced/self-hosting/functions/+page.markdoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ Check the **Any account** box under **Where can this GitHub App be installed?**
7979

8080
After creating your app, you'll have to configure the following environment variables.
8181

82-
Markdown doesn't natively support tables with complex markup like HTML does. However, you can create simple tables with Markdown. Here's a basic conversion of your table to Markdown:
83-
8482
| Variable | Description |
8583
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
8684
| `_APP_DOMAIN` | Your main Appwrite domain used to access the Appwrite Console. When setting a public suffix domain, Appwrite will attempt to issue a valid SSL certificate automatically. When used with a dev domain, Appwrite will assign a self-signed SSL certificate. If you're using a proxy for **localhost development**, such as [ngrok](https://ngrok.com/), this will be the domain of your localhost proxy. |

src/routes/docs/apis/graphql/+page.markdoc

Lines changed: 78 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
11
---
22
layout: article
33
title: GraphQL
4-
description:
5-
difficulty: beginner
6-
readtime: 10
4+
description: Description used for SEO
75
---
86

9-
Appwrite supports multiple protocols for accessing the server, including [REST](/docs/apis/rest), [GraphQL](/docs/apis/graphql), and [Realtime](/docs/apis/realtime). The GraphQL API allows you to query and mutate any resource type on your Appwrite server through the endpoint `/v1/graphql`. Every endpoint available through REST is available through GraphQL, except for OAuth.
7+
Appwrite supports multiple protocols for accessing the server, including [REST](/docs/rest), [GraphQL](/docs/graphql), and [Realtime](/docs/realtime).
8+
9+
The GraphQL API allows you to query and mutate any resource type on your Appwrite server through the endpoint `/v1/graphql`.
10+
Every endpoint available through REST is available through GraphQL, except for OAuth.
11+
12+
## Requests {% #requests %}
13+
14+
Although every query executes through the same endpoint, there are multiple ways to make a GraphQL request. All requests, however, share a common structure.
15+
16+
| Name | Type | Description |
17+
|----------------|--------|---------------------------------------------------------------------------|
18+
| query | string | **Required**, the GraphQL query to execute. |
19+
| operationName | string | **Optional**, if the query contains several named operations, controls which one to execute. |
20+
| variables | object | **Optional**, an object containing variable names and values for the query. Variables are made available to your query with the `$` prefix. |
21+
22+
### GraphQL model parameters {% #graphql-model-parameters %}
1023

11-
{% info title="GraphQL Model Parameters" %}
1224
In Appwrite's GraphQL API, all internal model parameters are prefixed with `_` instead of `$` because `$` is reserved by GraphQL.
1325

1426
For example, `$collectionId` in the REST API would be referenced as `_collectionId` in the GraphQL API.
15-
{% /info %}
1627

17-
## Requests {% #requests %}
18-
Although every query executes through the same endpoint, there are multiple ways to make a GraphQL request. All requests, however, share a common structure.
28+
### GET requests {% #get-resquest %}
1929

20-
{% table %}
21-
* Name {% width=100 %}
22-
* &nbsp; {% width=100 %}
23-
* Type {% width=100 %}
24-
* Description
25-
---
26-
* `query`
27-
* required
28-
* string
29-
* The GraphQL query to execute.
30-
---
31-
* `operationName`
32-
* optional
33-
* string
34-
* If the query contains several named operations, controls which one to execute.
35-
---
36-
* `variables`
37-
* optional
38-
* object
39-
* An object containing variable names and values for the query. Variables are made available to your query with the $ prefix.
40-
---
41-
{% /table %}
30+
You can execute a GraphQL query via a GET request, passing a `query` and optionally `operationName` and `variables` as query parameters.
4231

43-
### GET
44-
You can execute a GraphQL query via a GET request, passing a query and optionally operationName and variables as query parameters.
32+
### POST requests {% #post-request %}
4533

46-
### POST
4734
There are multiple ways to make a GraphQL POST request, differentiated by content type.
4835

49-
#### JSON
36+
{% tabs %}
37+
{% tabsitem #json title="JSON" %}
5038

51-
There are two ways to make requests with the `application/json` content type. You can send a JSON object containing a `query` and optionally `operationName` and `variables`, or an array of objects with the same structure.
39+
There are two ways to make requests with the `application/json` content type.
40+
You can send a JSON object containing a `query` and optionally `operationName` and `variables`, or an array of objects with the same structure.
5241

53-
**object**
42+
#### Object
5443

5544
```json
5645
{
@@ -60,7 +49,7 @@ There are two ways to make requests with the `application/json` content type. Yo
6049
}
6150
```
6251

63-
**array**
52+
#### Array
6453

6554
```json
6655
[
@@ -71,9 +60,9 @@ There are two ways to make requests with the `application/json` content type. Yo
7160
}
7261
]
7362
```
63+
{% /tabsitem %}
7464

75-
#### GraphQL
76-
65+
{% tabsitem #graphql title="GraphQL" %}
7766
The `application/graphql` content type can be used to send a query as the raw POST body.
7867

7968
```graphql
@@ -84,69 +73,55 @@ query GetAccount {
8473
}
8574
}
8675
```
76+
{% /tabsitem %}
77+
{% /tabs %}
8778

88-
#### Multipart Form Data
8979

90-
The `multipart/form-data` content type can be used to upload files via GraphQL. In this case, the form data must include the following parts in addition to the files to upload.
80+
### Multipart form data {% #multipart-form-data %}
9181

92-
{% table %}
93-
* Name {% width=100 %}
94-
* &nbsp; {% width=100 %}
95-
* Type {% width=100 %}
96-
* Description
97-
---
98-
* `operations`
99-
* required
100-
* string
101-
* JSON encoded GraphQL query and optionally operation name and variables. File variables should contain null values.
102-
---
103-
* `map`
104-
* required
105-
* string
106-
* JSON encoded map of form-data filenames to the operations dot-path to inject the file to, e.g. variables.file.
107-
---
108-
{% /table %}
82+
The `multipart/form-data` content type can be used to upload files via GraphQL.
83+
In this case, the form data must include the following parts in addition to the files to upload.
84+
85+
| Name | Type | Description |
86+
|-------------|--------|---------------------------------------------------------------------------------------------------------------------------|
87+
| operations |string | **Required**, JSON encoded GraphQL query and optionally operation name and variables. File variables should contain null values. |
88+
| map | string | **Required**, JSON encoded map of form-data filenames to the operations dot-path to inject the file to, e.g. `variables.file`. |
10989

11090
## Responses {% #responses %}
11191

112-
A response to a GraphQL request will have the following structure.
92+
A response to a GraphQL request will have the following structure:
11393

114-
{% table %}
115-
* Name {% width=100 %}
116-
* &nbsp; {% width=100 %}
117-
* Type {% width=100 %}
118-
* Description
119-
---
120-
* `data`
121-
*
122-
* object
123-
* The data returned by the query, maps requested field names to their results.
124-
---
125-
* `errors`
126-
*
127-
* object[]
128-
* An array of errors that occurred during the request.
129-
---
130-
{% /table %}
94+
| Name | Type | Description |
95+
|--------|----------|--------------------------------------------------------------------------------|
96+
| data | object | The data returned by the query, maps requested field names to their results. |
97+
| errors | object[] | An array of errors that occurred during the request. |
13198

132-
The data object will contain a map of requested field names to their results. If no data is returned, the object will not be present in the response.
99+
The data object will contain a map of requested field names to their results.
100+
If no data is returned, the object will not be present in the response.
133101

134-
The errors array will contain error objects, each with their own **message** and **path**. The path will contain the field key that is null due to the error. If no errors occur, the array will not be present in the response.
102+
The errors array will contain error objects, each with their own **message** and **path**.
103+
The path will contain the field key that is null due to the error.
104+
If no errors occur, the array will not be present in the response.
135105

136106
## Authentication {% #authentication %}
137-
GraphQL authenticates using Appwrite accounts and sessions. Both accounts and sessions can be created with GraphQL using the `accountCreate`, `accountCreateEmailSession`, `accountCreateAnonymousSession`, or `accountCreatePhoneSession` mutations.
138107

139-
More information and examples of authenticating users can be found in the dedicated [authentication guide](/docs/products/auth).
108+
GraphQL authenticates using Appwrite accounts and sessions.
109+
Both accounts and sessions can be created with GraphQL using the `accountCreate`, `accountCreateEmailSession`,
110+
`accountCreateAnonymousSession`, or `accountCreatePhoneSession` mutations.
140111

141-
## GraphQL vs REST {% #graphql-vs-rest %}
112+
More information and examples of authenticating users can be found in the dedicated [authentication guide](/docs/authentication).
113+
114+
## GraphQL vs REST {% #graphql-vs-rest %}
142115

143116
There are two main features that make GraphQL appealing when compared to the REST API: **selection sets** and **query batching**.
144117

145-
### Selection Sets
118+
### Selection sets {% #selection-sets %}
146119

147-
Selection sets can be used to tell a GraphQL API exactly which fields of a particular resource you would like to receive in the response. The server will respond with only those fields, nothing more, nothing less. This gives you full control over what data comes into your application.
120+
Selection sets can be used to tell a GraphQL API exactly which fields of a particular resource you would like to receive in the response.
121+
The server will respond with only those fields, nothing more, nothing less. This gives you full control over what data comes into your application.
148122

149-
For example, to retrieve only the email of a currently authenticated user, you could query the `accountGet` field, passing only email as the **field selection set**.
123+
For example, to retrieve only the email of a currently authenticated user, you could query the `accountGet` field,
124+
passing only email as the **field selection set**.
150125

151126
```graphql
152127
query GetAccount {
@@ -159,7 +134,7 @@ query GetAccount {
159134

160135
Given this query, the GraphQL API will respond with:
161136

162-
```graphql
137+
```json
163138
{
164139
"data": {
165140
"accountGet": {
@@ -170,11 +145,13 @@ Given this query, the GraphQL API will respond with:
170145
}
171146
```
172147

173-
This can be a useful feature for performance, network efficiency, and app responsiveness. As the processing happens on the server, the bandwidth consumed for the request can be dramatically reduced.
148+
This can be a useful feature for performance, network efficiency, and app responsiveness.
149+
As the processing happens on the server, the bandwidth consumed for the request can be dramatically reduced.
174150

175-
## Query batching {% #query-batching %}
151+
## Query batching {% #query-batching %}
176152

177-
GraphQL allows sending multiple queries or mutations in the same request. There are two different ways to batch queries. The simplest way is to include multiple fields in a single query **or** mutation.
153+
GraphQL allows sending multiple queries or mutations in the same request.
154+
There are two different ways to batch queries. The simplest way is to include multiple fields in a single query **or** mutation.
178155

179156
```graphql
180157
query GetAccountAndLocale {
@@ -204,7 +181,8 @@ If both field executions succeed, the response will contain a data key for each
204181
}
205182
```
206183

207-
If there was no authenticated user, the `accountGet` field would fail to resolve. In such a case the value of the data key for that field will be null, and an object will be added to the errors array instead.
184+
If there was no authenticated user, the `accountGet` field would fail to resolve.
185+
In such a case the value of the data key for that field will be null, and an object will be added to the errors array instead.
208186

209187
```json
210188
{
@@ -224,13 +202,16 @@ If there was no authenticated user, the `accountGet` field would fail to resolve
224202
}
225203
```
226204

227-
Batching with a single query or mutation has some down-sides. You can not mix and match queries and mutations within the same request unless you provide an operationName, in which case you can only execute one query per request.
205+
Batching with a single query or mutation has some down-sides.
206+
You cannot mix and match queries and mutations within the same request unless you provide an operationName,
207+
in which case you can only execute one query per request.
228208

229209
Additionally, all **variables** must be passed in the same object, which can be cumbersome and hard to maintain.
230210

231-
The second way to batch is to pass an array of queries or mutations in the request. In this way, you can execute queries **and** mutations and keep variables separated for each.
211+
The second way to batch is to pass an array of queries or mutations in the request.
212+
In this way, you can execute queries **and** mutations and keep variables separated for each.
232213

233-
```graphql
214+
```json
234215
[
235216
{
236217
"query": "query GetAccount { accountGet{ email } }",
@@ -241,7 +222,9 @@ The second way to batch is to pass an array of queries or mutations in the reque
241222
]
242223
```
243224

244-
## SDK Usage {% #sdk-usage %}
225+
This allows you to execute complex actions in a single network request.
226+
227+
## SDK usage {% #sdk-usage %}
245228

246229
Appwrite SDKs also support GraphQL in addition to the REST services.
247230

@@ -283,7 +266,6 @@ mutation.then(response => {
283266
console.log(error);
284267
});
285268
```
286-
287269
```dart
288270
import 'package:appwrite/appwrite.dart';
289271

@@ -321,8 +303,7 @@ mutation.then((response) {
321303
print(error.message);
322304
});
323305
```
324-
325-
```java
306+
```kotlin
326307
import io.appwrite.Client
327308
import io.appwrite.services.Graphql
328309

@@ -360,7 +341,6 @@ try {
360341
ex.printStackTrace()
361342
}
362343
```
363-
364344
```swift
365345
import Appwrite
366346

@@ -401,4 +381,4 @@ do {
401381
print(error.localizedDescription)
402382
}
403383
```
404-
{% /multicode %}
384+
{% /multicode %}

0 commit comments

Comments
 (0)