Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (insideIgnoredFragment) {
return;
}
if (schema) {
const lastType = typesStack[typesStack.length - 1];
if (lastType && (isObjectType(lastType) || isInterfaceType(lastType))) {
const currentType = lastType.getFields()[node.name.value].type;
// To handle `Maybe` usage
if (hasNullableTypeRecursively(currentType)) {
foundFields++;
}
typesStack.push(getBaseType(currentType));
}
}
const selections = node.selectionSet ? node.selectionSet.selections || [] : [];
const relevantFragmentSpreads = selections.filter(s => s.kind === Kind.FRAGMENT_SPREAD && !externalFragments.includes(s.name.value));
if (selections.length === 0 || relevantFragmentSpreads.length > 0) {
foundFields++;
}
},
leave: (node: FieldNode, key, parent, path, anscestors) => {
if (!linkFieldNode) {
linkFieldNode = {
selectedFieldType: selectedField.type,
field: selectionNode,
};
linkFieldSelectionSets.set(fieldName, linkFieldNode);
} else {
mergeSelectionSets(linkFieldNode.field.selectionSet, selectionNode.selectionSet);
}
}
}
}
const linkFields: LinkField[] = [];
for (const { field, selectedFieldType } of linkFieldSelectionSets.values()) {
const realSelectedFieldType = getBaseType(selectedFieldType as any);
const selectionSet = this.createNext(realSelectedFieldType, field.selectionSet);
linkFields.push({
alias: field.alias ? field.alias.value : undefined,
name: field.name.value,
type: realSelectedFieldType.name,
selectionSet: this._processor.config.wrapTypeWithModifiers(
selectionSet
.transformSelectionSet()
.split(`\n`)
.join(`\n `),
selectedFieldType as any
),
});
}
const childFields: ChildField[] = [...(options.additionalFields || [])];
const childInlineFragments: { onType: string; node: InlineFragmentNode }[] = [];
const childFragmentSpread: LoadedFragment[] = [...(options.additionalFragments || [])];
const selections = [...(options.selectionSet || [])];
const responseFieldArr: string[] = [];
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,
},
const parentType = schema.getType(parentTypeName);
const typeName = baseVisitor.convertName(fieldName);
if (selectionSet && selectionSet.selections && selectionSet.selections.length) {
const typeToUse = handleTypeNameDuplicates(result, typeName, typesPrefix);
result[typeToUse] = { export: 'type', name: stack };
for (const selection of selectionSet.selections) {
switch (selection.kind) {
case Kind.FIELD: {
if (isObjectType(parentType) || isInterfaceType(parentType)) {
const selectionName = selection.alias && selection.alias.value ? selection.alias.value : selection.name.value;
if (!selectionName.startsWith('__')) {
const field = parentType.getFields()[selection.name.value];
const baseType = getBaseType(field.type);
const wrapWithNonNull = (baseVisitor.config.strict || baseVisitor.config.preResolveTypes) && !isNonNullType(field.type);
const isArray = (isNonNullType(field.type) && isListType(field.type.ofType)) || isListType(field.type);
const typeRef = `${stack}['${selectionName}']`;
const nonNullableInnerType = `${wrapWithNonNull ? `(NonNullable<${typeRef}>)` : typeRef}`;
const arrayInnerType = isArray ? `${nonNullableInnerType}[0]` : nonNullableInnerType;
const wrapArrayWithNonNull = baseVisitor.config.strict || baseVisitor.config.preResolveTypes;
const newStack = isArray && wrapArrayWithNonNull ? `(NonNullable<${arrayInnerType}>)` : arrayInnerType;
selectionSetToTypes(typesPrefix, baseVisitor, schema, baseType.name, newStack, selectionName, selection.selectionSet, preResolveTypes, result);
}
}
break;
}
case Kind.FRAGMENT_SPREAD: {
const fragmentName = baseVisitor.convertName(selection.name.value, { suffix: 'Fragment' });
.some(fieldName => {
const field = fields[fieldName];
const fieldType = getBaseType(field.type);
if (checkedBefore[fieldType.name] !== undefined) {
return checkedBefore[fieldType.name];
}
if (this.config.mappers[type.name]) {
return true;
}
duringCheck.push(type.name);
const innerResult = this.shouldMapType(fieldType, checkedBefore, duringCheck);
return innerResult;
});
}
return fields.map(aliasedField => {
const name = this.config.formatNamedField(aliasedField.alias);
if (aliasedField.fieldName === '__typename') {
return {
name,
type: `'${schemaType.name}'`,
};
} else {
const fieldObj = schemaType.getFields()[aliasedField.fieldName];
const baseType = getBaseType(fieldObj.type);
let typeToUse = this.config.scalars[baseType.name] || baseType.name;
if (isEnumType(baseType)) {
typeToUse = (this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : '') + this.config.convertName(baseType.name, { useTypesPrefix: this.config.enumPrefix });
}
const wrappedType = this.config.wrapTypeWithModifiers(typeToUse, fieldObj.type as GraphQLObjectType);
return {
name,
type: wrappedType,
};
}
});
}
.filter(fieldName => {
const field = fields[fieldName];
const fieldType = getBaseType(field.type);
return !duringCheck.includes(fieldType.name);
})
.some(fieldName => {
.map(fieldName => {
const field = fields[fieldName];
const baseType = getBaseType(field.type);
const isUnion = isUnionType(baseType);
if (!this.config.mappers[baseType.name] && !isUnion && !nestedMapping[baseType.name]) {
return null;
}
const addOptionalSign = !this.config.avoidOptionals && !isNonNullType(field.type);
return {
addOptionalSign,
fieldName,
replaceWithType: this.wrapTypeWithModifiers(getTypeToUse(baseType.name), field.type),
};
})
.filter(a => a);