Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// '[redux-source] The result of query/mutation operation (an object or objects in an array) must have id attrubute',
// );
// }
const childRoot = {};
spreadSections.forEach(traverseProp(childRoot));
let isList = false;
let dataName = alias ? alias.value : originName;
if (RE_LIST_SUFFIX.test(dataName)) {
isList = true;
dataName = dataName.replace(RE_LIST_SUFFIX, '$1');
if (alias) {
alias.value = originName;
} else {
name.value = originName;
}
} else if (isPlural(dataName)) {
isList = true;
}
const entity = hasId
? new schema.Entity(singular(dataName), childRoot, {
idAttribute,
})
: childRoot;
root[dataName] = isList ? [entity] : entity;
};
definitions.forEach(definition => {
export const getConnectionQueryName = type =>
// Check is necessary since prisma pluralizes existing plural words
isPlural(type.name)
? `${camelCase(type.name)}esConnection`
: `${pluralize(camelCase(type.name))}Connection`;
const getNodeTypeNameForCollection = name => {
let nodeName = name;
// If the name is plural, use the Pluralize plugin to try make it singular
// This is to conform to the Gatsby convention of using singular names in their node types
if (Pluralize.isPlural(nodeName)) {
nodeName = Pluralize.singular(nodeName);
}
// Make the first letter upperace as per Gatsby's convention
nodeName = nodeName.charAt(0).toUpperCase() + nodeName.slice(1);
return nodeName;
};
for (const selection of selections) {
if (selection.kind === Kind.FIELD) {
this._imports.add(Imports.ResponseField);
const field = fields[selection.name.value];
const isObject = selection.selectionSet && selection.selectionSet.selections && selection.selectionSet.selections.length > 0;
const isNonNull = isNonNullType(field.type);
const fieldAnnotation = isNonNull ? 'Nonnull' : 'Nullable';
this._imports.add(Imports[fieldAnnotation]);
const baseType = getBaseType(field.type);
const isList = isListType(field.type) || (isNonNullType(field.type) && isListType(field.type.ofType));
if (isObject) {
let childClsName = this.convertName(field.name);
if (isList && isPlural(childClsName)) {
childClsName = singular(childClsName);
}
this.transformSelectionSet(
{
className: childClsName,
result: options.result,
selectionSet: selection.selectionSet.selections,
schemaType: baseType as GraphQLObjectType,
},
false
);
childFields.push({
rawType: field.type,
isObject: true,
function transformWord(word, toSingular) {
if (pluralize.isPlural(word)) {
return toSingular ? pluralize.singular(word) : word;
}
else {
return toSingular ? word : pluralize.plural(word);
}
}
function optsToArray(item) {
export function transformWord(word: string, toSingular: boolean) {
if (isPlural(word)) {
return toSingular ? singular(word) : word;
} else {
return toSingular ? word : plural(word);
}
}
pluralize.isPlural = (word: string) => require('pluralize').isPlural(word)
pluralize.isSingular = (word: string) => require('pluralize').isSingular(word)