Skip to content

GraphQL Docs for Parse Server 3.10.0 #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5446d2c
wip
Moumouls Nov 30, 2019
8b86952
wip
Moumouls Dec 2, 2019
101b599
first version
Moumouls Dec 2, 2019
8ee7334
Add nested Query & Mutation
Moumouls Dec 2, 2019
d46021c
Update _includes/graphql/users.md
Moumouls Dec 2, 2019
6973cb9
Update _includes/graphql/classes.md
Moumouls Dec 2, 2019
655f7a0
Update _includes/graphql/relay.md
Moumouls Dec 2, 2019
a981385
Update _includes/graphql/files.md
Moumouls Dec 2, 2019
2fc85d3
Update _includes/graphql/files.md
Moumouls Dec 2, 2019
80ae6be
Update _includes/graphql/getting-started.md
Moumouls Dec 2, 2019
74dbbbe
Update _includes/graphql/relay.md
Moumouls Dec 2, 2019
4cf995f
Update _includes/graphql/graphql.md
Moumouls Dec 2, 2019
0445972
Update _includes/graphql/relay.md
Moumouls Dec 2, 2019
dceac2f
Update _includes/graphql/relay.md
Moumouls Dec 2, 2019
4ad78dd
Update _includes/graphql/getting-started.md
Moumouls Dec 2, 2019
93b4aa9
Update _includes/graphql/graphql.md
Moumouls Dec 2, 2019
e76b5db
Update _includes/graphql/objects.md
Moumouls Dec 2, 2019
0b91812
Update _includes/graphql/objects.md
Moumouls Dec 2, 2019
54782cc
Update _includes/graphql/queries.md
Moumouls Dec 2, 2019
e0e3171
Update _includes/graphql/objects.md
Moumouls Dec 2, 2019
bfeec9c
Update _includes/graphql/objects.md
Moumouls Dec 2, 2019
59efa78
Update _includes/graphql/queries.md
Moumouls Dec 2, 2019
df55fb7
Fix
Moumouls Dec 2, 2019
43a48ba
Add Relational Query
Moumouls Dec 7, 2019
415c48c
Apply suggestions from code review
Moumouls Dec 7, 2019
ba8fc5c
Update _includes/graphql/queries.md
Moumouls Dec 7, 2019
a6c05ed
Update _includes/graphql/queries.md
Moumouls Dec 7, 2019
f6feced
Apply suggestions from code review
Moumouls Dec 7, 2019
baaf5cc
Wip optimization
Moumouls Dec 31, 2019
08ffb1c
Merge branch 'original/gh-pages' into graphql
Moumouls Jan 8, 2020
75e69a5
GraphQL Api second position + remove beta + fix conflicts
Moumouls Jan 8, 2020
d67699a
Apply suggestions from code review
Moumouls Jan 10, 2020
559ccd8
Update _includes/graphql/optimization.md
Moumouls Jan 10, 2020
3f8298f
Update queries.md
TomWFox Jan 12, 2020
2fd6b2d
minor changes
TomWFox Jan 12, 2020
f28d38c
change from previous review comment
TomWFox Jan 12, 2020
e5f2854
Update objects.md
TomWFox Jan 12, 2020
ff65f65
Update users.md
TomWFox Jan 12, 2020
f889f63
Update graphql.md
TomWFox Jan 12, 2020
a7fd38c
Update queries.md
TomWFox Jan 12, 2020
906e9ba
change from Omair review
TomWFox Jan 12, 2020
950efe6
changes from earlier review
TomWFox Jan 12, 2020
273f7bc
Update optimization.md
TomWFox Jan 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _includes/graphql/api-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# API Doc

GraphQL is a self documented API, to learn all available operations, it's recommended to start the Parse GraphQL Server and visit the Docs tab on the GraphQL Playground.

```bash
$ npm install -g parse-server mongodb-runner
$ mongodb-runner start
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground
```

