Skip to content

Commit 9cc311c

Browse files
committed
Merge remote-tracking branch 'upstream/gh-pages' into gh-pages
2 parents d61b9db + 4b24433 commit 9cc311c

File tree

14 files changed

+416
-312
lines changed

14 files changed

+416
-312
lines changed

_includes/cloudcode/cloud-code-advanced.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A simple GET request would look like:
88

99
```javascript
1010
Parse.Cloud.httpRequest({
11-
url: 'http://www.awesomewebsite.com/'
11+
url: 'https://www.awesomewebsite.com/'
1212
}).then(function(httpResponse) {
1313
// success
1414
console.log(httpResponse.text);
@@ -24,7 +24,7 @@ A GET request that specifies the port number would look like:
2424

2525
```javascript
2626
Parse.Cloud.httpRequest({
27-
url: 'http://www.awesomewebsite.com:8080/'
27+
url: 'https://www.awesomewebsite.com:8080/'
2828
}).then(function(httpResponse) {
2929
console.log(httpResponse.text);
3030
}, function(httpResponse) {
@@ -34,6 +34,19 @@ Parse.Cloud.httpRequest({
3434

3535
Valid port numbers are 80, 443, and all numbers from 1025 through 65535.
3636

37+
By default, `Parse.Cloud.httpRequest` does not follow redirects caused by HTTP 3xx response codes, the `followRedirects: true` option can be used to change this.
38+
39+
```javascript
40+
Parse.Cloud.httpRequest({
41+
url: 'https://www.awesomewebsite.com/',
42+
followRedirects: true
43+
}).then(function(httpResponse) {
44+
console.log(httpResponse.text);
45+
}, function(httpResponse) {
46+
console.error('Request failed with response code ' + httpResponse.status);
47+
});
48+
```
49+
3750
### Query Parameters
3851

3952
You can specify query parameters to append to the end of the url by setting `params` on the options object. You can either pass a JSON object of key value pairs like:
@@ -569,3 +582,13 @@ Here's an example of the JSON data that would be sent in the request to this web
569582
```
570583

571584
After setting up your webhook in the Dashboard UI, you'll be acurately decrementing comment counts!
585+
586+
# Config
587+
Parse Config offers a convenient way to configure parameters in Cloud Code.
588+
589+
```javascript
590+
const config = await Parse.Config.get({useMasterKey: true});
591+
const privateParam = config.get("privateParam");
592+
```
593+
594+
By default, Parse Config parameters can be publicly read which may be undesired if the parameter contains sensitive information that should not be exposed to clients. A parameter can be made readable only with the master key by setting the `Requires master key?` property via the Parse Dashboard to `Yes`.

_includes/cloudcode/cloud-code.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,6 @@ If the function throws, the `Review` object will not be saved, and the client wi
192192

193193
One useful tip is that even if your mobile app has many different versions, the same version of Cloud Code applies to all of them. Thus, if you launch an application that doesn't correctly check the validity of input data, you can still fix this problem by adding a validation with `beforeSave`.
194194

195-
If you want to use `beforeSave` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself:
196-
197-
```javascript
198-
Parse.Cloud.beforeSave(Parse.User, (request) => {
199-
if (!request.object.get("email")) {
200-
throw "email is required for signup";
201-
}
202-
});
203-
```
204-
205195
## Modifying Objects on Save
206196

207197
In some cases, you don't want to throw out invalid data. You just want to tweak it a bit before saving it. `beforeSave` can handle this case, too. Any adjustment you make to request.object will be saved.
@@ -469,6 +459,44 @@ Parse.Cloud.beforeLogin(async request => {
469459
- On sign up
470460
- If the login credentials are incorrect
471461
462+
# LiveQuery Triggers
463+
464+
*Available only on parse-server cloud code starting 2.6.2*
465+
466+
Sometimes you may want to monitor Live Query Events to be used with a 3rd Party such as datadog. The `onLiveQueryEvent` trigger can log events triggered, number of clients connected, number of subscriptions and errors.
467+
468+
```javascript
469+
Parse.Cloud.onLiveQueryEvent(({
470+
event,
471+
client,
472+
sessionToken,
473+
useMasterKey,
474+
installationId,
475+
clients,
476+
subscriptions,
477+
error
478+
}) => {
479+
if (event !== 'ws_disconnect') {
480+
return;
481+
}
482+
// Do your magic
483+
});
484+
```
485+
*client, sessionToken, useMasterKey and installationId are available on parse-server cloud code 3.8.0+*
486+
487+
To learn more, read the [Parse LiveQuery Protocol Specification](https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification)
488+
489+
## Events
490+
491+
* connect
492+
* subscribe
493+
* unsubscribe
494+
* ws_connect
495+
* ws_disconnect
496+
* ws_disconnect_error
497+
498+
"connect" differs from "ws_connect", the former means that the client completed the connect procedure as defined by Parse Live Query protocol, where "ws_connect" just means that a new websocket was created.
499+
472500
# Using the Master Key in cloud code
473501
Set `useMasterKey:true` in the requests that require master key.
474502

_includes/graphql/getting-started.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The easiest way to run the Parse GraphQL Server is using the CLI:
77
```bash
88
$ npm install -g parse-server mongodb-runner
99
$ mongodb-runner start
10-
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground
10+
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --publicServerURL http://localhost:1337/parse --mountGraphQL --mountPlayground
1111
```
1212

1313
Notes:
@@ -32,7 +32,7 @@ $ git clone https://github.com/parse-community/parse-server
3232
$ cd parse-server
3333
$ docker build --tag parse-server .
3434
$ docker run --name my-mongo -d mongo
35-
$ docker run --name my-parse-server --link my-mongo:mongo -d parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://mongo/test --mountGraphQL --mountPlayground
35+
$ docker run --name my-parse-server --link my-mongo:mongo -p 1337:1337 -d parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://mongo/test --publicServerURL http://localhost:1337/parse --mountGraphQL --mountPlayground
3636
```
3737

3838
After starting the server, you can visit [http://localhost:1337/playground](http://localhost:1337/playground) in your browser to start playing with your GraphQL API.
@@ -41,7 +41,15 @@ After starting the server, you can visit [http://localhost:1337/playground](http
4141

4242
## Using Express.js
4343

44-
You can also mount the GraphQL API in an Express.js application together with the REST API or solo:
44+
You can also mount the GraphQL API in an Express.js application together with the REST API or solo. You first need to create a new project and install the required dependencies:
45+
46+
```bash
47+
$ mkdir my-app
48+
$ cd my-app
49+
$ npm install parse-server express --save
50+
```
51+
52+
Then, create an `index.js` file with the following content:
4553

4654
```js
4755
const express = require('express');
@@ -53,7 +61,8 @@ const parseServer = new ParseServer({
5361
databaseURI: 'mongodb://localhost:27017/test',
5462
appId: 'APPLICATION_ID',
5563
masterKey: 'MASTER_KEY',
56-
serverURL: 'http://localhost:1337/parse'
64+
serverURL: 'http://localhost:1337/parse',
65+
publicServerURL: 'http://localhost:1337/parse'
5766
});
5867

5968
const parseGraphQLServer = new ParseGraphQLServer(
@@ -75,7 +84,14 @@ app.listen(1337, function() {
7584
});
7685
```
7786

78-
After starting the server, you can visit [http://localhost:1337/playground](http://localhost:1337/playground) in your browser to start playing with your GraphQL API.
87+
And finally start your app:
88+
89+
```bash
90+
$ npx mongodb-runner start
91+
$ node index.js
92+
```
93+
94+
After starting the app, you can visit [http://localhost:1337/playground](http://localhost:1337/playground) in your browser to start playing with your GraphQL API.
7995

8096
⚠️ Please do not mount the GraphQL Playground in production as anyone could access your API Playground and read or change your application's data. [Parse Dashboard](#running-parse-dashboard) has a built-in GraphQL Playground and it is the recommended option for production apps.
8197

0 commit comments

Comments
 (0)