Skip to content

Commit e00a1e1

Browse files
MoumoulsTomWFox
andauthored
GraphQL: Add File & LogInWith (#702)
* Add file documentation * add loginWith doc * Update _includes/graphql/users.md * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Tom Fox <[email protected]>
1 parent 338dfd6 commit e00a1e1

File tree

3 files changed

+116
-10
lines changed

3 files changed

+116
-10
lines changed

_includes/graphql/files.md

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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).
44

5-
## Add a File field
5+
## Add a File field to a Class
66
First of all we will update our `GameScore` class with a `screenshot` field of type `File`.
77

88
```js
@@ -42,9 +42,9 @@ mutation updateGameScoreClass {
4242
}
4343
```
4444

45-
## Create and add File
45+
## Create a File
4646

47-
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.
47+
The GraphQL API supports nested mutation for the `File` type, so you can send the file along with the Parse Object or just upload the file and get the returned information.
4848

4949
```js
5050
// Header
@@ -79,7 +79,10 @@ mutation createFile($file: Upload!) {
7979
}
8080
```
8181

82-
Then add the file to a new `GameScore` object.
82+
## Add an existing file
83+
84+
You can add an existing file to an object.
85+
8386
```js
8487
// Header
8588
{
@@ -94,10 +97,60 @@ mutation createGameScore {
9497
input: {
9598
fields: {
9699
playerName: "John"
97-
screenshot: {
98-
__type: "File",
99-
name: "6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
100-
url: "http://localhost:1337/graphq/files/APPLICATION_ID/6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
100+
screenshot: {
101+
file :{
102+
__type: "File",
103+
name: "6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
104+
url: "http://localhost:1337/graphq/files/APPLICATION_ID/6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
105+
}
106+
}
107+
}
108+
}
109+
) {
110+
gameScore {
111+
screenshot {
112+
name
113+
url
114+
}
115+
}
116+
}
117+
}
118+
```
119+
```js
120+
// Response
121+
{
122+
"data": {
123+
"createGameScore": {
124+
"gameScore": {
125+
"screenshot": {
126+
"name": "6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png",
127+
"url": "http://localhost:1337/graphq/files/APPLICATION_ID/6a4d43c3f0512bcb6bf05b6b0e7db47d_file.png"
128+
}
129+
}
130+
}
131+
}
132+
}
133+
```
134+
135+
## Create and add a file
136+
Lets create a new `GameScore` object and upload the file.
137+
```js
138+
// Header
139+
{
140+
"X-Parse-Application-Id": "APPLICATION_ID",
141+
"X-Parse-Master-Key": "MASTER_KEY" // (optional)
142+
}
143+
```
144+
```graphql
145+
# GraphQL
146+
# $file is a GraphQL Variable, see https://github.com/jaydenseric/apollo-upload-client
147+
mutation createGameScore($file: Upload! ) {
148+
createGameScore(
149+
input: {
150+
fields: {
151+
playerName: "John"
152+
screenshot: {
153+
upload : $file
101154
}
102155
}
103156
}

_includes/graphql/objects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ The code above should resolve to something similar to this:
161161

162162
## Nested Mutation
163163

164-
The GraphQL API supports nested mutations (except for `File`), so you can create objects with complex relationships in one request. Assuming that we have classes `Country`, `City` and `Company`.
164+
The GraphQL API supports nested mutations, so you can create objects with complex relationships in one request. Assuming that we have classes `Country`, `City` and `Company`.
165165

166166
```js
167167
// Header

_includes/graphql/users.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To sign up a new user, use the `signUp` mutation. For example:
2424
mutation signUp {
2525
signUp(
2626
input: {
27-
userFields: {
27+
fields: {
2828
username: "johndoe"
2929
password: "ASuperStrongPassword"
3030
@@ -72,6 +72,7 @@ After you allow users to sign up, you need to let them log in to their account w
7272
}
7373
```
7474
```graphql
75+
# GraphQL
7576
mutation logIn {
7677
logIn(input: { username: "johndoe", password: "ASuperStrongPassword" }) {
7778
viewer {
@@ -103,6 +104,58 @@ mutation logIn {
103104

104105
Note that, when the user logs in, Parse Server generates a new `sessionToken` for future operations.
105106

107+
## 3rd Party Authentication
108+
109+
You can log in a user via a [3rd party authentication](https://docs.parseplatform.org/parse-server/guide/#supported-3rd-party-authentications) system (Facebook, Twitter, Apple and many more) with the `logInWith` mutation.
110+
111+
```js
112+
// Header
113+
{
114+
"X-Parse-Application-Id": "APPLICATION_ID",
115+
"X-Parse-Master-Key": "MASTER_KEY" // optional
116+
}
117+
```
118+
```graphql
119+
# GraphQL
120+
mutation LoginWithFacebook {
121+
logInWith(
122+
input: {
123+
authData: {
124+
facebook: {
125+
id: "user's Facebook id number as a string"
126+
access_token: "Facebook access token for the user"
127+
expiration_date: "token expiration date"
128+
}
129+
}
130+
fields: { email: "[email protected]" }
131+
}
132+
) {
133+
viewer {
134+
sessionToken
135+
user {
136+
id
137+
email
138+
}
139+
}
140+
}
141+
}
142+
```
143+
```js
144+
// Response
145+
{
146+
"data": {
147+
"logInWith": {
148+
"viewer": {
149+
"sessionToken": "r:b0dfad1eeafa4425d9508f1c0a15c3fa",
150+
"user": {
151+
"email": "[email protected]"
152+
}
153+
}
154+
}
155+
}
156+
}
157+
```
158+
106159
## Using Session Token
107160

108161
For authenticating an operation as a specific user, you need to pass the `X-Parse-Session-Token` header with its valid session token.

0 commit comments

Comments
 (0)