| 9 | import { createSanitizedError } from '../../Error'; |
| 10 | |
| 11 | const 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: { |
nothing calls this directly
no test coverage detected
searching dependent graphs…