* 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
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
import Parse from 'parse/node';
|
|
import { GraphQLNonNull, GraphQLList } from 'graphql';
|
|
import { transformToGraphQL } from '../transformers/schemaFields';
|
|
import * as schemaTypes from './schemaTypes';
|
|
import { enforceMasterKeyAccess } from '../parseGraphQLUtils';
|
|
|
|
const getClass = async (name, schema) => {
|
|
try {
|
|
return await schema.getOneSchema(name, true);
|
|
} catch (e) {
|
|
if (e === undefined) {
|
|
throw new Parse.Error(
|
|
Parse.Error.INVALID_CLASS_NAME,
|
|
`Class ${name} does not exist.`
|
|
);
|
|
} else {
|
|
throw new Parse.Error(
|
|
Parse.Error.INTERNAL_SERVER_ERROR,
|
|
'Database adapter error.'
|
|
);
|
|
}
|
|
}
|
|
};
|
|
|
|
const load = parseGraphQLSchema => {
|
|
parseGraphQLSchema.addGraphQLQuery(
|
|
'class',
|
|
{
|
|
description:
|
|
'The class query can be used to retrieve an existing object class.',
|
|
args: {
|
|
name: schemaTypes.CLASS_NAME_ATT,
|
|
},
|
|
type: new GraphQLNonNull(schemaTypes.CLASS),
|
|
resolve: async (_source, args, context) => {
|
|
try {
|
|
const { name } = args;
|
|
const { config, auth } = context;
|
|
|
|
enforceMasterKeyAccess(auth);
|
|
|
|
const schema = await config.database.loadSchema({ clearCache: true });
|
|
const parseClass = await getClass(name, schema);
|
|
return {
|
|
name: parseClass.className,
|
|
schemaFields: transformToGraphQL(parseClass.fields),
|
|
};
|
|
} catch (e) {
|
|
parseGraphQLSchema.handleError(e);
|
|
}
|
|
},
|
|
},
|
|
true,
|
|
true
|
|
);
|
|
|
|
parseGraphQLSchema.addGraphQLQuery(
|
|
'classes',
|
|
{
|
|
description:
|
|
'The classes query can be used to retrieve the existing object classes.',
|
|
type: new GraphQLNonNull(
|
|
new GraphQLList(new GraphQLNonNull(schemaTypes.CLASS))
|
|
),
|
|
resolve: async (_source, _args, context) => {
|
|
try {
|
|
const { config, auth } = context;
|
|
|
|
enforceMasterKeyAccess(auth);
|
|
|
|
const schema = await config.database.loadSchema({ clearCache: true });
|
|
return (await schema.getAllClasses(true)).map(parseClass => ({
|
|
name: parseClass.className,
|
|
schemaFields: transformToGraphQL(parseClass.fields),
|
|
}));
|
|
} catch (e) {
|
|
parseGraphQLSchema.handleError(e);
|
|
}
|
|
},
|
|
},
|
|
true,
|
|
true
|
|
);
|
|
};
|
|
|
|
export { getClass, load };
|