Skip to content

Commit

Permalink
Add in deprecations for Swift (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximusMcCann authored and martijnwalraven committed Aug 4, 2017
1 parent dc6722a commit 18c837f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/swift/codeGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
propertyDeclarations,
escapeIdentifierIfNeeded,
comment,
deprecation,
Property
} from './language';

Expand Down Expand Up @@ -434,7 +435,7 @@ function operationIdentifier(
}

function propertyDeclarationForField(generator: CodeGenerator, field: Field) {
const { kind, propertyName, typeName, type, isConditional, description } = propertyFromField(
const { kind, propertyName, typeName, type, isConditional, description, isDeprecated, deprecationReason } = propertyFromField(
generator.context,
field
);
Expand All @@ -443,6 +444,7 @@ function propertyDeclarationForField(generator: CodeGenerator, field: Field) {

generator.printNewlineIfNeeded();
comment(generator, description);
deprecation(generator, isDeprecated, deprecationReason)
generator.printOnNewline(`public var ${propertyName}: ${typeName}`);
generator.withinBlock(() => {
if (isCompositeType(namedType)) {
Expand Down Expand Up @@ -647,6 +649,7 @@ function enumerationDeclaration(generator: CodeGenerator, type: GraphQLEnumType)
generator.withinBlock(() => {
values.forEach(value => {
comment(generator, value.description);
deprecation(generator, value.isDeprecated, value.deprecationReason)
generator.printOnNewline(
`case ${escapeIdentifierIfNeeded(enumCaseName(value.name))} = "${value.value}"`
);
Expand Down
7 changes: 7 additions & 0 deletions src/swift/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export function comment(generator: CodeGenerator, comment: string | undefined) {
});
}

export function deprecation(generator: CodeGenerator, isDeprecated: boolean | undefined, deprecationReason: string | undefined) {
if (isDeprecated !== undefined && isDeprecated) {
deprecationReason = (deprecationReason !== undefined && deprecationReason.length > 0) ? deprecationReason : ""
generator.printOnNewline(`@available(*, deprecated, message: "${deprecationReason}")`)
}
}

export function namespaceDeclaration(
generator: CodeGenerator,
namespace: string | undefined,
Expand Down

0 comments on commit 18c837f

Please sign in to comment.