Skip to content

Commit 7bad5e7

Browse files
committed
Including README notes about GraphQL
1 parent 630e0ec commit 7bad5e7

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,148 @@ Live queries are meant to be used in real-time reactive applications, where just
356356

357357
Take a look at [Live Query Guide](https://docs.parseplatform.org/parse-server/guide/#live-queries), [Live Query Server Setup Guide](https://docs.parseplatform.org/parse-server/guide/#scalability) and [Live Query Protocol Specification](https://github.com/parse-community/parse-server/wiki/Parse-LiveQuery-Protocol-Specification). You can setup a standalone server or multiple instances for scalability (recommended).
358358

359+
# GraphQL
360+
361+
[GraphQL](https://graphql.org/), developed by Facebook, is an open-source data query and manipulation language for APIs. In addition to the traditional REST API, Parse Server automatically generates a GraphQL API based on your current application schema.
362+
363+
## Running
364+
365+
```
366+
$ npm install -g parse-server mongodb-runner
367+
$ mongodb-runner start
368+
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground
369+
```
370+
371+
After starting the server, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.
372+
373+
***Note:*** Do ***NOT*** use --mountPlayground option in production.
374+
375+
## Checking the API health
376+
377+
Run the following:
378+
379+
```graphql
380+
query Health {
381+
health
382+
}
383+
```
384+
385+
You should receive the following response:
386+
387+
```json
388+
{
389+
"data": {
390+
"health": true
391+
}
392+
}
393+
```
394+
395+
## Creating your first object
396+
397+
Since your application does not have a schema yet, you can use the generic `create` mutation to create your first object. Run the following:
398+
399+
```graphql
400+
mutation CreateObject {
401+
objects {
402+
create(className: "GameScore" fields: { score: 1337 playerName: "Sean Plott" cheatMode: false }) {
403+
objectId
404+
createdAt
405+
}
406+
}
407+
}
408+
```
409+
410+
You should receive a response similar to this:
411+
412+
```json
413+
{
414+
"data": {
415+
"objects": {
416+
"create": {
417+
"objectId": "7jfBmbGgyF",
418+
"createdAt": "2019-06-20T23:50:50.825Z"
419+
}
420+
}
421+
}
422+
}
423+
```
424+
425+
## Using automatically generated operations
426+
427+
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!
428+
429+
Run the following to create a second object:
430+
431+
```graphql
432+
mutation CreateGameScore {
433+
objects {
434+
createGameScore(fields: { score: 2558 playerName: "Luke Skywalker" cheatMode: false }) {
435+
objectId
436+
createdAt
437+
}
438+
}
439+
}
440+
```
441+
442+
You should receive a response similar to this:
443+
444+
```json
445+
{
446+
"data": {
447+
"objects": {
448+
"createGameScore": {
449+
"objectId": "gySYolb2CL",
450+
"createdAt": "2019-06-20T23:56:37.114Z"
451+
}
452+
}
453+
}
454+
}
455+
```
456+
457+
You can also run a query to this new class:
458+
459+
```graphql
460+
query FindGameScore {
461+
objects {
462+
findGameScore {
463+
results {
464+
playerName
465+
score
466+
}
467+
}
468+
}
469+
}
470+
```
471+
472+
You should receive a response similar to this:
473+
474+
```json
475+
{
476+
"data": {
477+
"objects": {
478+
"findGameScore": {
479+
"results": [
480+
{
481+
"playerName": "Sean Plott",
482+
"score": 1337
483+
},
484+
{
485+
"playerName": "Luke Skywalker",
486+
"score": 2558
487+
}
488+
]
489+
}
490+
}
491+
}
492+
}
493+
```
494+
495+
## Learning more
496+
497+
Please look at the right side of your GraphQL Playground. You will see `DOCS` and `SCHEMA` version that are automatically generated based on your application schema. Please refer to them and learn about everything you can do with your Parse GraphQL API.
498+
499+
Additionally, the [GraphQL Docs](https://graphql.org/learn/) is a very good source to start learning about the power of the GraphQL language.
500+
359501
# Upgrading to 3.0.0
360502

361503
Starting 3.0.0, parse-server uses the JS SDK version 2.0.

0 commit comments

Comments
 (0)