GraphQL: Renaming Types/Inputs (#5883)
* Renaming GraphQL Types/Inputs * Add Native Type to avoid collision * Use pluralize for renaming * Fixing tests * Improve name collision management - tests passsing * Renaming few more default types * Rename file input * Reverting fields types to not collide with the relay spec types Improver users mutations * Adding ArrayResult to the reserved list * Fixing tests * Add more unit tests to ParseGraphQLSchema * Test transformClassNameToGraphQL * Name collision tests
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
cf6e79ee75
commit
59b0221fec
@@ -5,6 +5,7 @@ import { extractKeysAndInclude } from '../parseGraphQLUtils';
|
||||
import * as objectsMutations from './objectsMutations';
|
||||
import * as objectsQueries from './objectsQueries';
|
||||
import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLController';
|
||||
import { transformClassNameToGraphQL } from '../transformers/className';
|
||||
|
||||
const getParseClassMutationConfig = function(
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
@@ -39,7 +40,9 @@ const load = function(
|
||||
parseClass,
|
||||
parseClassConfig: ?ParseGraphQLClassConfig
|
||||
) {
|
||||
const { className } = parseClass;
|
||||
const className = parseClass.className;
|
||||
const graphQLClassName = transformClassNameToGraphQL(className);
|
||||
|
||||
const {
|
||||
create: isCreateEnabled = true,
|
||||
update: isUpdateEnabled = true,
|
||||
@@ -52,37 +55,29 @@ const load = function(
|
||||
classGraphQLOutputType,
|
||||
} = parseGraphQLSchema.parseClassTypes[className];
|
||||
|
||||
const createFields = {
|
||||
description: 'These are the fields used to create the object.',
|
||||
type: classGraphQLCreateType,
|
||||
};
|
||||
const updateFields = {
|
||||
description: 'These are the fields used to update the object.',
|
||||
type: classGraphQLUpdateType,
|
||||
};
|
||||
|
||||
const classGraphQLCreateTypeFields = isCreateEnabled
|
||||
? classGraphQLCreateType.getFields()
|
||||
: null;
|
||||
const classGraphQLUpdateTypeFields = isUpdateEnabled
|
||||
? classGraphQLUpdateType.getFields()
|
||||
: null;
|
||||
|
||||
const transformTypes = (inputType: 'create' | 'update', fields) => {
|
||||
if (fields) {
|
||||
const classGraphQLCreateTypeFields =
|
||||
isCreateEnabled && classGraphQLCreateType
|
||||
? classGraphQLCreateType.getFields()
|
||||
: null;
|
||||
const classGraphQLUpdateTypeFields =
|
||||
isUpdateEnabled && classGraphQLUpdateType
|
||||
? classGraphQLUpdateType.getFields()
|
||||
: null;
|
||||
Object.keys(fields).forEach(field => {
|
||||
let inputTypeField;
|
||||
if (inputType === 'create') {
|
||||
if (inputType === 'create' && classGraphQLCreateTypeFields) {
|
||||
inputTypeField = classGraphQLCreateTypeFields[field];
|
||||
} else {
|
||||
} else if (classGraphQLUpdateTypeFields) {
|
||||
inputTypeField = classGraphQLUpdateTypeFields[field];
|
||||
}
|
||||
if (inputTypeField) {
|
||||
switch (inputTypeField.type) {
|
||||
case defaultGraphQLTypes.GEO_POINT:
|
||||
case defaultGraphQLTypes.GEO_POINT_INPUT:
|
||||
fields[field].__type = 'GeoPoint';
|
||||
break;
|
||||
case defaultGraphQLTypes.POLYGON:
|
||||
case defaultGraphQLTypes.POLYGON_INPUT:
|
||||
fields[field] = {
|
||||
__type: 'Polygon',
|
||||
coordinates: fields[field].map(geoPoint => [
|
||||
@@ -98,13 +93,18 @@ const load = function(
|
||||
};
|
||||
|
||||
if (isCreateEnabled) {
|
||||
const createGraphQLMutationName = `create${className}`;
|
||||
parseGraphQLSchema.graphQLObjectsMutations[createGraphQLMutationName] = {
|
||||
description: `The ${createGraphQLMutationName} mutation can be used to create a new object of the ${className} class.`,
|
||||
const createGraphQLMutationName = `create${graphQLClassName}`;
|
||||
parseGraphQLSchema.addGraphQLObjectMutation(createGraphQLMutationName, {
|
||||
description: `The ${createGraphQLMutationName} mutation can be used to create a new object of the ${graphQLClassName} class.`,
|
||||
args: {
|
||||
fields: createFields,
|
||||
fields: {
|
||||
description: 'These are the fields used to create the object.',
|
||||
type: classGraphQLCreateType || defaultGraphQLTypes.OBJECT,
|
||||
},
|
||||
},
|
||||
type: new GraphQLNonNull(classGraphQLOutputType),
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
async resolve(_source, args, context, mutationInfo) {
|
||||
try {
|
||||
let { fields } = args;
|
||||
@@ -150,18 +150,23 @@ const load = function(
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (isUpdateEnabled) {
|
||||
const updateGraphQLMutationName = `update${className}`;
|
||||
parseGraphQLSchema.graphQLObjectsMutations[updateGraphQLMutationName] = {
|
||||
description: `The ${updateGraphQLMutationName} mutation can be used to update an object of the ${className} class.`,
|
||||
const updateGraphQLMutationName = `update${graphQLClassName}`;
|
||||
parseGraphQLSchema.addGraphQLObjectMutation(updateGraphQLMutationName, {
|
||||
description: `The ${updateGraphQLMutationName} mutation can be used to update an object of the ${graphQLClassName} class.`,
|
||||
args: {
|
||||
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
|
||||
fields: updateFields,
|
||||
fields: {
|
||||
description: 'These are the fields used to update the object.',
|
||||
type: classGraphQLUpdateType || defaultGraphQLTypes.OBJECT,
|
||||
},
|
||||
},
|
||||
type: new GraphQLNonNull(classGraphQLOutputType),
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
async resolve(_source, args, context, mutationInfo) {
|
||||
try {
|
||||
const { objectId, fields } = args;
|
||||
@@ -205,17 +210,19 @@ const load = function(
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (isDestroyEnabled) {
|
||||
const deleteGraphQLMutationName = `delete${className}`;
|
||||
parseGraphQLSchema.graphQLObjectsMutations[deleteGraphQLMutationName] = {
|
||||
description: `The ${deleteGraphQLMutationName} mutation can be used to delete an object of the ${className} class.`,
|
||||
const deleteGraphQLMutationName = `delete${graphQLClassName}`;
|
||||
parseGraphQLSchema.addGraphQLObjectMutation(deleteGraphQLMutationName, {
|
||||
description: `The ${deleteGraphQLMutationName} mutation can be used to delete an object of the ${graphQLClassName} class.`,
|
||||
args: {
|
||||
objectId: defaultGraphQLTypes.OBJECT_ID_ATT,
|
||||
},
|
||||
type: new GraphQLNonNull(classGraphQLOutputType),
|
||||
type: new GraphQLNonNull(
|
||||
classGraphQLOutputType || defaultGraphQLTypes.OBJECT
|
||||
),
|
||||
async resolve(_source, args, context, mutationInfo) {
|
||||
try {
|
||||
const { objectId } = args;
|
||||
@@ -250,7 +257,7 @@ const load = function(
|
||||
parseGraphQLSchema.handleError(e);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user