| 18 | }; |
| 19 | |
| 20 | const load = parseGraphQLSchema => { |
| 21 | parseGraphQLSchema.addGraphQLQuery( |
| 22 | 'class', |
| 23 | { |
| 24 | description: 'The class query can be used to retrieve an existing object class.', |
| 25 | args: { |
| 26 | name: schemaTypes.CLASS_NAME_ATT, |
| 27 | }, |
| 28 | type: new GraphQLNonNull(schemaTypes.CLASS), |
| 29 | resolve: async (_source, args, context) => { |
| 30 | try { |
| 31 | const { name } = cloneArgs(args); |
| 32 | const { config, auth } = context; |
| 33 | |
| 34 | enforceMasterKeyAccess(auth, config); |
| 35 | |
| 36 | const schema = await config.database.loadSchema({ clearCache: true }); |
| 37 | const parseClass = await getClass(name, schema); |
| 38 | return { |
| 39 | name: parseClass.className, |
| 40 | schemaFields: transformToGraphQL(parseClass.fields), |
| 41 | }; |
| 42 | } catch (e) { |
| 43 | parseGraphQLSchema.handleError(e); |
| 44 | } |
| 45 | }, |
| 46 | }, |
| 47 | true, |
| 48 | true |
| 49 | ); |
| 50 | |
| 51 | parseGraphQLSchema.addGraphQLQuery( |
| 52 | 'classes', |
| 53 | { |
| 54 | description: 'The classes query can be used to retrieve the existing object classes.', |
| 55 | type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(schemaTypes.CLASS))), |
| 56 | resolve: async (_source, _args, context) => { |
| 57 | try { |
| 58 | const { config, auth } = context; |
| 59 | |
| 60 | enforceMasterKeyAccess(auth, config); |
| 61 | |
| 62 | const schema = await config.database.loadSchema({ clearCache: true }); |
| 63 | return (await schema.getAllClasses(true)).map(parseClass => ({ |
| 64 | name: parseClass.className, |
| 65 | schemaFields: transformToGraphQL(parseClass.fields), |
| 66 | })); |
| 67 | } catch (e) { |
| 68 | parseGraphQLSchema.handleError(e); |
| 69 | } |
| 70 | }, |
| 71 | }, |
| 72 | true, |
| 73 | true |
| 74 | ); |
| 75 | }; |
| 76 | |
| 77 | export { getClass, load }; |
nothing calls this directly
no test coverage detected