Files
kami-parse-server/src/GraphQL/parseGraphQLUtils.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

import Parse from 'parse/node';
import { GraphQLError } from 'graphql';
GraphQL schema operations (#5993) * Remove nested operations * Improve error log * Fix bug schema to load * Fix ParseGraphQLSchema tests * Fix tests * Fix failing tests * First verstion not complete of create class mutation * Fix bug caused by circular dependency * Renaming files * Schema types should be loaded before parse classes * Fix tests * Create class mutation boilerplate * Improve CreateClassSchemaInput fields names * Remove fields * Pointer and relation fields * Improve pointer default type * Class type * Create class mutation resolver * Schema field transformers * Class types transformations * First test * Numbers test * Boolean tests * Date test * Fix some get tests * Test for created at and updated at * File tests * Test for objects * Renaming reducerFabric to reducerGenerator * Changing get tests for file and object * Object composed queries test * Array test * Null field test * Bytes test * Geo Point test * Polygons tests * Remove create generic mutation * Fix tests * Create class test - isRequired and defaultValue will be added back later * Enforce master key * Fix tests * Duplicated field test * updateClass mutation * Remove update generic mutation tests * Remove update generic mutation * deleteClass mutation * Remove delete generic mutation tests * Remove delete generic mutation * class query * Classes query * Remove get generic query from tests * Remove remaining generic operations and fix tests * Fix last test * Try to fix redis tests * Fix postgres tests * Update objectsMutations and objectsQueries files locations * Rename classSchema files to schema files * Rename ClassObject to ParseObject * Fix names and paths * Still some wrong names
2019-09-01 22:11:03 -07:00
export function enforceMasterKeyAccess(auth) {
if (!auth.isMaster) {
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'unauthorized: master key is required');
GraphQL schema operations (#5993) * Remove nested operations * Improve error log * Fix bug schema to load * Fix ParseGraphQLSchema tests * Fix tests * Fix failing tests * First verstion not complete of create class mutation * Fix bug caused by circular dependency * Renaming files * Schema types should be loaded before parse classes * Fix tests * Create class mutation boilerplate * Improve CreateClassSchemaInput fields names * Remove fields * Pointer and relation fields * Improve pointer default type * Class type * Create class mutation resolver * Schema field transformers * Class types transformations * First test * Numbers test * Boolean tests * Date test * Fix some get tests * Test for created at and updated at * File tests * Test for objects * Renaming reducerFabric to reducerGenerator * Changing get tests for file and object * Object composed queries test * Array test * Null field test * Bytes test * Geo Point test * Polygons tests * Remove create generic mutation * Fix tests * Create class test - isRequired and defaultValue will be added back later * Enforce master key * Fix tests * Duplicated field test * updateClass mutation * Remove update generic mutation tests * Remove update generic mutation * deleteClass mutation * Remove delete generic mutation tests * Remove delete generic mutation * class query * Classes query * Remove get generic query from tests * Remove remaining generic operations and fix tests * Fix last test * Try to fix redis tests * Fix postgres tests * Update objectsMutations and objectsQueries files locations * Rename classSchema files to schema files * Rename ClassObject to ParseObject * Fix names and paths * Still some wrong names
2019-09-01 22:11:03 -07:00
}
}
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 GraphQLError(message, { extensions: { 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,
};
};
2020-07-13 13:06:52 -05:00
export const getParseClassMutationConfig = function (parseClassConfig) {
return (parseClassConfig && parseClassConfig.mutation) || {};
};