You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _includes/graphql/customisation.md
+145Lines changed: 145 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -287,3 +287,148 @@ You can optionally override the default generated mutation names with aliases:
287
287
]
288
288
}
289
289
```
290
+
291
+
## Cloud Code Resolvers
292
+
293
+
The Parse GraphQL API supports the use of custom user-defined schema. The [Adding Custom Schema](#adding-custom-schema) section explains how to get started using this feature.
294
+
295
+
Cloud Code functions can then be used as custom resolvers for your user-defined schema.
296
+
297
+
### Query Resolvers
298
+
299
+
Here's an example of a custom query and its related cloud code function resolver in action:
At times, you may need more control over how your mutations modify data than what Parse's auto-generated mutations can provide. For example, if you have classes named `Item` and `CartItem` in the schema, you can create an `addToCart` custom mutation that tests whether a specific item is already in the user's cart. If found, the cart item's quantity is incremented by one. If not, a new `CartItem` object is created.
341
+
342
+
The ability to branch your resolver logic enables you to replicate functionality found in Parse's auto-generated `createCartItem` and `updateCartItem` mutations and combine those behaviors into a single custom resolver.
Copy file name to clipboardExpand all lines: _includes/graphql/getting-started.md
+65Lines changed: 65 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,71 @@ After starting the app, you can visit [http://localhost:1337/playground](http://
93
93
94
94
⚠️ 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).
95
95
96
+
## Adding Custom Schema
97
+
98
+
The Parse GraphQL API supports the use of custom user-defined schema. You can write your own types, queries, and mutations, which will be merged with the ones that are automatically generated. Your custom schema is resolved via [Cloud Code](#cloud-code-resolvers) functions.
99
+
100
+
First, add a utility for parsing GraphQL queries as a required dependency:
101
+
102
+
```sh
103
+
$ npm install graphql-tag --save
104
+
```
105
+
106
+
Then, modify your `index.js` file to include your custom schema, along with the path to your cloud code file:
107
+
108
+
```js
109
+
constgql=require('graphql-tag');
110
+
111
+
constparseServer=newParseServer({
112
+
appId:'APPLICATION_ID',
113
+
cloud:'./cloud/main.js',
114
+
});
115
+
116
+
constparseGraphQLServer=newParseGraphQLServer(
117
+
parseServer,
118
+
{
119
+
graphQLPath:'/graphql',
120
+
playgroundPath:'/playground',
121
+
graphQLCustomTypeDefs:gql`
122
+
extendtypeQuery {
123
+
hello: String!@resolve
124
+
hello2: String!@resolve(to: "hello")
125
+
}
126
+
`,
127
+
}
128
+
);
129
+
```
130
+
131
+
Alternatively, you can create your custom schema in a dedicated `schema.graphql` file and reference the file in your `index.js`:
[ParseDashboard](https://github.com/parse-community/parse-dashboard) isastandalonedashboardformanagingyourParseServerapps, includingyourobjects' 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.
Copy file name to clipboardExpand all lines: _includes/graphql/objects.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ mutation createAGameScore {
70
70
}
71
71
```
72
72
73
-
**Note:** The `id` is a [Relay Global Object Identification](https://facebook.github.io/relay/graphql/objectidentification.htm), it's **not** a Parse `objectId`. Most of the time the `Relay Node Id` is a `Base64` of the `ParseClass` and the `objectId`.
73
+
**Note:** The `id` is a [Relay Global Object Identification](https://facebook.github.io/relay/graphql/objectidentification.htm); it's **not** a Parse `objectId`. Most of the time the `Relay Node Id` is a `Base64` of the `ParseClass` and the `objectId`.
0 commit comments