123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.enforceMasterKeyAccess = enforceMasterKeyAccess;
- exports.getParseClassMutationConfig = exports.extractKeysAndInclude = void 0;
- exports.toGraphQLError = toGraphQLError;
- var _node = _interopRequireDefault(require("parse/node"));
- var _graphql = require("graphql");
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- function enforceMasterKeyAccess(auth) {
- if (!auth.isMaster) {
- throw new _node.default.Error(_node.default.Error.OPERATION_FORBIDDEN, 'unauthorized: master key is required');
- }
- }
- function toGraphQLError(error) {
- let code, message;
- if (error instanceof _node.default.Error) {
- code = error.code;
- message = error.message;
- } else {
- code = _node.default.Error.INTERNAL_SERVER_ERROR;
- message = 'Internal server error';
- }
- return new _graphql.GraphQLError(message, {
- extensions: {
- code
- }
- });
- }
- 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
- };
- };
- exports.extractKeysAndInclude = extractKeysAndInclude;
- const getParseClassMutationConfig = function (parseClassConfig) {
- return parseClassConfig && parseClassConfig.mutation || {};
- };
- exports.getParseClassMutationConfig = getParseClassMutationConfig;
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfbm9kZSIsIl9pbnRlcm9wUmVxdWlyZURlZmF1bHQ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