Skip to content

Commit 06a8678

Browse files
authored
Improve API (#3)
* Improve API * improve arguments API * update README
1 parent 86852d0 commit 06a8678

File tree

15 files changed

+553
-614
lines changed

15 files changed

+553
-614
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ First, build a Graphiti type schema which maps to your code base.
4242

4343
```swift
4444
let schema = try Schema<Void> { schema in
45-
schema.query = try ObjectType(name: "RootQueryType") { query in
46-
try query.field(name: "hello", type: String.self) { _ in
47-
"world"
45+
schema.query { query in
46+
try query.field(name: "hello", type: String.self) { _, _, _, _ in
47+
return "world"
4848
}
4949
}
5050
}
@@ -93,7 +93,7 @@ Output:
9393
"column": 3
9494
}
9595
],
96-
"message": "Cannot query field \"boyhowdy\" on type \"RootQueryType\"."
96+
"message": "Cannot query field \"boyhowdy\" on type \"Query\"."
9797
}
9898
]
9999
}

Sources/Graphiti/Graphiti.swift

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1-
import GraphQL
1+
import protocol GraphQL.MapFallibleRepresentable
22
@_exported import enum GraphQL.Map
33
@_exported import enum GraphQL.MapError
4+
5+
final class AnyType : Hashable {
6+
let type: Any.Type
7+
8+
init(_ type: Any.Type) {
9+
self.type = type
10+
}
11+
12+
var hashValue: Int {
13+
return String(describing: type).hashValue
14+
}
15+
16+
static func == (lhs: AnyType, rhs: AnyType) -> Bool {
17+
return lhs.hashValue == rhs.hashValue
18+
}
19+
}
20+
21+
func isProtocol(type: Any.Type) -> Bool {
22+
let description = String(describing: type(of: type))
23+
return description.hasSuffix("Protocol")
24+
}
25+
26+
func fixName(_ name: String) -> String {
27+
if name.hasPrefix("(") {
28+
var newName: [Character] = []
29+
30+
for character in String(name.characters.dropFirst()).characters {
31+
if character != " " {
32+
newName.append(character)
33+
} else {
34+
break
35+
}
36+
}
37+
38+
return String(newName)
39+
}
40+
41+
return name
42+
}
43+
44+
45+
func isMapFallibleRepresentable(type: Any.Type) -> Bool {
46+
if isProtocol(type: type) {
47+
return true
48+
}
49+
50+
if let type = type as? Wrapper.Type {
51+
return isMapFallibleRepresentable(type: type.wrappedType)
52+
}
53+
54+
return type is MapFallibleRepresentable.Type
55+
}
56+

0 commit comments

Comments
 (0)