forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigMutations.js
More file actions
76 lines (67 loc) · 2.37 KB
/
configMutations.js
File metadata and controls
76 lines (67 loc) · 2.37 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { GraphQLNonNull, GraphQLString, GraphQLBoolean } from 'graphql';
import { mutationWithClientMutationId } from 'graphql-relay';
import Parse from 'parse/node';
import { createSanitizedError } from '../../Error';
import GlobalConfigRouter from '../../Routers/GlobalConfigRouter';
const globalConfigRouter = new GlobalConfigRouter();
const updateCloudConfig = async (context, paramName, value, isMasterKeyOnly = false) => {
const { config, auth } = context;
if (!auth.isMaster) {
throw createSanitizedError(
Parse.Error.OPERATION_FORBIDDEN,
'Master Key is required to update GlobalConfig.'
);
}
await globalConfigRouter.updateGlobalConfig({
body: {
params: { [paramName]: value },
masterKeyOnly: { [paramName]: isMasterKeyOnly },
},
config,
auth,
context,
});
return { value, isMasterKeyOnly };
};
const load = parseGraphQLSchema => {
const updateCloudConfigMutation = mutationWithClientMutationId({
name: 'UpdateCloudConfig',
description: 'Updates the value of a specific parameter in GlobalConfig.',
inputFields: {
paramName: {
description: 'The name of the parameter to set.',
type: new GraphQLNonNull(GraphQLString),
},
value: {
description: 'The value to set for the parameter.',
type: new GraphQLNonNull(GraphQLString),
},
isMasterKeyOnly: {
description: 'Whether this parameter should only be accessible with master key.',
type: GraphQLBoolean,
defaultValue: false,
},
},
outputFields: {
cloudConfig: {
description: 'The updated config value.',
type: new GraphQLNonNull(parseGraphQLSchema.cloudConfigType),
},
},
mutateAndGetPayload: async (args, context) => {
try {
const { paramName, value, isMasterKeyOnly } = args;
const result = await updateCloudConfig(context, paramName, value, isMasterKeyOnly);
return {
cloudConfig: result,
};
} catch (e) {
parseGraphQLSchema.handleError(e);
}
},
});
parseGraphQLSchema.addGraphQLType(updateCloudConfigMutation.args.input.type.ofType, true, true);
parseGraphQLSchema.addGraphQLType(updateCloudConfigMutation.type, true, true);
parseGraphQLSchema.addGraphQLMutation('updateCloudConfig', updateCloudConfigMutation, true, true);
};
export { load, updateCloudConfig };