forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL { functions { call } } generic mutation (parse-community#5818)
* Generic call function mutation * Change function return type to any * First passing test * Testing errors * Testing different data types
- Loading branch information
1 parent
1d8fa76
commit de0e35e
Showing
3 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import * as objectsMutations from './objectsMutations'; | ||
import * as filesMutations from './filesMutations'; | ||
import * as usersMutations from './usersMutations'; | ||
import * as functionsMutations from './functionsMutations'; | ||
|
||
const load = parseGraphQLSchema => { | ||
objectsMutations.load(parseGraphQLSchema); | ||
filesMutations.load(parseGraphQLSchema); | ||
usersMutations.load(parseGraphQLSchema); | ||
functionsMutations.load(parseGraphQLSchema); | ||
}; | ||
|
||
export { load }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { GraphQLObjectType, GraphQLNonNull, GraphQLString } from 'graphql'; | ||
import { FunctionsRouter } from '../../Routers/FunctionsRouter'; | ||
import * as defaultGraphQLTypes from './defaultGraphQLTypes'; | ||
|
||
const load = parseGraphQLSchema => { | ||
const fields = {}; | ||
|
||
fields.call = { | ||
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, | ||
}, | ||
}, | ||
type: defaultGraphQLTypes.ANY, | ||
async resolve(_source, args, context) { | ||
try { | ||
const { functionName, params } = args; | ||
const { config, auth, info } = context; | ||
|
||
return (await FunctionsRouter.handleCloudFunction({ | ||
params: { | ||
functionName, | ||
}, | ||
config, | ||
auth, | ||
info, | ||
body: params, | ||
})).response.result; | ||
} catch (e) { | ||
parseGraphQLSchema.handleError(e); | ||
} | ||
}, | ||
}; | ||
|
||
const functionsMutation = new GraphQLObjectType({ | ||
name: 'FunctionsMutation', | ||
description: | ||
'FunctionsMutation is the top level type for functions mutations.', | ||
fields, | ||
}); | ||
parseGraphQLSchema.graphQLTypes.push(functionsMutation); | ||
|
||
parseGraphQLSchema.graphQLMutations.functions = { | ||
description: 'This is the top level for functions mutations.', | ||
type: functionsMutation, | ||
resolve: () => new Object(), | ||
}; | ||
}; | ||
|
||
export { load }; |