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
This commit is contained in:
committed by
GitHub
parent
e404c43222
commit
5a482bd661
147
src/GraphQL/transformers/schemaFields.js
Normal file
147
src/GraphQL/transformers/schemaFields.js
Normal file
@@ -0,0 +1,147 @@
|
||||
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 &&
|
||||
graphQLSchemaFields.remove.find(
|
||||
removeField => removeField.name === field.name
|
||||
)
|
||||
) {
|
||||
return parseSchemaFields;
|
||||
}
|
||||
if (
|
||||
parseSchemaFields[field.name] ||
|
||||
(existingFields && existingFields[field.name])
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_KEY_NAME,
|
||||
`Duplicated field name: ${field.name}`
|
||||
);
|
||||
}
|
||||
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 };
|
||||
Reference in New Issue
Block a user