diff --git a/_includes/graphql/objects.md b/_includes/graphql/objects.md index 949f21fd7..afceda635 100644 --- a/_includes/graphql/objects.md +++ b/_includes/graphql/objects.md @@ -10,18 +10,16 @@ For creating an object, you simply need to set whatever key-value pairs you want ```graphql mutation CreateObject { - objects { - create( - className: "GameScore" - fields: { - score: 1337 - playerName: "Sean Plott" - cheatMode: false - } - ) { - objectId - createdAt + create( + className: "GameScore" + fields: { + score: 1337 + playerName: "Sean Plott" + cheatMode: false } + ) { + objectId + createdAt } } ``` @@ -31,11 +29,9 @@ If you execute the code above in your GraphQL Playground, you should receive a r ```json { "data": { - "objects": { - "create": { - "objectId": "MssDRE0I0s", - "createdAt": "2019-07-08T21:23:21.275Z" - } + "create": { + "objectId": "EGyoD3goxn", + "createdAt": "2019-08-27T06:53:08.780Z" } } } @@ -51,15 +47,13 @@ For example, if you have a class named `GameScore` in the schema, Parse Server a ```graphql mutation CreateGameScore { - objects { - createGameScore(fields: { - score: 80075 - playerName: "Jang Min Chul" - cheatMode: false - }) { - objectId - createdAt - } + createGameScore(fields: { + score: 80075 + playerName: "Jang Min Chul" + cheatMode: false + }) { + objectId + createdAt } } ``` @@ -69,11 +63,9 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "createGameScore": { - "objectId": "sCR5LNkF0z", - "createdAt": "2019-07-08T21:24:24.727Z" - } + "createGameScore": { + "objectId": "NNfsmFxMIv", + "createdAt": "2019-08-27T06:57:18.452Z" } } } @@ -87,9 +79,7 @@ You can get an existing object by its `className` and `objectId` using the `get` ```graphql query GetObject { - objects { - get(className: "GameScore" objectId: "MssDRE0I0s") - } + get(className: "GameScore" objectId: "EGyoD3goxn") } ``` @@ -98,15 +88,13 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "get": { - "objectId": "MssDRE0I0s", - "score": 1337, - "playerName": "Sean Plott", - "cheatMode": false, - "createdAt": "2019-07-08T21:23:21.275Z", - "updatedAt": "2019-07-08T21:23:21.275Z" - } + "get": { + "objectId": "EGyoD3goxn", + "score": 1337, + "playerName": "Sean Plott", + "cheatMode": false, + "createdAt": "2019-08-27T06:53:08.780Z", + "updatedAt": "2019-08-27T06:53:08.780Z" } } } @@ -116,19 +104,17 @@ The code above should resolve to something similar to this: For each class of your application's schema, Parse Server automatically generates a custom query for getting this class' objects through the GraphQL API. -For example, if you have a class named `GameScore` in the schema, Parse Server automatically generates a new query called `getGameScore`, and you should be able to run the code below in your GraphQL Playground: +For example, if you have a class named `GameScore` in the schema, Parse Server automatically generates a new query called `gameScore`, and you should be able to run the code below in your GraphQL Playground: ```graphql -query GetGameScore { - objects { - getGameScore(objectId: "MssDRE0I0s") { - objectId - playerName - score - cheatMode - createdAt - updatedAt - } +query GameScore { + gameScore(objectId: "EGyoD3goxn") { + objectId + playerName + score + cheatMode + createdAt + updatedAt } } ``` @@ -138,15 +124,13 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "getGameScore": { - "objectId": "MssDRE0I0s", - "playerName": "Sean Plott", - "score": 1337, - "cheatMode": false, - "createdAt": "2019-07-08T21:23:21.275Z", - "updatedAt": "2019-07-08T21:23:21.275Z" - } + "gameScore": { + "objectId": "EGyoD3goxn", + "playerName": "Sean Plott", + "score": 1337, + "cheatMode": false, + "createdAt": "2019-08-27T06:53:08.780Z", + "updatedAt": "2019-08-27T06:53:08.780Z" } } } @@ -160,11 +144,9 @@ You can retrieve multiple objects at once using the `find` query. For example: ```graphql query FindObjects { - objects { - find(className: "GameScore") { - count - results - } + find(className: "GameScore") { + count + results } } ``` @@ -174,28 +156,26 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "find": { - "count": 2, - "results": [ - { - "objectId": "MssDRE0I0s", - "score": 1337, - "playerName": "Sean Plott", - "cheatMode": false, - "createdAt": "2019-07-08T21:23:21.275Z", - "updatedAt": "2019-07-08T21:23:21.275Z" - }, - { - "objectId": "sCR5LNkF0z", - "playerName": "Jang Min Chul", - "score": 80075, - "cheatMode": false, - "createdAt": "2019-07-08T21:24:24.727Z", - "updatedAt": "2019-07-08T21:24:24.727Z" - } - ] - } + "find": { + "count": 2, + "results": [ + { + "objectId": "EGyoD3goxn", + "score": 1337, + "playerName": "Sean Plott", + "cheatMode": false, + "createdAt": "2019-08-27T06:53:08.780Z", + "updatedAt": "2019-08-27T06:53:08.780Z" + }, + { + "objectId": "NNfsmFxMIv", + "playerName": "Jang Min Chul", + "score": 80075, + "cheatMode": false, + "createdAt": "2019-08-27T06:57:18.452Z", + "updatedAt": "2019-08-27T06:57:18.452Z" + } + ] } } } @@ -205,21 +185,19 @@ The code above should resolve to something similar to this: For each class of your application's schema, Parse Server automatically generates a custom query for finding this class' objects through the GraphQL API. -For example, if you have a class named `GameScore` in the schema, Parse Server automatically generates a new query called `findGameScore`, and you should be able to run the code below in your GraphQL Playground: +For example, if you have a class named `GameScore` in the schema, Parse Server automatically generates a new query called `gameScores`, and you should be able to run the code below in your GraphQL Playground: ```graphql -query FindGameScore { - objects { - findGameScore { - count - results { - objectId - playerName - score - cheatMode - createdAt - updatedAt - } +query GameScores { + gameScores { + count + results { + objectId + playerName + score + cheatMode + createdAt + updatedAt } } } @@ -230,28 +208,26 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "findGameScore": { - "count": 2, - "results": [ - { - "objectId": "MssDRE0I0s", - "playerName": "Sean Plott", - "score": 1337, - "cheatMode": false, - "createdAt": "2019-07-08T21:23:21.275Z", - "updatedAt": "2019-07-08T21:23:21.275Z" - }, - { - "objectId": "sCR5LNkF0z", - "playerName": "Jang Min Chul", - "score": 80075, - "cheatMode": false, - "createdAt": "2019-07-08T21:24:24.727Z", - "updatedAt": "2019-07-08T21:24:24.727Z" - } - ] - } + "gameScores": { + "count": 2, + "results": [ + { + "objectId": "EGyoD3goxn", + "playerName": "Sean Plott", + "score": 1337, + "cheatMode": false, + "createdAt": "2019-08-27T06:53:08.780Z", + "updatedAt": "2019-08-27T06:53:08.780Z" + }, + { + "objectId": "NNfsmFxMIv", + "playerName": "Jang Min Chul", + "score": 80075, + "cheatMode": false, + "createdAt": "2019-08-27T06:57:18.452Z", + "updatedAt": "2019-08-27T06:57:18.452Z" + } + ] } } } @@ -263,18 +239,16 @@ You can use the `where` argument to add constraints to either a generic or a cla ```graphql query ConstraintsExamples { - objects { - genericExample: find( - className: "GameScore" - where: { score: { _lt: 1500 } } - ) { - count - } - classExample: findGameScore( - where: { score: { _gt: 1500 } } - ) { - count - } + genericExample: find( + className: "GameScore" + where: { score: { _lt: 1500 } } + ) { + count + } + classExample: gameScores( + where: { score: { _gt: 1500 } } + ) { + count } } ``` @@ -284,13 +258,11 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "genericExample": { - "count": 1 - }, - "classExample": { - "count": 1 - } + "genericExample": { + "count": 1 + }, + "classExample": { + "count": 1 } } } @@ -302,22 +274,20 @@ You can use the `order` argument to select in which order the results should sho ```graphql query OrderExamples { - objects { - genericExample: find( - className: "GameScore" - where: { cheatMode: false } - order: "-score" - ) { - results - } - classExample: findGameScore( - where: { cheatMode: { _eq: false } } - order: [score_ASC] - ) { - results { - playerName - score - } + genericExample: find( + className: "GameScore" + where: { cheatMode: false } + order: "-score" + ) { + results + } + classExample: gameScores( + where: { cheatMode: { _eq: false } } + order: [score_ASC] + ) { + results { + playerName + score } } } @@ -328,39 +298,37 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "genericExample": { - "results": [ - { - "objectId": "sCR5LNkF0z", - "playerName": "Jang Min Chul", - "score": 80075, - "cheatMode": false, - "createdAt": "2019-07-08T21:24:24.727Z", - "updatedAt": "2019-07-08T21:24:24.727Z" - }, - { - "objectId": "MssDRE0I0s", - "score": 1337, - "playerName": "Sean Plott", - "cheatMode": false, - "createdAt": "2019-07-08T21:23:21.275Z", - "updatedAt": "2019-07-08T21:23:21.275Z" - } - ] - }, - "classExample": { - "results": [ - { - "playerName": "Sean Plott", - "score": 1337 - }, - { - "playerName": "Jang Min Chul", - "score": 80075 - } - ] - } + "genericExample": { + "results": [ + { + "objectId": "NNfsmFxMIv", + "playerName": "Jang Min Chul", + "score": 80075, + "cheatMode": false, + "createdAt": "2019-08-27T06:57:18.452Z", + "updatedAt": "2019-08-27T06:57:18.452Z" + }, + { + "objectId": "EGyoD3goxn", + "score": 1337, + "playerName": "Sean Plott", + "cheatMode": false, + "createdAt": "2019-08-27T06:53:08.780Z", + "updatedAt": "2019-08-27T06:53:08.780Z" + } + ] + }, + "classExample": { + "results": [ + { + "playerName": "Sean Plott", + "score": 1337 + }, + { + "playerName": "Jang Min Chul", + "score": 80075 + } + ] } } } @@ -372,26 +340,24 @@ You can use the `skip` and `limit` arguments to paginate the results either in a ```graphql query PaginationExamples { - objects { - genericExample: find( - className: "GameScore" - where: { cheatMode: false } - order: "-score" - skip: 0 - limit: 1 - ) { - results - } - classExample: findGameScore( - where: { cheatMode: { _eq: false } } - order: [score_DESC] - skip: 1 - limit: 1 - ) { - results { - playerName - score - } + genericExample: find( + className: "GameScore" + where: { cheatMode: false } + order: "-score" + skip: 0 + limit: 1 + ) { + results + } + classExample: gameScores( + where: { cheatMode: { _eq: false } } + order: [score_DESC] + skip: 1 + limit: 1 + ) { + results { + playerName + score } } } @@ -402,27 +368,25 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "genericExample": { - "results": [ - { - "objectId": "sCR5LNkF0z", - "playerName": "Jang Min Chul", - "score": 80075, - "cheatMode": false, - "createdAt": "2019-07-08T21:24:24.727Z", - "updatedAt": "2019-07-08T21:24:24.727Z" - } - ] - }, - "classExample": { - "results": [ - { - "playerName": "Sean Plott", - "score": 1337 - } - ] - } + "genericExample": { + "results": [ + { + "objectId": "NNfsmFxMIv", + "playerName": "Jang Min Chul", + "score": 80075, + "cheatMode": false, + "createdAt": "2019-08-27T06:57:18.452Z", + "updatedAt": "2019-08-27T06:57:18.452Z" + } + ] + }, + "classExample": { + "results": [ + { + "playerName": "Sean Plott", + "score": 1337 + } + ] } } } @@ -436,14 +400,12 @@ You can update an existing object using the `update` mutation. You simply need t ```graphql mutation UpdateObject { - objects { - update( - className: "GameScore" - objectId: "sCR5LNkF0z" - fields: { ranking: 1 } - ) { - updatedAt - } + update( + className: "GameScore" + objectId: "NNfsmFxMIv" + fields: { ranking: 1 } + ) { + updatedAt } } ``` @@ -453,10 +415,8 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "update": { - "updatedAt": "2019-07-08T22:52:41.874Z" - } + "update": { + "updatedAt": "2019-08-27T07:14:04.346Z" } } } @@ -470,13 +430,11 @@ For example, if you have a class named `GameScore` in the schema, Parse Server a ```graphql mutation UpdateGameScore { - objects { - updateGameScore( - objectId: "MssDRE0I0s" - fields: { ranking: 2 } - ) { - updatedAt - } + updateGameScore( + objectId: "EGyoD3goxn" + fields: { ranking: 2 } + ) { + updatedAt } } ``` @@ -486,10 +444,8 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "updateGameScore": { - "updatedAt": "2019-07-08T22:55:53.853Z" - } + "updateGameScore": { + "updatedAt": "2019-08-27T07:15:05.351Z" } } } @@ -503,9 +459,7 @@ You can delete an existing object using the `delete` mutation. You simply need t ```graphql mutation DeleteObject { - objects { - delete(className: "GameScore" objectId: "MssDRE0I0s") - } + delete(className: "GameScore" objectId: "NNfsmFxMIv") } ``` @@ -514,9 +468,7 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "delete": true - } + "delete": true } } ``` @@ -529,8 +481,8 @@ For example, if you have a class named `GameScore` in the schema, Parse Server a ```graphql mutation DeleteGameScore { - objects { - deleteGameScore(objectId: "sCR5LNkF0z") + deleteGameScore(objectId: "EGyoD3goxn") { + objectId } } ``` @@ -540,8 +492,8 @@ The code above should resolve to something similar to this: ```json { "data": { - "objects": { - "deleteGameScore": true + "deleteGameScore": { + "objectId": "EGyoD3goxn" } } } diff --git a/_includes/graphql/users.md b/_includes/graphql/users.md index ccb1eca51..efee8a58b 100644 --- a/_includes/graphql/users.md +++ b/_includes/graphql/users.md @@ -2,7 +2,7 @@ In general, users have the same features as other objects, such as the flexible schema. The differences are that user objects must have a username and password, the password is automatically encrypted and stored securely, and Parse Server enforces the uniqueness of the username and email fields. -Therefore you can manage users objects using the `create_User`, `get_User`, `find_User`, `update_User`, `delete_User`, and the generic operations with `_User` in the `className` argument. +Therefore you can manage users objects using the `createUser`, `user`, `users`, `updateUser`, `deleteUser`, and the generic operations with `_User` in the `className` argument. Additionally, you can use the `signUp`, `logIn`, and `logOut` operations, which will be presented in the following sections. @@ -16,15 +16,13 @@ To sign up a new user, use the `signUp` mutation. For example: ```graphql mutation SignUp { - users { - signUp(fields: { - username: "somedude" - password: "Parse_3.5_Rocks!" - }) { - objectId - createdAt - sessionToken - } + signUp(fields: { + username: "somedude" + password: "Parse_3.5_Rocks!" + }) { + objectId + createdAt + sessionToken } } ``` @@ -34,12 +32,10 @@ The code above should resolve to something similar to this: ```json { "data": { - "users": { - "signUp": { - "objectId": "nkGmXzlTnA", - "createdAt": "2019-07-08T23:59:35.694Z", - "sessionToken": "r:9cfef8ec8e77c4e01f6e1069d0a199d8" - } + "signUp": { + "objectId": "A13obRUwDE", + "createdAt": "2019-08-27T07:22:25.251Z", + "sessionToken": "r:caca30fa5c68f0ce467e7790a7208ff7" } } } @@ -53,14 +49,12 @@ After you allow users to sign up, you need to let them log in to their account w ```graphql mutation LogIn { - users { - logIn(username: "somedude" password: "Parse_3.5_Rocks!") { - objectId - username - sessionToken - createdAt - updatedAt - } + logIn(fields: { username: "somedude" password: "Parse_3.5_Rocks!" }) { + objectId + username + sessionToken + createdAt + updatedAt } } ``` @@ -70,14 +64,12 @@ The code above should resolve to something similar to this: ```json { "data": { - "users": { - "logIn": { - "objectId": "nkGmXzlTnA", - "username": "somedude", - "sessionToken": "r:28eeeed86ad96e88e120783b2ea612ef", - "createdAt": "2019-07-08T23:59:35.694Z", - "updatedAt": "2019-07-08T23:59:35.694Z" - } + "logIn": { + "objectId": "A13obRUwDE", + "username": "somedude", + "sessionToken": "r:28eeeed86ad96e88e120783b2ea612ef", + "createdAt": "2019-08-27T07:22:25.251Z", + "updatedAt": "2019-08-27T07:22:25.251Z" } } } @@ -96,11 +88,9 @@ You can easily do this in the GraphQL Playground. There is an option called `HTT After setting up the `X-Parse-Session-Token` header, any operation will run as this user. For example, you can run the code below to validate the session token and return its associated user: ```graphql -query Me { - users { - me { - username - } +query Viewer { + viewer { + username } } ``` @@ -110,10 +100,8 @@ The code above should resolve to something similar to this: ```json { "data": { - "users": { - "me": { - "username": "somedude" - } + "viewer": { + "username": "somedude" } } } @@ -125,8 +113,8 @@ You can log out a user through the `logOut` mutation. You need to send the `X-Pa ```graphql mutation LogOut { - users { - logOut + logOut { + username } } ``` @@ -136,8 +124,8 @@ The code above should resolve to something similar to this: ```json { "data": { - "users": { - "logOut": true + "logOut": { + "username": "somedude" } } }