-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathGraphQLRouter.js
38 lines (33 loc) · 1.07 KB
/
GraphQLRouter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Parse from 'parse/node';
import PromiseRouter from '../PromiseRouter';
import * as middleware from '../middlewares';
const GraphQLConfigPath = '/graphql-config';
export class GraphQLRouter extends PromiseRouter {
async getGraphQLConfig(req) {
const result = await req.config.parseGraphQLController.getGraphQLConfig();
return {
response: result,
};
}
async updateGraphQLConfig(req) {
if (req.auth.isReadOnly) {
throw new Parse.Error(
Parse.Error.OPERATION_FORBIDDEN,
"read-only masterKey isn't allowed to update the GraphQL config."
);
}
const data = await req.config.parseGraphQLController.updateGraphQLConfig(req.body.params || {});
return {
response: data,
};
}
mountRoutes() {
this.route('GET', GraphQLConfigPath, middleware.promiseEnforceMasterKeyAccess, req => {
return this.getGraphQLConfig(req);
});
this.route('PUT', GraphQLConfigPath, middleware.promiseEnforceMasterKeyAccess, req => {
return this.updateGraphQLConfig(req);
});
}
}
export default GraphQLRouter;