2019-08-17 11:02:19 -07:00
|
|
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
2019-07-18 12:41:10 -07:00
|
|
|
import { FunctionsRouter } from '../../Routers/FunctionsRouter';
|
|
|
|
|
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
|
|
|
|
|
|
|
|
|
|
const load = parseGraphQLSchema => {
|
2019-08-17 11:02:19 -07:00
|
|
|
parseGraphQLSchema.addGraphQLMutation(
|
|
|
|
|
'callCloudCode',
|
|
|
|
|
{
|
|
|
|
|
description:
|
|
|
|
|
'The call mutation can be used to invoke a cloud code function.',
|
|
|
|
|
args: {
|
|
|
|
|
functionName: {
|
|
|
|
|
description: 'This is the name of the function to be called.',
|
|
|
|
|
type: new GraphQLNonNull(GraphQLString),
|
|
|
|
|
},
|
|
|
|
|
params: {
|
|
|
|
|
description: 'These are the params to be passed to the function.',
|
|
|
|
|
type: defaultGraphQLTypes.OBJECT,
|
|
|
|
|
},
|
2019-07-18 12:41:10 -07:00
|
|
|
},
|
2019-08-17 11:02:19 -07:00
|
|
|
type: defaultGraphQLTypes.ANY,
|
|
|
|
|
async resolve(_source, args, context) {
|
|
|
|
|
try {
|
|
|
|
|
const { functionName, params } = args;
|
|
|
|
|
const { config, auth, info } = context;
|
2019-07-18 12:41:10 -07:00
|
|
|
|
2019-08-17 11:02:19 -07:00
|
|
|
return (await FunctionsRouter.handleCloudFunction({
|
|
|
|
|
params: {
|
|
|
|
|
functionName,
|
|
|
|
|
},
|
|
|
|
|
config,
|
|
|
|
|
auth,
|
|
|
|
|
info,
|
|
|
|
|
body: params,
|
|
|
|
|
})).response.result;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
parseGraphQLSchema.handleError(e);
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-07-18 12:41:10 -07:00
|
|
|
},
|
2019-08-17 11:02:19 -07:00
|
|
|
true,
|
|
|
|
|
true
|
|
|
|
|
);
|
2019-07-18 12:41:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export { load };
|