| 6 | import * as defaultGraphQLTypes from './defaultGraphQLTypes'; |
| 7 | |
| 8 | const load = parseGraphQLSchema => { |
| 9 | if (parseGraphQLSchema.functionNames.length > 0) { |
| 10 | const cloudCodeFunctionEnum = parseGraphQLSchema.addGraphQLType( |
| 11 | new GraphQLEnumType({ |
| 12 | name: 'CloudCodeFunction', |
| 13 | description: |
| 14 | 'The CloudCodeFunction enum type contains a list of all available cloud code functions.', |
| 15 | values: parseGraphQLSchema.functionNames.reduce( |
| 16 | (values, functionName) => ({ |
| 17 | ...values, |
| 18 | [functionName]: { value: functionName }, |
| 19 | }), |
| 20 | {} |
| 21 | ), |
| 22 | }), |
| 23 | true, |
| 24 | true |
| 25 | ); |
| 26 | |
| 27 | const callCloudCodeMutation = mutationWithClientMutationId({ |
| 28 | name: 'CallCloudCode', |
| 29 | description: 'The callCloudCode mutation can be used to invoke a cloud code function.', |
| 30 | inputFields: { |
| 31 | functionName: { |
| 32 | description: 'This is the function to be called.', |
| 33 | type: new GraphQLNonNull(cloudCodeFunctionEnum), |
| 34 | }, |
| 35 | params: { |
| 36 | description: 'These are the params to be passed to the function.', |
| 37 | type: defaultGraphQLTypes.OBJECT, |
| 38 | }, |
| 39 | }, |
| 40 | outputFields: { |
| 41 | result: { |
| 42 | description: 'This is the result value of the cloud code function execution.', |
| 43 | type: defaultGraphQLTypes.ANY, |
| 44 | }, |
| 45 | }, |
| 46 | mutateAndGetPayload: async (args, context) => { |
| 47 | try { |
| 48 | const { functionName, params } = cloneArgs(args); |
| 49 | const { config, auth, info } = context; |
| 50 | |
| 51 | return { |
| 52 | result: ( |
| 53 | await FunctionsRouter.handleCloudFunction({ |
| 54 | params: { |
| 55 | functionName, |
| 56 | }, |
| 57 | config, |
| 58 | auth, |
| 59 | info, |
| 60 | body: params, |
| 61 | }) |
| 62 | ).response.result, |
| 63 | }; |
| 64 | } catch (e) { |
| 65 | parseGraphQLSchema.handleError(e); |
nothing calls this directly
no test coverage detected