-
Notifications
You must be signed in to change notification settings - Fork 22
InputValue [4 of 4] #14
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
Changes from all commits
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 |
---|---|---|
|
@@ -298,6 +298,38 @@ public struct SchemaViolationError: Error { | |
} | ||
} | ||
|
||
public enum InputValue<T> { | ||
case some(T) | ||
case null | ||
case undefined | ||
|
||
public init(orNull optional: Optional<T>) { | ||
if let value = optional { | ||
self = .some(value) | ||
} else { | ||
self = .null | ||
} | ||
} | ||
|
||
public init(orUndefined optional: Optional<T>) { | ||
if let value = optional { | ||
self = .some(value) | ||
} else { | ||
self = .undefined | ||
} | ||
} | ||
} | ||
|
||
public extension Optional { | ||
public var orNull: InputValue<Wrapped> { | ||
return InputValue(orNull: self) | ||
} | ||
|
||
public var orUndefined: InputValue<Wrapped> { | ||
return InputValue(orUndefined: self) | ||
} | ||
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. These optional extensions feel redundant to me. Not everyone will want to use them. These could be removed from the generator. Consumers that want this extension can always build it themselves. 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. True. Agreed. |
||
} | ||
|
||
extension GraphQL.Selection: Equatable {} | ||
public func ==(lhs: GraphQL.Selection, rhs: GraphQL.Selection) -> Bool { | ||
return (lhs === rhs) || (lhs.field == rhs.field && lhs.alias == rhs.alias && lhs.args == rhs.args && lhs.subfields == rhs.subfields) | ||
|
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.
This looks like a painful way to generate code 😕 I think
graphql_swift_gen.rb
is more of a place to do some calculated logic rather then template the entireinit
. Having a function that is constantly appening to a string isn't nearly as readable or friendly as using embedded ruby. This should be intype.swift.erb
.