Fix Prettier (#7066)

This commit is contained in:
Diamond Lewis
2020-12-13 11:19:04 -06:00
committed by GitHub
parent d4948572a8
commit 033a0bd443
64 changed files with 697 additions and 1887 deletions

View File

@@ -2,10 +2,7 @@ import { GraphQLNonNull } from 'graphql';
import { fromGlobalId, mutationWithClientMutationId } from 'graphql-relay';
import getFieldNames from 'graphql-list-fields';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
import {
extractKeysAndInclude,
getParseClassMutationConfig,
} from '../parseGraphQLUtils';
import { extractKeysAndInclude, getParseClassMutationConfig } from '../parseGraphQLUtils';
import * as objectsMutations from '../helpers/objectsMutations';
import * as objectsQueries from '../helpers/objectsQueries';
import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLController';
@@ -18,17 +15,10 @@ const getOnlyRequiredFields = (
includedFieldsString,
nativeObjectFields
) => {
const includedFields = includedFieldsString
? includedFieldsString.split(',')
: [];
const selectedFields = selectedFieldsString
? selectedFieldsString.split(',')
: [];
const includedFields = includedFieldsString ? includedFieldsString.split(',') : [];
const selectedFields = selectedFieldsString ? selectedFieldsString.split(',') : [];
const missingFields = selectedFields
.filter(
field =>
!nativeObjectFields.includes(field) || includedFields.includes(field)
)
.filter(field => !nativeObjectFields.includes(field) || includedFields.includes(field))
.join(',');
if (!missingFields.length) {
return { needGet: false, keys: '' };
@@ -37,15 +27,10 @@ const getOnlyRequiredFields = (
}
};
const load = function(
parseGraphQLSchema,
parseClass,
parseClassConfig: ?ParseGraphQLClassConfig
) {
const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseGraphQLClassConfig) {
const className = parseClass.className;
const graphQLClassName = transformClassNameToGraphQL(className);
const getGraphQLQueryName =
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
const getGraphQLQueryName = graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
const {
create: isCreateEnabled = true,
@@ -63,24 +48,20 @@ const load = function(
} = parseGraphQLSchema.parseClassTypes[className];
if (isCreateEnabled) {
const createGraphQLMutationName =
createAlias || `create${graphQLClassName}`;
const createGraphQLMutationName = createAlias || `create${graphQLClassName}`;
const createGraphQLMutation = mutationWithClientMutationId({
name: `Create${graphQLClassName}`,
description: `The ${createGraphQLMutationName} mutation can be used to create a new object of the ${graphQLClassName} class.`,
inputFields: {
fields: {
description:
'These are the fields that will be used to create the new object.',
description: 'These are the fields that will be used to create the new object.',
type: classGraphQLCreateType || defaultGraphQLTypes.OBJECT,
},
},
outputFields: {
[getGraphQLQueryName]: {
description: 'This is the created object.',
type: new GraphQLNonNull(
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
),
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
},
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
@@ -106,12 +87,12 @@ const load = function(
.filter(field => field.startsWith(`${getGraphQLQueryName}.`))
.map(field => field.replace(`${getGraphQLQueryName}.`, ''));
const { keys, include } = extractKeysAndInclude(selectedFields);
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(
fields,
keys,
include,
['id', 'objectId', 'createdAt', 'updatedAt']
);
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(fields, keys, include, [
'id',
'objectId',
'createdAt',
'updatedAt',
]);
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
parseClass.fields,
keys,
@@ -160,38 +141,29 @@ const load = function(
});
if (
parseGraphQLSchema.addGraphQLType(
createGraphQLMutation.args.input.type.ofType
) &&
parseGraphQLSchema.addGraphQLType(createGraphQLMutation.args.input.type.ofType) &&
parseGraphQLSchema.addGraphQLType(createGraphQLMutation.type)
) {
parseGraphQLSchema.addGraphQLMutation(
createGraphQLMutationName,
createGraphQLMutation
);
parseGraphQLSchema.addGraphQLMutation(createGraphQLMutationName, createGraphQLMutation);
}
}
if (isUpdateEnabled) {
const updateGraphQLMutationName =
updateAlias || `update${graphQLClassName}`;
const updateGraphQLMutationName = updateAlias || `update${graphQLClassName}`;
const updateGraphQLMutation = mutationWithClientMutationId({
name: `Update${graphQLClassName}`,
description: `The ${updateGraphQLMutationName} mutation can be used to update an object of the ${graphQLClassName} class.`,
inputFields: {
id: defaultGraphQLTypes.GLOBAL_OR_OBJECT_ID_ATT,
fields: {
description:
'These are the fields that will be used to update the object.',
description: 'These are the fields that will be used to update the object.',
type: classGraphQLUpdateType || defaultGraphQLTypes.OBJECT,
},
},
outputFields: {
[getGraphQLQueryName]: {
description: 'This is the updated object.',
type: new GraphQLNonNull(
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
),
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
},
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
@@ -225,12 +197,11 @@ const load = function(
.filter(field => field.startsWith(`${getGraphQLQueryName}.`))
.map(field => field.replace(`${getGraphQLQueryName}.`, ''));
const { keys, include } = extractKeysAndInclude(selectedFields);
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(
fields,
keys,
include,
['id', 'objectId', 'updatedAt']
);
const { keys: requiredKeys, needGet } = getOnlyRequiredFields(fields, keys, include, [
'id',
'objectId',
'updatedAt',
]);
const needToGetAllKeys = objectsQueries.needToGetAllKeys(
parseClass.fields,
keys,
@@ -279,21 +250,15 @@ const load = function(
});
if (
parseGraphQLSchema.addGraphQLType(
updateGraphQLMutation.args.input.type.ofType
) &&
parseGraphQLSchema.addGraphQLType(updateGraphQLMutation.args.input.type.ofType) &&
parseGraphQLSchema.addGraphQLType(updateGraphQLMutation.type)
) {
parseGraphQLSchema.addGraphQLMutation(
updateGraphQLMutationName,
updateGraphQLMutation
);
parseGraphQLSchema.addGraphQLMutation(updateGraphQLMutationName, updateGraphQLMutation);
}
}
if (isDestroyEnabled) {
const deleteGraphQLMutationName =
destroyAlias || `delete${graphQLClassName}`;
const deleteGraphQLMutationName = destroyAlias || `delete${graphQLClassName}`;
const deleteGraphQLMutation = mutationWithClientMutationId({
name: `Delete${graphQLClassName}`,
description: `The ${deleteGraphQLMutationName} mutation can be used to delete an object of the ${graphQLClassName} class.`,
@@ -303,9 +268,7 @@ const load = function(
outputFields: {
[getGraphQLQueryName]: {
description: 'This is the deleted object.',
type: new GraphQLNonNull(
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
),
type: new GraphQLNonNull(classGraphQLOutputType || defaultGraphQLTypes.OBJECT),
},
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
@@ -324,11 +287,7 @@ const load = function(
.map(field => field.replace(`${getGraphQLQueryName}.`, ''));
const { keys, include } = extractKeysAndInclude(selectedFields);
let optimizedObject = {};
if (
keys &&
keys.split(',').filter(key => !['id', 'objectId'].includes(key))
.length > 0
) {
if (keys && keys.split(',').filter(key => !['id', 'objectId'].includes(key)).length > 0) {
optimizedObject = await objectsQueries.getObject(
className,
id,
@@ -342,13 +301,7 @@ const load = function(
parseGraphQLSchema.parseClasses
);
}
await objectsMutations.deleteObject(
className,
id,
config,
auth,
info
);
await objectsMutations.deleteObject(className, id, config, auth, info);
return {
[getGraphQLQueryName]: {
objectId: id,
@@ -362,15 +315,10 @@ const load = function(
});
if (
parseGraphQLSchema.addGraphQLType(
deleteGraphQLMutation.args.input.type.ofType
) &&
parseGraphQLSchema.addGraphQLType(deleteGraphQLMutation.args.input.type.ofType) &&
parseGraphQLSchema.addGraphQLType(deleteGraphQLMutation.type)
) {
parseGraphQLSchema.addGraphQLMutation(
deleteGraphQLMutationName,
deleteGraphQLMutation
);
parseGraphQLSchema.addGraphQLMutation(deleteGraphQLMutationName, deleteGraphQLMutation);
}
}
};