Allow to unset file from graphql (#6651)

This commit is contained in:
Antoine Cormouls
2020-04-30 07:18:25 +02:00
committed by GitHub
parent d279198db7
commit 4d1bd9346f
3 changed files with 85 additions and 50 deletions

View File

@@ -15,7 +15,7 @@ const transformTypes = async (
config: { isCreateEnabled, isUpdateEnabled },
} = parseGraphQLSchema.parseClassTypes[className];
const parseClass = parseGraphQLSchema.parseClasses.find(
clazz => clazz.className === className
(clazz) => clazz.className === className
);
if (fields) {
const classGraphQLCreateTypeFields =
@@ -26,7 +26,7 @@ const transformTypes = async (
isUpdateEnabled && classGraphQLUpdateType
? classGraphQLUpdateType.getFields()
: null;
const promises = Object.keys(fields).map(async field => {
const promises = Object.keys(fields).map(async (field) => {
let inputTypeField;
if (inputType === 'create' && classGraphQLCreateTypeFields) {
inputTypeField = classGraphQLCreateTypeFields[field];
@@ -73,6 +73,9 @@ const transformTypes = async (
const transformers = {
file: async ({ file, upload }, { config }) => {
if (file === null && !upload) {
return null;
}
if (upload) {
const { fileInfo } = await handleUpload(upload, config);
return { ...fileInfo, __type: 'File' };
@@ -81,15 +84,18 @@ const transformers = {
}
throw new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Invalid file upload.');
},
polygon: value => ({
polygon: (value) => ({
__type: 'Polygon',
coordinates: value.map(geoPoint => [geoPoint.latitude, geoPoint.longitude]),
coordinates: value.map((geoPoint) => [
geoPoint.latitude,
geoPoint.longitude,
]),
}),
geoPoint: value => ({
geoPoint: (value) => ({
...value,
__type: 'GeoPoint',
}),
ACL: value => {
ACL: (value) => {
const parseACL = {};
if (value.public) {
parseACL['*'] = {
@@ -98,7 +104,7 @@ const transformers = {
};
}
if (value.users) {
value.users.forEach(rule => {
value.users.forEach((rule) => {
const globalIdObject = fromGlobalId(rule.userId);
if (globalIdObject.type === '_User') {
rule.userId = globalIdObject.id;
@@ -110,7 +116,7 @@ const transformers = {
});
}
if (value.roles) {
value.roles.forEach(rule => {
value.roles.forEach((rule) => {
parseACL[`role:${rule.roleName}`] = {
read: rule.read,
write: rule.write,
@@ -141,7 +147,7 @@ const transformers = {
if (value.createAndAdd) {
nestedObjectsToAdd = (
await Promise.all(
value.createAndAdd.map(async input => {
value.createAndAdd.map(async (input) => {
const parseFields = await transformTypes('create', input, {
className: targetClass,
parseGraphQLSchema,
@@ -156,7 +162,7 @@ const transformers = {
);
})
)
).map(object => ({
).map((object) => ({
__type: 'Pointer',
className: targetClass,
objectId: object.objectId,
@@ -165,7 +171,7 @@ const transformers = {
if (value.add || nestedObjectsToAdd.length > 0) {
if (!value.add) value.add = [];
value.add = value.add.map(input => {
value.add = value.add.map((input) => {
const globalIdObject = fromGlobalId(input);
if (globalIdObject.type === targetClass) {
input = globalIdObject.id;
@@ -185,7 +191,7 @@ const transformers = {
if (value.remove) {
op.ops.push({
__op: 'RemoveRelation',
objects: value.remove.map(input => {
objects: value.remove.map((input) => {
const globalIdObject = fromGlobalId(input);
if (globalIdObject.type === targetClass) {
input = globalIdObject.id;