GraphQL support via cli (#5697)
* Including GraphQL options in CLI - now it was auto-generated * Improving the way that the headers are passed to the playground * Including README notes about GraphQL * Improving final text
This commit is contained in:
committed by
GitHub
parent
7ffb3b65e0
commit
5bc79cc3db
142
README.md
142
README.md
@@ -356,6 +356,148 @@ Live queries are meant to be used in real-time reactive applications, where just
|
||||
|
||||
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).
|
||||
|
||||
# GraphQL
|
||||
|
||||
[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.
|
||||
|
||||
## Running
|
||||
|
||||
```
|
||||
$ npm install -g parse-server mongodb-runner
|
||||
$ mongodb-runner start
|
||||
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground
|
||||
```
|
||||
|
||||
After starting the server, you can visit http://localhost:1337/playground in your browser to start playing with your GraphQL API.
|
||||
|
||||
***Note:*** Do ***NOT*** use --mountPlayground option in production.
|
||||
|
||||
## Checking the API health
|
||||
|
||||
Run the following:
|
||||
|
||||
```graphql
|
||||
query Health {
|
||||
health
|
||||
}
|
||||
```
|
||||
|
||||
You should receive the following response:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"health": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Creating your first object
|
||||
|
||||
Since your application does not have a schema yet, you can use the generic `create` mutation to create your first object. Run the following:
|
||||
|
||||
```graphql
|
||||
mutation CreateObject {
|
||||
objects {
|
||||
create(className: "GameScore" fields: { score: 1337 playerName: "Sean Plott" cheatMode: false }) {
|
||||
objectId
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You should receive a response similar to this:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"objects": {
|
||||
"create": {
|
||||
"objectId": "7jfBmbGgyF",
|
||||
"createdAt": "2019-06-20T23:50:50.825Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Using automatically generated operations
|
||||
|
||||
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!
|
||||
|
||||
Run the following to create a second object:
|
||||
|
||||
```graphql
|
||||
mutation CreateGameScore {
|
||||
objects {
|
||||
createGameScore(fields: { score: 2558 playerName: "Luke Skywalker" cheatMode: false }) {
|
||||
objectId
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You should receive a response similar to this:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"objects": {
|
||||
"createGameScore": {
|
||||
"objectId": "gySYolb2CL",
|
||||
"createdAt": "2019-06-20T23:56:37.114Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can also run a query to this new class:
|
||||
|
||||
```graphql
|
||||
query FindGameScore {
|
||||
objects {
|
||||
findGameScore {
|
||||
results {
|
||||
playerName
|
||||
score
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You should receive a response similar to this:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"objects": {
|
||||
"findGameScore": {
|
||||
"results": [
|
||||
{
|
||||
"playerName": "Sean Plott",
|
||||
"score": 1337
|
||||
},
|
||||
{
|
||||
"playerName": "Luke Skywalker",
|
||||
"score": 2558
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Learning more
|
||||
|
||||
Please look at the right side of your GraphQL Playground. You will see the `DOCS` and `SCHEMA` menus. They are automatically generated by analysing your application schema. Please refer to them and learn more about everything that you can do with your Parse GraphQL API.
|
||||
|
||||
Additionally, the [GraphQL Learn Section](https://graphql.org/learn/) is a very good source to start learning about the power of the GraphQL language.
|
||||
|
||||
# Upgrading to 3.0.0
|
||||
|
||||
Starting 3.0.0, parse-server uses the JS SDK version 2.0.
|
||||
|
||||
Reference in New Issue
Block a user