GraphQL classConfig query alias (#6257)
* adds alias option * added tests
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
abcc5fdb31
commit
188f033330
@@ -266,7 +266,13 @@ class ParseGraphQLController {
|
||||
}
|
||||
if (query !== null) {
|
||||
if (isValidSimpleObject(query)) {
|
||||
const { find = null, get = null, ...invalidKeys } = query;
|
||||
const {
|
||||
find = null,
|
||||
get = null,
|
||||
findAlias = null,
|
||||
getAlias = null,
|
||||
...invalidKeys
|
||||
} = query;
|
||||
if (Object.keys(invalidKeys).length) {
|
||||
return `"query" contains invalid keys, [${Object.keys(
|
||||
invalidKeys
|
||||
@@ -275,6 +281,10 @@ class ParseGraphQLController {
|
||||
return `"query.find" must be a boolean`;
|
||||
} else if (get !== null && typeof get !== 'boolean') {
|
||||
return `"query.get" must be a boolean`;
|
||||
} else if (findAlias !== null && typeof findAlias !== 'string') {
|
||||
return `"query.findAlias" must be a string`;
|
||||
} else if (getAlias !== null && typeof getAlias !== 'string') {
|
||||
return `"query.getAlias" must be a string`;
|
||||
}
|
||||
} else {
|
||||
return `"query" must be a valid object`;
|
||||
@@ -361,6 +371,8 @@ export interface ParseGraphQLClassConfig {
|
||||
query: ?{
|
||||
get: ?boolean,
|
||||
find: ?boolean,
|
||||
findAlias: ?String,
|
||||
getAlias: ?String,
|
||||
};
|
||||
/* The `mutation` object contains options for which class mutations are generated */
|
||||
mutation: ?{
|
||||
|
||||
@@ -52,6 +52,8 @@ const load = function(
|
||||
const {
|
||||
get: isGetEnabled = true,
|
||||
find: isFindEnabled = true,
|
||||
getAlias: getAlias = '',
|
||||
findAlias: findAlias = '',
|
||||
} = getParseClassQueryConfig(parseClassConfig);
|
||||
|
||||
const {
|
||||
@@ -61,8 +63,11 @@ const load = function(
|
||||
} = parseGraphQLSchema.parseClassTypes[className];
|
||||
|
||||
if (isGetEnabled) {
|
||||
const getGraphQLQueryName =
|
||||
const lowerCaseClassName =
|
||||
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
|
||||
const getGraphQLQueryName = getAlias || lowerCaseClassName;
|
||||
|
||||
parseGraphQLSchema.addGraphQLQuery(getGraphQLQueryName, {
|
||||
description: `The ${getGraphQLQueryName} query can be used to get an object of the ${graphQLClassName} class by its id.`,
|
||||
args: {
|
||||
@@ -83,9 +88,11 @@ const load = function(
|
||||
}
|
||||
|
||||
if (isFindEnabled) {
|
||||
const findGraphQLQueryName = pluralize(
|
||||
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1)
|
||||
);
|
||||
const lowerCaseClassName =
|
||||
graphQLClassName.charAt(0).toLowerCase() + graphQLClassName.slice(1);
|
||||
|
||||
const findGraphQLQueryName = findAlias || pluralize(lowerCaseClassName);
|
||||
|
||||
parseGraphQLSchema.addGraphQLQuery(findGraphQLQueryName, {
|
||||
description: `The ${findGraphQLQueryName} query can be used to find objects of the ${graphQLClassName} class.`,
|
||||
args: classGraphQLFindArgs,
|
||||
|
||||
Reference in New Issue
Block a user