MCPcopy Create free account
hub / github.com/parse-community/parse-server / load

Function load

src/GraphQL/loaders/schemaMutations.js:11–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import { createSanitizedError } from '../../Error';
10
11const load = parseGraphQLSchema => {
12 const createClassMutation = mutationWithClientMutationId({
13 name: 'CreateClass',
14 description:
15 'The createClass mutation can be used to create the schema for a new object class.',
16 inputFields: {
17 name: schemaTypes.CLASS_NAME_ATT,
18 schemaFields: {
19 description: "These are the schema's fields of the object class.",
20 type: schemaTypes.SCHEMA_FIELDS_INPUT,
21 },
22 },
23 outputFields: {
24 class: {
25 description: 'This is the created class.',
26 type: new GraphQLNonNull(schemaTypes.CLASS),
27 },
28 },
29 mutateAndGetPayload: async (args, context) => {
30 try {
31 const { name, schemaFields } = cloneArgs(args);
32 const { config, auth } = context;
33
34 enforceMasterKeyAccess(auth, config);
35
36 if (auth.isReadOnly) {
37 throw createSanitizedError(
38 Parse.Error.OPERATION_FORBIDDEN,
39 "read-only masterKey isn't allowed to create a schema.",
40 config
41 );
42 }
43
44 const schema = await config.database.loadSchema({ clearCache: true });
45 const parseClass = await schema.addClassIfNotExists(name, transformToParse(schemaFields));
46 return {
47 class: {
48 name: parseClass.className,
49 schemaFields: transformToGraphQL(parseClass.fields),
50 },
51 };
52 } catch (e) {
53 parseGraphQLSchema.handleError(e);
54 }
55 },
56 });
57
58 parseGraphQLSchema.addGraphQLType(createClassMutation.args.input.type.ofType, true, true);
59 parseGraphQLSchema.addGraphQLType(createClassMutation.type, true, true);
60 parseGraphQLSchema.addGraphQLMutation('createClass', createClassMutation, true, true);
61
62 const updateClassMutation = mutationWithClientMutationId({
63 name: 'UpdateClass',
64 description:
65 'The updateClass mutation can be used to update the schema for an existing object class.',
66 inputFields: {
67 name: schemaTypes.CLASS_NAME_ATT,
68 schemaFields: {

Callers

nothing calls this directly

Calls 13

cloneArgsFunction · 0.90
enforceMasterKeyAccessFunction · 0.90
createSanitizedErrorFunction · 0.90
transformToParseFunction · 0.90
transformToGraphQLFunction · 0.90
getClassFunction · 0.90
loadSchemaMethod · 0.80
addClassIfNotExistsMethod · 0.80
addGraphQLTypeMethod · 0.80
addGraphQLMutationMethod · 0.80
updateClassMethod · 0.80
deleteSchemaMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…