Skip to content

Commit d704740

Browse files
davimacedodouglasmuraoka
authored andcommitted
Update GraphQL readme section (#6056)
1 parent fc57ff4 commit d704740

File tree

1 file changed

+106
-29
lines changed

1 file changed

+106
-29
lines changed

README.md

Lines changed: 106 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ Take a look at [Live Query Guide](https://docs.parseplatform.org/parse-server/gu
418418

419419
The easiest way to run the Parse GraphQL API is through the CLI:
420420

421-
```
421+
```bash
422422
$ npm install -g parse-server mongodb-runner
423423
$ mongodb-runner start
424-
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground
424+
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --publicServerURL http://localhost:1337/parse --mountGraphQL --mountPlayground
425425
```
426426

427427
After starting the server, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.
@@ -432,12 +432,12 @@ After starting the server, you can visit http://localhost:1337/playground in you
432432

433433
You can also run the Parse GraphQL API inside a Docker container:
434434

435-
```
435+
```bash
436436
$ git clone https://github.com/parse-community/parse-server
437437
$ cd parse-server
438438
$ docker build --tag parse-server .
439439
$ docker run --name my-mongo -d mongo
440-
$ 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
440+
$ 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
441441
```
442442

443443
After starting the server, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.
@@ -446,9 +446,17 @@ After starting the server, you can visit http://localhost:1337/playground in you
446446

447447
### Using Express.js
448448

449-
You can also mount the GraphQL API in an Express.js application together with the REST API or solo:
449+
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:
450450

451+
```bash
452+
$ mkdir my-app
453+
$ cd my-app
454+
$ npm install parse-server express --save
451455
```
456+
457+
Then, create an `index.js` file with the following content:
458+
459+
```js
452460
const express = require('express');
453461
const { default: ParseServer, ParseGraphQLServer } = require('parse-server');
454462

@@ -458,7 +466,8 @@ const parseServer = new ParseServer({
458466
databaseURI: 'mongodb://localhost:27017/test',
459467
appId: 'APPLICATION_ID',
460468
masterKey: 'MASTER_KEY',
461-
serverURL: 'http://localhost:1337/parse'
469+
serverURL: 'http://localhost:1337/parse',
470+
publicServerURL: 'http://localhost:1337/parse'
462471
});
463472

464473
const parseGraphQLServer = new ParseGraphQLServer(
@@ -480,7 +489,14 @@ app.listen(1337, function() {
480489
});
481490
```
482491

483-
After starting the server, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.
492+
And finally start your app:
493+
494+
```bash
495+
$ npx mongodb-runner start
496+
$ node index.js
497+
```
498+
499+
After starting the app, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.
484500

485501
***Note:*** Do ***NOT*** mount the GraphQL Playground in production. [Parse Dashboard](https://github.com/parse-community/parse-dashboard) has a built-in GraphQL Playground and it is the recommended option for production apps.
486502

@@ -504,43 +520,93 @@ You should receive the following response:
504520
}
505521
```
506522

507-
## Creating your first object
523+
## Creating your first class
508524

509-
Since your application does not have a schema yet, you can use the generic `create` mutation to create your first object. Run the following:
525+
Since your application does not have any schema yet, you can use the `createClass` mutation to create your first class. Run the following:
510526

511527
```graphql
512-
mutation CreateObject {
513-
create(className: "GameScore" fields: { score: 1337 playerName: "Sean Plott" cheatMode: false }) {
514-
objectId
515-
createdAt
528+
mutation CreateClass {
529+
createClass(
530+
name: "GameScore"
531+
schemaFields: {
532+
addStrings: [{ name: "playerName" }]
533+
addNumbers: [{ name: "score" }]
534+
addBooleans: [{ name: "cheatMode" }]
535+
}
536+
) {
537+
name
538+
schemaFields {
539+
name
540+
__typename
541+
}
516542
}
517543
}
518544
```
519545

520-
You should receive a response similar to this:
546+
You should receive the following response:
521547

522548
```json
523549
{
524550
"data": {
525-
"create": {
526-
"objectId": "CVuh0o0ioY",
527-
"createdAt": "2019-08-27T06:35:15.641Z"
551+
"createClass": {
552+
"name": "GameScore",
553+
"schemaFields": [
554+
{
555+
"name": "objectId",
556+
"__typename": "SchemaStringField"
557+
},
558+
{
559+
"name": "updatedAt",
560+
"__typename": "SchemaDateField"
561+
},
562+
{
563+
"name": "createdAt",
564+
"__typename": "SchemaDateField"
565+
},
566+
{
567+
"name": "playerName",
568+
"__typename": "SchemaStringField"
569+
},
570+
{
571+
"name": "score",
572+
"__typename": "SchemaNumberField"
573+
},
574+
{
575+
"name": "cheatMode",
576+
"__typename": "SchemaBooleanField"
577+
},
578+
{
579+
"name": "ACL",
580+
"__typename": "SchemaACLField"
581+
}
582+
]
528583
}
529584
}
530585
}
531586
```
532587

533588
## Using automatically generated operations
534589

535-
Parse Server learned from the first object that you created and now you have the `GameScore` class in your schema. You can now start using the automatically generated operations!
590+
Parse Server learned from the first class that you created and now you have the `GameScore` class in your schema. You can now start using the automatically generated operations!
536591

537-
Run the following to create a second object:
592+
Run the following to create your first object:
538593

539594
```graphql
540595
mutation CreateGameScore {
541-
createGameScore(fields: { score: 2558 playerName: "Luke Skywalker" cheatMode: false }) {
542-
objectId
596+
createGameScore(
597+
fields: {
598+
playerName: "Sean Plott"
599+
score: 1337
600+
cheatMode: false
601+
}
602+
) {
603+
id
604+
updatedAt
543605
createdAt
606+
playerName
607+
score
608+
cheatMode
609+
ACL
544610
}
545611
}
546612
```
@@ -551,8 +617,13 @@ You should receive a response similar to this:
551617
{
552618
"data": {
553619
"createGameScore": {
554-
"objectId": "XyvErLoJ2O",
555-
"createdAt": "2019-08-27T06:37:32.078Z"
620+
"id": "XN75D94OBD",
621+
"updatedAt": "2019-09-17T06:50:26.357Z",
622+
"createdAt": "2019-09-17T06:50:26.357Z",
623+
"playerName": "Sean Plott",
624+
"score": 1337,
625+
"cheatMode": false,
626+
"ACL": null
556627
}
557628
}
558629
}
@@ -564,8 +635,13 @@ You can also run a query to this new class:
564635
query GameScores {
565636
gameScores {
566637
results {
638+
id
639+
updatedAt
640+
createdAt
567641
playerName
568642
score
643+
cheatMode
644+
ACL
569645
}
570646
}
571647
}
@@ -579,12 +655,13 @@ You should receive a response similar to this:
579655
"gameScores": {
580656
"results": [
581657
{
658+
"id": "XN75D94OBD",
659+
"updatedAt": "2019-09-17T06:50:26.357Z",
660+
"createdAt": "2019-09-17T06:50:26.357Z",
582661
"playerName": "Sean Plott",
583-
"score": 1337
584-
},
585-
{
586-
"playerName": "Luke Skywalker",
587-
"score": 2558
662+
"score": 1337,
663+
"cheatMode": false,
664+
"ACL": null
588665
}
589666
]
590667
}
@@ -599,7 +676,7 @@ Parse GraphQL Server allows you to create a custom GraphQL schema with own queri
599676
To start creating your custom schema, you need to code a `schema.graphql` file and initialize Parse Server with `--graphQLSchema` and `--cloud` options:
600677

601678
```bash
602-
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground --graphQLSchema ./schema.graphql --cloud ./main.js
679+
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --publicServerURL http://localhost:1337/parse --cloud ./cloud/main.js --graphQLSchema ./cloud/schema.graphql --mountGraphQL --mountPlayground
603680
```
604681

605682
### Creating your first custom query

0 commit comments

Comments
 (0)