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
46
src/GraphQL/transformers/constraintType.js
Normal file
46
src/GraphQL/transformers/constraintType.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
|
||||
const transformConstraintTypeToGraphQL = (
|
||||
parseType,
|
||||
targetClass,
|
||||
parseClassTypes
|
||||
) => {
|
||||
switch (parseType) {
|
||||
case 'String':
|
||||
return defaultGraphQLTypes.STRING_WHERE_INPUT;
|
||||
case 'Number':
|
||||
return defaultGraphQLTypes.NUMBER_WHERE_INPUT;
|
||||
case 'Boolean':
|
||||
return defaultGraphQLTypes.BOOLEAN_WHERE_INPUT;
|
||||
case 'Array':
|
||||
return defaultGraphQLTypes.ARRAY_WHERE_INPUT;
|
||||
case 'Object':
|
||||
return defaultGraphQLTypes.OBJECT_WHERE_INPUT;
|
||||
case 'Date':
|
||||
return defaultGraphQLTypes.DATE_WHERE_INPUT;
|
||||
case 'Pointer':
|
||||
if (
|
||||
parseClassTypes[targetClass] &&
|
||||
parseClassTypes[targetClass].classGraphQLConstraintType
|
||||
) {
|
||||
return parseClassTypes[targetClass].classGraphQLConstraintType;
|
||||
} else {
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
}
|
||||
case 'File':
|
||||
return defaultGraphQLTypes.FILE_WHERE_INPUT;
|
||||
case 'GeoPoint':
|
||||
return defaultGraphQLTypes.GEO_POINT_WHERE_INPUT;
|
||||
case 'Polygon':
|
||||
return defaultGraphQLTypes.POLYGON_WHERE_INPUT;
|
||||
case 'Bytes':
|
||||
return defaultGraphQLTypes.BYTES_WHERE_INPUT;
|
||||
case 'ACL':
|
||||
return defaultGraphQLTypes.OBJECT_WHERE_INPUT;
|
||||
case 'Relation':
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export { transformConstraintTypeToGraphQL };
|
||||
62
src/GraphQL/transformers/inputType.js
Normal file
62
src/GraphQL/transformers/inputType.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLFloat,
|
||||
GraphQLBoolean,
|
||||
GraphQLList,
|
||||
} from 'graphql';
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
|
||||
const transformInputTypeToGraphQL = (
|
||||
parseType,
|
||||
targetClass,
|
||||
parseClassTypes
|
||||
) => {
|
||||
switch (parseType) {
|
||||
case 'String':
|
||||
return GraphQLString;
|
||||
case 'Number':
|
||||
return GraphQLFloat;
|
||||
case 'Boolean':
|
||||
return GraphQLBoolean;
|
||||
case 'Array':
|
||||
return new GraphQLList(defaultGraphQLTypes.ANY);
|
||||
case 'Object':
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
case 'Date':
|
||||
return defaultGraphQLTypes.DATE;
|
||||
case 'Pointer':
|
||||
if (
|
||||
parseClassTypes &&
|
||||
parseClassTypes[targetClass] &&
|
||||
parseClassTypes[targetClass].classGraphQLPointerType
|
||||
) {
|
||||
return parseClassTypes[targetClass].classGraphQLPointerType;
|
||||
} else {
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
}
|
||||
case 'Relation':
|
||||
if (
|
||||
parseClassTypes &&
|
||||
parseClassTypes[targetClass] &&
|
||||
parseClassTypes[targetClass].classGraphQLRelationType
|
||||
) {
|
||||
return parseClassTypes[targetClass].classGraphQLRelationType;
|
||||
} else {
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
}
|
||||
case 'File':
|
||||
return defaultGraphQLTypes.FILE;
|
||||
case 'GeoPoint':
|
||||
return defaultGraphQLTypes.GEO_POINT_INPUT;
|
||||
case 'Polygon':
|
||||
return defaultGraphQLTypes.POLYGON_INPUT;
|
||||
case 'Bytes':
|
||||
return defaultGraphQLTypes.BYTES;
|
||||
case 'ACL':
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export { transformInputTypeToGraphQL };
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
import * as objectsMutations from '../loaders/objectsMutations';
|
||||
import * as objectsMutations from '../helpers/objectsMutations';
|
||||
|
||||
const transformTypes = async (
|
||||
inputType: 'create' | 'update',
|
||||
|
||||
65
src/GraphQL/transformers/outputType.js
Normal file
65
src/GraphQL/transformers/outputType.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as defaultGraphQLTypes from '../loaders/defaultGraphQLTypes';
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLFloat,
|
||||
GraphQLBoolean,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
|
||||
const transformOutputTypeToGraphQL = (
|
||||
parseType,
|
||||
targetClass,
|
||||
parseClassTypes
|
||||
) => {
|
||||
switch (parseType) {
|
||||
case 'String':
|
||||
return GraphQLString;
|
||||
case 'Number':
|
||||
return GraphQLFloat;
|
||||
case 'Boolean':
|
||||
return GraphQLBoolean;
|
||||
case 'Array':
|
||||
return new GraphQLList(defaultGraphQLTypes.ARRAY_RESULT);
|
||||
case 'Object':
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
case 'Date':
|
||||
return defaultGraphQLTypes.DATE;
|
||||
case 'Pointer':
|
||||
if (
|
||||
parseClassTypes &&
|
||||
parseClassTypes[targetClass] &&
|
||||
parseClassTypes[targetClass].classGraphQLOutputType
|
||||
) {
|
||||
return parseClassTypes[targetClass].classGraphQLOutputType;
|
||||
} else {
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
}
|
||||
case 'Relation':
|
||||
if (
|
||||
parseClassTypes &&
|
||||
parseClassTypes[targetClass] &&
|
||||
parseClassTypes[targetClass].classGraphQLFindResultType
|
||||
) {
|
||||
return new GraphQLNonNull(
|
||||
parseClassTypes[targetClass].classGraphQLFindResultType
|
||||
);
|
||||
} else {
|
||||
return new GraphQLNonNull(defaultGraphQLTypes.FIND_RESULT);
|
||||
}
|
||||
case 'File':
|
||||
return defaultGraphQLTypes.FILE_INFO;
|
||||
case 'GeoPoint':
|
||||
return defaultGraphQLTypes.GEO_POINT;
|
||||
case 'Polygon':
|
||||
return defaultGraphQLTypes.POLYGON;
|
||||
case 'Bytes':
|
||||
return defaultGraphQLTypes.BYTES;
|
||||
case 'ACL':
|
||||
return defaultGraphQLTypes.OBJECT;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export { transformOutputTypeToGraphQL };
|
||||
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