forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseGraphQLUtils.js
More file actions
52 lines (46 loc) · 1.6 KB
/
parseGraphQLUtils.js
File metadata and controls
52 lines (46 loc) · 1.6 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
import Parse from 'parse/node';
import { ApolloError } from 'apollo-server-core';
export function enforceMasterKeyAccess(auth) {
if (!auth.isMaster) {
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'unauthorized: master key is required');
}
}
export function toGraphQLError(error) {
let code, message;
if (error instanceof Parse.Error) {
code = error.code;
message = error.message;
} else {
code = Parse.Error.INTERNAL_SERVER_ERROR;
message = 'Internal server error';
}
return new ApolloError(message, code);
}
export const extractKeysAndInclude = selectedFields => {
selectedFields = selectedFields.filter(field => !field.includes('__typename'));
// Handles "id" field for both current and included objects
selectedFields = selectedFields.map(field => {
if (field === 'id') return 'objectId';
return field.endsWith('.id')
? `${field.substring(0, field.lastIndexOf('.id'))}.objectId`
: field;
});
let keys = undefined;
let include = undefined;
if (selectedFields.length > 0) {
keys = [...new Set(selectedFields)].join(',');
// We can use this shortcut since optimization is handled
// later on RestQuery, avoid overhead here.
include = keys;
}
return {
// If authData is detected keys will not work properly
// since authData has a special storage behavior
// so we need to skip keys currently
keys: keys && keys.indexOf('authData') === -1 ? keys : undefined,
include,
};
};
export const getParseClassMutationConfig = function (parseClassConfig) {
return (parseClassConfig && parseClassConfig.mutation) || {};
};