Skip to content

Commit

Permalink
Merge pull request #82 from NeedleInAJayStack/feature/input-field-as
Browse files Browse the repository at this point in the history
Input Field "as" initializer
  • Loading branch information
NeedleInAJayStack authored Aug 26, 2022
2 parents afa0873 + 05d24f9 commit 508f24e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Sources/Graphiti/InputField/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public extension InputField {
}
}

public extension InputField {
convenience init(
_ name: String,
as _: FieldType.Type
) {
self.init(name: name)
}
}

public extension InputField where FieldType: Encodable {
func defaultValue(_ defaultValue: FieldType) -> Self {
self.defaultValue = AnyEncodable(defaultValue)
Expand Down
2 changes: 1 addition & 1 deletion Tests/GraphitiTests/HelloWorldTests/HelloWorldTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct HelloAPI: API {

Input(UserInput.self) {
InputField("id", at: \.id)
InputField("name", at: \.name)
InputField("name", as: String?.self)
InputField("friends", at: \.friends, as: [TypeReference<UserInput>]?.self)
}

Expand Down

0 comments on commit 508f24e

Please sign in to comment.