GraphQL classConfig query alias (#6257)

* adds alias option

* added tests
This commit is contained in:
Old Grandpa
2019-12-04 03:14:48 +03:00
committed by Antonio Davi Macedo Coelho de Castro
parent abcc5fdb31
commit 188f033330
3 changed files with 122 additions and 5 deletions

View File

@@ -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,