-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift Codegen Upgrades #1441
Swift Codegen Upgrades #1441
Changes from all commits
43269cb
b66e256
0839e46
27215b0
2c210f5
d0fb42b
2ada433
c4986fe
b4def67
db9112d
72c8e6c
3f4a6a0
216fe2e
58cf555
17de607
4f01da2
e26e9c4
724e81e
f07badd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,7 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> { | |
}, | ||
() => { | ||
if (source) { | ||
this.commentWithoutTrimming(source); | ||
this.printOnNewline("public let operationDefinition ="); | ||
this.withIndent(() => { | ||
this.multilineString(source); | ||
|
@@ -315,6 +316,7 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> { | |
outputIndividualFiles, | ||
() => { | ||
if (source) { | ||
this.commentWithoutTrimming(source); | ||
this.printOnNewline("public static let fragmentDefinition ="); | ||
this.withIndent(() => { | ||
this.multilineString(source); | ||
|
@@ -977,7 +979,7 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> { | |
this.printNewlineIfNeeded(); | ||
this.comment(description || undefined); | ||
this.printOnNewline( | ||
`public enum ${name}: RawRepresentable, Equatable, Hashable, Apollo.JSONDecodable, Apollo.JSONEncodable` | ||
`public enum ${name}: RawRepresentable, Equatable, Hashable, CaseIterable, Apollo.JSONDecodable, Apollo.JSONEncodable` | ||
); | ||
this.withinBlock(() => { | ||
this.printOnNewline("public typealias RawValue = String"); | ||
|
@@ -1049,6 +1051,21 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> { | |
this.printOnNewline(`default: return false`); | ||
}); | ||
}); | ||
|
||
this.printNewlineIfNeeded(); | ||
this.printOnNewline(`public static var allCases: [${name}]`); | ||
this.withinBlock(() => { | ||
this.printOnNewline(`return [`); | ||
values.forEach(value => { | ||
const enumDotCaseName = escapeIdentifierIfNeeded( | ||
this.helpers.enumDotCaseName(value.name) | ||
); | ||
this.withIndent(() => { | ||
this.printOnNewline(`${enumDotCaseName},`); | ||
}); | ||
}); | ||
this.printOnNewline(`]`); | ||
}); | ||
}); | ||
} | ||
|
||
|
@@ -1120,7 +1137,8 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> { | |
name, | ||
propertyName, | ||
typeName, | ||
description | ||
description, | ||
isOptional | ||
} of properties) { | ||
this.printNewlineIfNeeded(); | ||
this.comment(description || undefined); | ||
|
@@ -1130,9 +1148,15 @@ export class SwiftAPIGenerator extends SwiftGenerator<CompilerContext> { | |
this.withinBlock(() => { | ||
this.printOnNewline("get"); | ||
this.withinBlock(() => { | ||
this.printOnNewline( | ||
`return graphQLMap["${name}"] as! ${typeName}` | ||
); | ||
if (isOptional) { | ||
this.printOnNewline( | ||
`return graphQLMap["${name}"] as? ${typeName} ?? .none` | ||
); | ||
} else { | ||
this.printOnNewline( | ||
`return graphQLMap["${name}"] as! ${typeName}` | ||
); | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be rewritten: this.withinBlock(() =>
this.printOnNewline( isOptional
? `return graphQLMap["${name}"] as? ${typeName}`
: `return graphQLMap["${name}"] as! ${typeName}`)) or even this.withinBlock(() =>
this.printOnNewline(`return graphQLMap["${name}"] as${isOptional ? '?' : '!'} ${typeName}`)) IMO this makes it a bit more immediately clear what the effect of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more in line with how this is done throughout the rest of the file - I like the first option but I'm slightly reluctant to touch the other stuff at the moment if I don't have to. |
||
this.printOnNewline("set"); | ||
this.withinBlock(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I very explicitly do not want this. This comment just bloats the file. I notice all your tests are relatively short snippets, but for comparison, I have a single query I'm looking at right now that spans 56 lines, and I'd really not like to have a 56-line comment in the generated source obscuring the actual datatype.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is at least one other person who has explicitly requested multiline string support.
In your opinion, what is better when we're talking about things of similar length: A multiline string that has to be compiled or a multiline comment that doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment approach is better. Can we make it an option as to whether to have it though?