Files
kami-parse-server/src/GraphQL/transformers/schemaFields.js

140 lines
3.7 KiB
JavaScript
Raw Normal View History

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
import Parse from 'parse/node';
const transformToParse = (graphQLSchemaFields, existingFields) => {
if (!graphQLSchemaFields) {
return {};
}
let parseSchemaFields = {};
const reducerGenerator = type => (parseSchemaFields, field) => {
if (type === 'Remove') {
if (existingFields[field.name]) {
return {
...parseSchemaFields,
[field.name]: {
__op: 'Delete',
},
};
} else {
return parseSchemaFields;
}
}
if (
graphQLSchemaFields.remove &&
2020-12-13 11:19:04 -06:00
graphQLSchemaFields.remove.find(removeField => removeField.name === field.name)
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
) {
return parseSchemaFields;
}
2020-12-13 11:19:04 -06:00
if (parseSchemaFields[field.name] || (existingFields && existingFields[field.name])) {
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Duplicated field name: ${field.name}`);
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
}
if (type === 'Relation' || type === 'Pointer') {
return {
...parseSchemaFields,
[field.name]: {
type,
targetClass: field.targetClassName,
},
};
}
return {
...parseSchemaFields,
[field.name]: {
type,
},
};
};
if (graphQLSchemaFields.addStrings) {
parseSchemaFields = graphQLSchemaFields.addStrings.reduce(
reducerGenerator('String'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addNumbers) {
parseSchemaFields = graphQLSchemaFields.addNumbers.reduce(
reducerGenerator('Number'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addBooleans) {
parseSchemaFields = graphQLSchemaFields.addBooleans.reduce(
reducerGenerator('Boolean'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addArrays) {
parseSchemaFields = graphQLSchemaFields.addArrays.reduce(
reducerGenerator('Array'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addObjects) {
parseSchemaFields = graphQLSchemaFields.addObjects.reduce(
reducerGenerator('Object'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addDates) {
parseSchemaFields = graphQLSchemaFields.addDates.reduce(
reducerGenerator('Date'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addFiles) {
parseSchemaFields = graphQLSchemaFields.addFiles.reduce(
reducerGenerator('File'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addGeoPoint) {
parseSchemaFields = [graphQLSchemaFields.addGeoPoint].reduce(
reducerGenerator('GeoPoint'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addPolygons) {
parseSchemaFields = graphQLSchemaFields.addPolygons.reduce(
reducerGenerator('Polygon'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addBytes) {
parseSchemaFields = graphQLSchemaFields.addBytes.reduce(
reducerGenerator('Bytes'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addPointers) {
parseSchemaFields = graphQLSchemaFields.addPointers.reduce(
reducerGenerator('Pointer'),
parseSchemaFields
);
}
if (graphQLSchemaFields.addRelations) {
parseSchemaFields = graphQLSchemaFields.addRelations.reduce(
reducerGenerator('Relation'),
parseSchemaFields
);
}
if (existingFields && graphQLSchemaFields.remove) {
parseSchemaFields = graphQLSchemaFields.remove.reduce(
reducerGenerator('Remove'),
parseSchemaFields
);
}
return parseSchemaFields;
};
const transformToGraphQL = parseSchemaFields => {
return Object.keys(parseSchemaFields).map(name => ({
name,
type: parseSchemaFields[name].type,
targetClassName: parseSchemaFields[name].targetClass,
}));
};
export { transformToParse, transformToGraphQL };