Skip to content

Commit

Permalink
Merge pull request #34 from NicholasBellucci/develop
Browse files Browse the repository at this point in the history
Bugfix collections with ArgumentValueRepresentable values
  • Loading branch information
NicholasBellucci authored Sep 1, 2020
2 parents ed4b8b8 + b500575 commit bf59243
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/SociableWeaver/Protocols/Argument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ extension Array: ArgumentValueRepresentable {
return value.argumentValue
} else if let value = value as? Dictionary<String, Any> {
return value.argumentValue
} else if let value = value as? ArgumentValueRepresentable {
return value.argumentValue
}

return ""
Expand Down Expand Up @@ -113,6 +115,8 @@ extension Dictionary: ArgumentValueRepresentable {
return value.argumentValue
} else if let value = value as? Dictionary<String, Any> {
return value.argumentValue
} else if let value = value as? ArgumentValueRepresentable {
return value.argumentValue
} else if let _ = value as? NSNull {
return "null"
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/SociableWeaverTests/SociableWeaverGeneralTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ final class SociableWeaverGeneralTests: XCTestCase {
XCTAssertEqual(String(describing: query), expected)
}

func testOperationWithCustomEnumArray() {
enum PostCategories: EnumValueRepresentable {
case art
case music
case technology
}

let query = Weave(.query) {
Object(Post.self) {
Field(Post.CodingKeys.title)
Field(Post.CodingKeys.content)

Object(Post.CodingKeys.author) {
Field(Author.CodingKeys.id)
Field(Author.CodingKeys.name)
}
}
.argument(key: "category", value: [PostCategories.art, PostCategories.music, PostCategories.technology])
}

let expected = "query { post(category: [ART, MUSIC, TECHNOLOGY]) { title content author { id name } } }"
XCTAssertEqual(String(describing: query), expected)
}

static var allTests = [
("testOperationWithArguments", testOperationWithArguments),
("testOperationWithFragment", testOperationWithFragment),
Expand Down

0 comments on commit bf59243

Please sign in to comment.