* Install graphql-relay * Add relayNodeInterface to ParseGraphQLSchema * Add support to global id * Add support to global id in other operations * Fix sort by glboal id * Fix where by global id * Introduce IdWhereInput * Add Relay object identification tests * Client mutation id on createFile mutation * Client mutation id on callCloudCode mutation * Client mutation id on signUp mutation * Client mutation id on logIn mutation * Client mutation id on logOut mutation * Client mutation id on createClass mutation * Client mutation id on updateClass mutation * Client mutation id on deleteClass mutation * Client mutation id on create object mutation * Improve Viewer type * Client mutation id on update object mutation * Client mutation id on delete object mutation * Introducing connections * Fix tests * Add pagination test * Fix file location * Fix postgres tests * Add comments * Tests to calculateSkipAndLimit
84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
import { GraphQLNonNull, GraphQLEnumType } from 'graphql';
|
|
import { mutationWithClientMutationId } from 'graphql-relay';
|
|
import { FunctionsRouter } from '../../Routers/FunctionsRouter';
|
|
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
|
|
|
|
const load = parseGraphQLSchema => {
|
|
if (parseGraphQLSchema.functionNames.length > 0) {
|
|
const cloudCodeFunctionEnum = parseGraphQLSchema.addGraphQLType(
|
|
new GraphQLEnumType({
|
|
name: 'CloudCodeFunction',
|
|
description:
|
|
'The CloudCodeFunction enum type contains a list of all available cloud code functions.',
|
|
values: parseGraphQLSchema.functionNames.reduce(
|
|
(values, functionName) => ({
|
|
...values,
|
|
[functionName]: { value: functionName },
|
|
}),
|
|
{}
|
|
),
|
|
}),
|
|
true,
|
|
true
|
|
);
|
|
|
|
const callCloudCodeMutation = mutationWithClientMutationId({
|
|
name: 'CallCloudCode',
|
|
description:
|
|
'The callCloudCode mutation can be used to invoke a cloud code function.',
|
|
inputFields: {
|
|
functionName: {
|
|
description: 'This is the function to be called.',
|
|
type: new GraphQLNonNull(cloudCodeFunctionEnum),
|
|
},
|
|
params: {
|
|
description: 'These are the params to be passed to the function.',
|
|
type: defaultGraphQLTypes.OBJECT,
|
|
},
|
|
},
|
|
outputFields: {
|
|
result: {
|
|
description:
|
|
'This is the result value of the cloud code function execution.',
|
|
type: defaultGraphQLTypes.ANY,
|
|
},
|
|
},
|
|
mutateAndGetPayload: async (args, context) => {
|
|
try {
|
|
const { functionName, params } = args;
|
|
const { config, auth, info } = context;
|
|
|
|
return {
|
|
result: (await FunctionsRouter.handleCloudFunction({
|
|
params: {
|
|
functionName,
|
|
},
|
|
config,
|
|
auth,
|
|
info,
|
|
body: params,
|
|
})).response.result,
|
|
};
|
|
} catch (e) {
|
|
parseGraphQLSchema.handleError(e);
|
|
}
|
|
},
|
|
});
|
|
|
|
parseGraphQLSchema.addGraphQLType(
|
|
callCloudCodeMutation.args.input.type.ofType,
|
|
true,
|
|
true
|
|
);
|
|
parseGraphQLSchema.addGraphQLType(callCloudCodeMutation.type, true, true);
|
|
parseGraphQLSchema.addGraphQLMutation(
|
|
'callCloudCode',
|
|
callCloudCodeMutation,
|
|
true,
|
|
true
|
|
);
|
|
}
|
|
};
|
|
|
|
export { load };
|