Visit your [Local GraphQL Playground](http://localhost:1337/playground)

<img alt="GraphQL Playground" data-echo="{{ '/assets/images/graphql/graphql-playground.png' | prepend: site.baseurl }}"/>
81 changes: 81 additions & 0 deletions _includes/graphql/classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Classes

Since your application does not have a schema yet, you can use the `createClass` mutation to create your first class through the GraphQL API. Run the following:
```js
// Header
{
"X-Parse-Application-Id": "APPLICATION_ID",
"X-Parse-Master-Key": "MASTER_KEY"
}
```

```graphql
# GraphQL
mutation createGameScoreClass {
createClass(
input: {
clientMutationId: "anFrontId"
name: "GameScore"
schemaFields: {
addStrings: [{ name: "playerName" }]
addNumbers: [{ name: "score" }]
addBooleans: [{ name: "cheatMode" }]
}
}
) {
clientMutationId
class {
name
schemaFields {
name
__typename
}
}
}
}
```
```js
// Response
{
"data": {
"createClass": {
"clientMutationId": "anFrontId",
"class": {
"name": "GameScore",
"schemaFields": [
{
"name": "objectId",
"__typename": "SchemaStringField"
},
{
"name": "updatedAt",
"__typename": "SchemaDateField"
},
{
"name": "createdAt",
"__typename": "SchemaDateField"
},
{
"name": "playerName",
"__typename": "SchemaStringField"
},
{
"name": "score",
"__typename": "SchemaNumberField"
},
{
"name": "cheatMode",
"__typename": "SchemaBooleanField"
},
{
"name": "ACL",
"__typename": "SchemaACLField"
}
]
}
}
}
}
```

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!
4 changes: 2 additions & 2 deletions _includes/graphql/customisation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Customisation

Although we automtically generate a GraphQL schema based on your Parse Server database, we have provided a number of ways in which to configure and extend this schema.
Although we automatically generate a GraphQL schema based on your Parse Server database, we have provided a number of ways in which to configure and extend this schema.

## Configuration

Expand Down Expand Up @@ -67,7 +67,7 @@ interface ParseGraphQLConfiguration {
find?: boolean;
};

// By default, all write mutation types are
// By default, all write mutation types are
// exposed for all included classes. Use this to disable
// the available mutation types for this class.
mutation?: {
Expand Down
128 changes: 128 additions & 0 deletions _includes/graphql/files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Files

The GraphQL API supports file upload via [GraphQL Upload](https://github.com/jaydenseric/graphql-upload), to send a `File` through `GraphQL` it's recommended to use the [Apollo Upload Client](https://github.com/jaydenseric/apollo-upload-client).

## Add a File field
First of all we will update our `GameScore` class with a `screenshot` field of type `File`.

```js
// Header
{
"X-Parse-Application-Id": "APPLICATION_ID",
"X-Parse-Master-Key": "MASTER_KEY"
}
```
```graphql
# GraphQL
mutation updateGameScoreClass {
updateClass(
input: {
name: "GameScore",
schemaFields: {
addFiles: [{ name: "screenshot" }]
}
}
) {
class {
name
}
}
}
```
```js
// Response
{
"data": {
"updateClass": {
"class": {
"name": "GameScore"
}
}
}
}
```

## Create and add File

Currently the GraphQL API does not support nested mutation for the `File` type, so we need to send the file and then create/update the `GameScore` object with the returned information.

```js
// Header
{
"X-Parse-Application-Id": "APPLICATION_ID",
"X-Parse-Master-Key": "MASTER_KEY" // (optional)
}
```
```graphql
# GraphQL
# $file is a GraphQL Variable, see https://github.com/jaydenseric/apollo-upload-client
mutation createFile($file: Upload!) {
createFile(input: { upload: $file }) {
fileInfo {
name
url
}
}
}
```
```js
// Response
{
"data": {
"createFile": {
"fileInfo": {
"name": "6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png",
"url": "http://localhost:1337/graphq/files/APPLICATION_ID/6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
}
}
}
}
```

Then add the file to a new `GameScore` object.
```js
// Header
{
"X-Parse-Application-Id": "APPLICATION_ID",
"X-Parse-Master-Key": "MASTER_KEY" // (optional)
}
```
```graphql
# GraphQL
mutation createGameScore {
createGameScore(
input: {
fields: {
playerName: "John"
screenshot: {
__type: "File",
name: "6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
url: "http://localhost:1337/graphq/files/APPLICATION_ID/6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
}
}
}
) {
gameScore {
screenshot {
name
url
}
}
}
}
```
```js
// Response
{
"data": {
"createGameScore": {
"gameScore": {
"screenshot": {
"name": "6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png",
"url": "http://localhost:1337/graphq/files/APPLICATION_ID/6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
}
}
}
}
}
```
58 changes: 28 additions & 30 deletions _includes/graphql/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
# Getting Started

[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](/rest/guide/), Parse Server automatically generates a GraphQL API based on your current application schema.
[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](/rest/guide/), Parse Server automatically generates a GraphQL API based on your current application schema. Specifically, Parse has opted for the [Relay](https://relay.dev/docs/en/introduction-to-relay) specification in-line with industry best-practices.

## Fast launch
The easiest way to run the Parse GraphQL Server is using the CLI:

```bash
$ npm install -g parse-server mongodb-runner
$ mongodb-runner start
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --publicServerURL http://localhost:1337/parse --mountGraphQL --mountPlayground
$ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://localhost/test --mountGraphQL --mountPlayground
```

Notes:
* Run `parse-server --help` or refer to [Parse Server Options](https://parseplatform.org/parse-server/api/master/ParseServerOptions.html) for a complete list of Parse Server configuration options.
* ⚠️ Please do not use `--mountPlayground` option 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.
* ⚠️ The Parse GraphQL ```beta``` implementation is fully functional but discussions are taking place on how to improve it. So new versions of Parse Server can bring breaking changes to the current API.
* ⚠️ Please do not use `--mountPlayground` option 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. If you want to secure your API in production take a look at [Class Level Permissions](/js/guide/#class-level-permissions)

After running the CLI command, you should have something like this in your terminal:

<img alt="Parse GraphQL Server" data-echo="{{ '/assets/images/graphql/parse-graphql-server.png' | prepend: site.baseurl }}"/>
```sh
...
[35071] parse-server running on http://localhost:1337/parse
[35071] GraphQL running on http://localhost:1337/graphql
[35071] Playground running on http://localhost:1337/playground
```

Since you have already started your Parse GraphQL Server, you can now visit [http://localhost:1337/playground](http://localhost:1337/playground) in your web browser to start playing with your GraphQL API.

<img alt="GraphQL Playground" data-echo="{{ '/assets/images/graphql/graphql-playground.png' | prepend: site.baseurl }}"/>

## Using Docker

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

```bash
$ git clone https://github.com/parse-community/parse-server
$ cd parse-server
$ docker build --tag parse-server .
$ docker run --name my-mongo -d mongo
$ 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
```

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.

⚠️ Please do not use `--mountPlayground` option 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.

## Using Express.js

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:

```bash
```sh
$ mkdir my-app
$ cd my-app
$ npm init
$ npm install parse-server express --save
```

Then, create an `index.js` file with the following content:

```js
// index.js
const express = require('express');
const { default: ParseServer, ParseGraphQLServer } = require('parse-server');

// Create express app
const app = express();

// Create a Parse Server Instance
const parseServer = new ParseServer({
databaseURI: 'mongodb://localhost:27017/test',
appId: 'APPLICATION_ID',
Expand All @@ -65,6 +58,7 @@ const parseServer = new ParseServer({
publicServerURL: 'http://localhost:1337/parse'
});

// Create the GraphQL Server Instance
const parseGraphQLServer = new ParseGraphQLServer(
parseServer,
{
Expand All @@ -73,10 +67,14 @@ const parseGraphQLServer = new ParseGraphQLServer(
}
);

app.use('/parse', parseServer.app); // (Optional) Mounts the REST API
parseGraphQLServer.applyGraphQL(app); // Mounts the GraphQL API
parseGraphQLServer.applyPlayground(app); // (Optional) Mounts the GraphQL Playground - do NOT use in Production
// (Optional) Mounts the REST API
app.use('/parse', parseServer.app);
// Mounts the GraphQL API using graphQLPath: '/graphql'
parseGraphQLServer.applyGraphQL(app);
// (Optional) Mounts the GraphQL Playground - do NOT use in Production
parseGraphQLServer.applyPlayground(app);

// Start the server
app.listen(1337, function() {
console.log('REST API running on http://localhost:1337/parse');
console.log('GraphQL API running on http://localhost:1337/graphql');
Expand All @@ -86,22 +84,22 @@ app.listen(1337, function() {

And finally start your app:

```bash
```sh
$ npx mongodb-runner start
$ node index.js
```

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.

⚠️ 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.
⚠️ 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. If you want to secure your API in production take a look at [Class Level Permissions](/js/guide/#class-level-permissions).

## Running Parse Dashboard

[Parse Dashboard](https://github.com/parse-community/parse-dashboard) is a standalone dashboard for managing your Parse Server apps, including your objects' schema and data, logs, jobs, and push notifications. Parse Dashboard also has a built-in GraphQL Playground that you can use to play around with your auto-generated Parse GraphQL API. It is the recommended option for production applications.
[Parse Dashboard](https://github.com/parse-community/parse-dashboard) is a standalone dashboard for managing your Parse Server apps, including your objects' schema and data, logs, jobs, CLPs, and push notifications. Parse Dashboard also has a built-in GraphQL Playground that you can use to play around with your auto-generated Parse GraphQL API. It is the recommended option for **production** applications.

The easiest way to run the Parse Dashboard is through its CLI:

```bash
```sh
$ npm install -g parse-dashboard
$ parse-dashboard --dev --appId APPLICATION_ID --masterKey MASTER_KEY --serverURL "http://localhost:1337/parse" --graphQLServerURL "http://localhost:1337/graphql" --appName MyAppName
```
Expand All @@ -110,4 +108,4 @@ After starting the dashboard, you can visit [http://0.0.0.0:4040/apps/MyAppName/

<img alt="Parse Dashboard GraphQL Playground" data-echo="{{ '/assets/images/graphql/dashboard-graphql-playground.png' | prepend: site.baseurl }}"/>

To learn more about Parse Dashboard and its setup options, please visit [Parse Dashboard Repository](https://github.com/parse-community/parse-dashboard).
To learn more about Parse Dashboard and its setup options, please visit the [Parse Dashboard Repository](https://github.com/parse-community/parse-dashboard).
11 changes: 11 additions & 0 deletions _includes/graphql/graphql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GraphQL

Before continuing, it is recommended to study some of the GraphQL documentation:

A GraphQL API contains 3 main concepts:
* `Query`: Fetch data
* `Mutation`: Create or update data
* `Subscription`: Listen for data changes

## Learn Query & Mutation
To learn how to query data and execute operation on a GraphQL API [consult the official documentation](https://graphql.org/learn/queries/).
Loading