Improve callCloudCode mutation to receive a CloudCodeFunction enum instead of a String (#6029)
* Add listing test * Improvements * Fixinf package.json * Fix package.json * Fix tests
This commit is contained in:
committed by
GitHub
parent
33d2b16476
commit
a754b883b2
@@ -15,6 +15,7 @@ import DatabaseController from '../Controllers/DatabaseController';
|
||||
import { toGraphQLError } from './parseGraphQLUtils';
|
||||
import * as schemaDirectives from './loaders/schemaDirectives';
|
||||
import * as schemaTypes from './loaders/schemaTypes';
|
||||
import { getFunctionNames } from '../triggers';
|
||||
|
||||
const RESERVED_GRAPHQL_TYPE_NAMES = [
|
||||
'String',
|
||||
@@ -29,6 +30,7 @@ const RESERVED_GRAPHQL_TYPE_NAMES = [
|
||||
'Viewer',
|
||||
'SignUpFieldsInput',
|
||||
'LogInFieldsInput',
|
||||
'CloudCodeFunction',
|
||||
];
|
||||
const RESERVED_GRAPHQL_QUERY_NAMES = ['health', 'viewer', 'class', 'classes'];
|
||||
const RESERVED_GRAPHQL_MUTATION_NAMES = [
|
||||
@@ -53,6 +55,7 @@ class ParseGraphQLSchema {
|
||||
databaseController: DatabaseController,
|
||||
parseGraphQLController: ParseGraphQLController,
|
||||
log: any,
|
||||
appId: string,
|
||||
} = {}
|
||||
) {
|
||||
this.parseGraphQLController =
|
||||
@@ -64,13 +67,16 @@ class ParseGraphQLSchema {
|
||||
this.log =
|
||||
params.log || requiredParameter('You must provide a log instance!');
|
||||
this.graphQLCustomTypeDefs = params.graphQLCustomTypeDefs;
|
||||
this.appId =
|
||||
params.appId || requiredParameter('You must provide the appId!');
|
||||
}
|
||||
|
||||
async load() {
|
||||
const { parseGraphQLConfig } = await this._initializeSchemaAndConfig();
|
||||
|
||||
const parseClasses = await this._getClassesForSchema(parseGraphQLConfig);
|
||||
const parseClassesString = JSON.stringify(parseClasses);
|
||||
const functionNames = await this._getFunctionNames();
|
||||
const functionNamesString = JSON.stringify(functionNames);
|
||||
|
||||
if (
|
||||
this.graphQLSchema &&
|
||||
@@ -78,6 +84,7 @@ class ParseGraphQLSchema {
|
||||
parseClasses,
|
||||
parseClassesString,
|
||||
parseGraphQLConfig,
|
||||
functionNamesString,
|
||||
})
|
||||
) {
|
||||
return this.graphQLSchema;
|
||||
@@ -86,6 +93,8 @@ class ParseGraphQLSchema {
|
||||
this.parseClasses = parseClasses;
|
||||
this.parseClassesString = parseClassesString;
|
||||
this.parseGraphQLConfig = parseGraphQLConfig;
|
||||
this.functionNames = functionNames;
|
||||
this.functionNamesString = functionNamesString;
|
||||
this.parseClassTypes = {};
|
||||
this.viewerType = null;
|
||||
this.graphQLAutoSchema = null;
|
||||
@@ -360,6 +369,19 @@ class ParseGraphQLSchema {
|
||||
});
|
||||
}
|
||||
|
||||
async _getFunctionNames() {
|
||||
return await getFunctionNames(this.appId).filter(functionName => {
|
||||
if (/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(functionName)) {
|
||||
return true;
|
||||
} else {
|
||||
this.log.warn(
|
||||
`Function ${functionName} could not be added to the auto schema because GraphQL names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/.`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for changes to the parseClasses
|
||||
* objects (i.e. database schema) or to
|
||||
@@ -370,12 +392,19 @@ class ParseGraphQLSchema {
|
||||
parseClasses: any,
|
||||
parseClassesString: string,
|
||||
parseGraphQLConfig: ?ParseGraphQLConfig,
|
||||
functionNamesString: string,
|
||||
}): boolean {
|
||||
const { parseClasses, parseClassesString, parseGraphQLConfig } = params;
|
||||
const {
|
||||
parseClasses,
|
||||
parseClassesString,
|
||||
parseGraphQLConfig,
|
||||
functionNamesString,
|
||||
} = params;
|
||||
|
||||
if (
|
||||
JSON.stringify(this.parseGraphQLConfig) ===
|
||||
JSON.stringify(parseGraphQLConfig)
|
||||
JSON.stringify(parseGraphQLConfig) &&
|
||||
this.functionNamesString === functionNamesString
|
||||
) {
|
||||
if (this.parseClasses === parseClasses) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user