Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
propertiesForSelectionSet(
selectionSet: SelectionSet,
namespace?: string
): (Field & Property & Struct)[] | undefined {
const properties = collectAndMergeFields(selectionSet, true)
.filter(field => field.name !== "__typename")
.map(field => this.propertyFromField(field, namespace));
// If we're not merging in fields from fragment spreads, there is no guarantee there will a generated
// type for a composite field, so to avoid compiler errors we skip the initializer for now.
if (
selectionSet.selections.some(
selection => selection.kind === "FragmentSpread"
) &&
properties.some(property => isCompositeType(getNamedType(property.type)))
) {
return undefined;
}
return properties;
}
swift`public private(set) var resultMap: ResultMap`
);
this.printNewlineIfNeeded();
this.printOnNewline(swift`public init(unsafeResultMap: ResultMap)`);
this.withinBlock(() => {
this.printOnNewline(swift`self.resultMap = unsafeResultMap`);
});
if (typeCase) {
this.initializersForTypeCase(typeCase);
} else {
this.initializersForVariant(variant);
}
const fields = collectAndMergeFields(
variant,
!!mergeInFieldsFromFragmentSpreads
).map(field => this.helpers.propertyFromField(field as Field));
const fragmentSpreads = variant.fragmentSpreads.map(fragmentSpread => {
const isConditional = variant.possibleTypes.some(
type => !fragmentSpread.selectionSet.possibleTypes.includes(type)
);
return this.helpers.propertyFromFragmentSpread(
fragmentSpread,
isConditional
);
});
fields.forEach(this.propertyDeclarationForField, this);
private getPropertiesForVariant(variant: Variant): ObjectProperty[] {
const fields = collectAndMergeFields(
variant,
this.context.options.mergeInFieldsFromFragmentSpreads
);
return fields.map(field => {
const fieldName = field.alias !== undefined ? field.alias : field.name;
this.scopeStackPush(fieldName);
let res: ObjectProperty;
if (field.selectionSet) {
res = this.handleFieldSelectionSetValue(
t.identifier(this.nameFromScopeStack(this.scopeStack)),
field
);
} else {
res = this.handleFieldValue(field, variant);
}
private getPropertiesForVariant(variant: Variant): ObjectProperty[] {
const fields = collectAndMergeFields(
variant,
this.context.options.mergeInFieldsFromFragmentSpreads
);
return fields.map(field => {
const fieldName = field.alias !== undefined ? field.alias : field.name;
this.scopeStackPush(fieldName);
let res;
if (field.selectionSet) {
const generatedTypeName = this.annotationFromScopeStack(
this.scopeStack
);
res = this.handleFieldSelectionSetValue(generatedTypeName, field);
} else {
res = this.handleFieldValue(field, variant);