Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
context: LegacyCompilerContext,
field: GraphQLInputField,
namespace?: string,
parentTraitName?: string
): GraphQLInputField & Property {
const name = field.name;
const unescapedPropertyName = isMetaFieldName(name) ? name : camelCase(name);
const propertyName = escapeIdentifierIfNeeded(unescapedPropertyName);
const type = field.type;
const isList = isListType(type);
const isOptional = !isNonNullType(type);
const bareType = getNamedType(type);
const bareTypeName = isCompositeType(bareType)
? join(
[
namespace,
parentTraitName,
escapeIdentifierIfNeeded(pascalCase(Inflector.singularize(name)))
],
"."
)
: undefined;
const typeName = typeNameFromGraphQLType(
context,
type,
bareTypeName,
isOptional,
true
);
return {
classDeclaration(
{ className, modifiers, superClass, adoptedProtocols = [] }: Class,
closure: Function
) {
this.printNewlineIfNeeded();
this.printOnNewline(
(
wrap(swift``, new SwiftSource(_join(modifiers, " ")), swift` `) ||
swift``
).concat(swift`class ${className}`)
);
this.print(
wrap(
swift`: `,
join(
[
superClass !== undefined
? SwiftSource.identifier(superClass)
: undefined,
...adoptedProtocols.map(SwiftSource.identifier)
],
", "
)
)
insideCompanion: () => {
if (possibleTypes) {
generator.printNewlineIfNeeded();
generator.printOnNewline("val possibleTypes = scala.collection.Set(");
generator.print(
join(Array.from(possibleTypes).map(type => `"${String(type)}"`), ", ")
);
generator.print(")");
}
generator.printNewlineIfNeeded();
generator.printOnNewline(
`implicit class ViewExtensions(private val orig: ${traitName}) extends AnyVal`
);
generator.withinBlock(() => {
if (inlineFragments && inlineFragments.length > 0) {
inlineFragments.forEach(inlineFragment => {
const fragClass = traitNameForInlineFragment(inlineFragment);
generator.printOnNewline(`def as${inlineFragment.typeCondition}`);
generator.print(`: Option[${fragClass}] =`);
generator.withinBlock(() => {
generator.printOnNewline(
propertyFromField(
field: Field,
namespace?: string
): Field & Property & Struct {
const { responseKey, isConditional } = field;
const propertyName = isMetaFieldName(responseKey)
? responseKey
: camelCase(responseKey);
const structName = join(
[namespace, this.structNameForPropertyName(responseKey)],
"."
);
let type = field.type;
if (isConditional && isNonNullType(type)) {
type = type.ofType;
}
const isOptional = !isNonNullType(type);
const unmodifiedType = getNamedType(field.type);
const unmodifiedTypeName = isCompositeType(unmodifiedType)
? structName
export function propertyFromLegacyField(
context: LegacyCompilerContext,
field: LegacyField,
namespace?: string,
parentTraitName?: string
): LegacyField & Property {
const name = field.responseName;
const propertyName = escapeIdentifierIfNeeded(name);
const type = field.type;
const isList = isListType(type);
const isOptional = field.isConditional || !isNonNullType(type);
const bareType = getNamedType(type);
const bareTypeName = isCompositeType(bareType)
? join(
[
namespace,
parentTraitName,
escapeIdentifierIfNeeded(pascalCase(Inflector.singularize(name)))
],
"."
)
: undefined;
const typeName = typeNameFromGraphQLType(
context,
type,
bareTypeName,
isOptional
);
return { ...field, propertyName, typeName, isOptional, isList };
}
static join(
maybeArray?: (SwiftSource | undefined)[],
separator?: string
): SwiftSource | undefined {
const result = _join(maybeArray, separator);
return result ? new SwiftSource(result) : undefined;
}
}