-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InputValue & OutputType Conversion protocols
- Loading branch information
1 parent
b91ac93
commit 8d96c9c
Showing
6 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public protocol OutputTypeConvertible { | ||
@inlinable static var asOutputType: Selection.Field.OutputType { get } | ||
} | ||
|
||
extension String: OutputTypeConvertible { | ||
public static let asOutputType: Selection.Field.OutputType = .nonNull(.scalar(String.self)) | ||
} | ||
extension Int: OutputTypeConvertible { | ||
public static let asOutputType: Selection.Field.OutputType = .nonNull(.scalar(Int.self)) | ||
} | ||
extension Bool: OutputTypeConvertible { | ||
public static let asOutputType: Selection.Field.OutputType = .nonNull(.scalar(Bool.self)) | ||
} | ||
extension Float: OutputTypeConvertible { | ||
public static let asOutputType: Selection.Field.OutputType = .nonNull(.scalar(Float.self)) | ||
} | ||
extension Double: OutputTypeConvertible { | ||
public static let asOutputType: Selection.Field.OutputType = .nonNull(.scalar(Double.self)) | ||
} | ||
|
||
extension Optional: OutputTypeConvertible where Wrapped: OutputTypeConvertible { | ||
@inlinable public static var asOutputType: Selection.Field.OutputType { | ||
guard case let .nonNull(wrappedOutputType) = Wrapped.asOutputType else { | ||
return Wrapped.asOutputType | ||
} | ||
return wrappedOutputType | ||
} | ||
} | ||
|
||
extension Array: OutputTypeConvertible where Element: OutputTypeConvertible { | ||
@inlinable public static var asOutputType: Selection.Field.OutputType { | ||
.nonNull(.list(Element.asOutputType)) | ||
} | ||
} | ||
|
||
extension AnySelectionSet { | ||
@inlinable public static var asOutputType: Selection.Field.OutputType { | ||
.nonNull(.object(self)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters