Skip to content

Commit 354fcfb

Browse files
committed
Revert "Swap MapRepresentable with Encodable."
This reverts commit 29a0c5d.
1 parent 29a0c5d commit 354fcfb

39 files changed

+2215
-7022
lines changed

.gitignore

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
.DS_Store
2-
3-
### SwiftPM ###
4-
Packages
5-
.build/
6-
xcuserdata
7-
DerivedData/
8-
*.xcodeproj
9-
10-
### Xcode Patch ###
11-
*.xcodeproj/*
12-
!*.xcodeproj/project.pbxproj
13-
!*.xcodeproj/xcshareddata/
14-
!*.xcworkspace/contents.xcworkspacedata
15-
/*.gcno
16-
**/xcshareddata/WorkspaceSettings.xcsettings
17-
18-
## User settings
19-
xcuserdata/
2+
/.build
3+
/Packages
4+
/*.xcodeproj

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 0 additions & 7 deletions
This file was deleted.

.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

Lines changed: 0 additions & 8 deletions
This file was deleted.

Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ let package = Package(
1010

1111
dependencies: [
1212
.package(url: "https://github.com/wickwirew/Runtime.git", .upToNextMinor(from: "2.1.0")),
13-
.package(url: "https://github.com/apple/swift-nio.git", from: "1.14.1"),
13+
14+
// ⏱ Promises and reactive-streams in Swift built for high-performance and scalability.
15+
.package(url: "https://github.com/vapor/core.git", from: "3.0.0"),
1416
],
1517

1618
targets: [
17-
.target(name: "GraphQL", dependencies: ["Runtime", "NIO"]),
19+
.target(name: "GraphQL", dependencies: ["Runtime", "Async"]),
1820
.testTarget(name: "GraphQLTests", dependencies: ["GraphQL"]),
1921
]
2022
)

Sources/GraphQL/Error/GraphQLError.swift

Lines changed: 17 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
* it also includes information about the locations in a
55
* GraphQL document and/or execution result that correspond to the error.
66
*/
7-
public struct GraphQLError : Error, Encodable {
8-
private enum CodingKeys : String, CodingKey {
9-
case message
10-
case locations
11-
case path
12-
}
7+
public struct GraphQLError : Error {
138

149
/**
1510
* A message describing the Error for debugging purposes.
@@ -36,7 +31,7 @@ public struct GraphQLError : Error, Encodable {
3631
*
3732
* Appears in the result of `description`.
3833
*/
39-
public let path: IndexPath
34+
public let path: [IndexPathElement]
4035

4136
/**
4237
* An array of GraphQL AST Nodes corresponding to this error.
@@ -59,14 +54,8 @@ public struct GraphQLError : Error, Encodable {
5954
*/
6055
public let originalError: Error?
6156

62-
public init(
63-
message: String,
64-
nodes: [Node] = [],
65-
source: Source? = nil,
66-
positions: [Int] = [],
67-
path: IndexPath = [],
68-
originalError: Error? = nil
69-
) {
57+
public init(message: String, nodes: [Node] = [], source: Source? = nil, positions: [Int] = [],
58+
path: [IndexPathElement] = [], originalError: Error? = nil) {
7059
self.message = message
7160
self.nodes = nodes
7261

@@ -93,27 +82,6 @@ public struct GraphQLError : Error, Encodable {
9382
self.path = path
9483
self.originalError = originalError
9584
}
96-
97-
public init(
98-
message: String,
99-
locations: [SourceLocation],
100-
path: IndexPath = []
101-
) {
102-
self.message = message
103-
self.locations = locations
104-
self.path = path
105-
self.nodes = []
106-
self.source = nil
107-
self.positions = []
108-
self.originalError = nil
109-
}
110-
111-
public init(_ error: Error) {
112-
self.init(
113-
message: error.localizedDescription,
114-
originalError: error
115-
)
116-
}
11785
}
11886

11987
extension GraphQLError : CustomStringConvertible {
@@ -132,96 +100,23 @@ extension GraphQLError : Hashable {
132100
}
133101
}
134102

135-
// MARK: IndexPath
136-
137-
public struct IndexPath : Encodable {
138-
public let elements: [IndexPathValue]
139-
140-
public init(_ elements: [IndexPathElement] = []) {
141-
self.elements = elements.map({ $0.indexPathValue })
142-
}
143-
144-
public func appending(_ elements: IndexPathElement) -> IndexPath {
145-
return IndexPath(self.elements + [elements])
146-
}
147-
}
148-
149-
extension IndexPath : ExpressibleByArrayLiteral {
150-
public init(arrayLiteral elements: IndexPathElement...) {
151-
self.elements = elements.map({ $0.indexPathValue })
152-
}
153-
}
103+
extension GraphQLError : MapRepresentable {
104+
public var map: Map {
105+
var dictionary: [String: Map] = ["message": message.map]
154106

155-
public enum IndexPathValue : Encodable {
156-
case index(Int)
157-
case key(String)
158-
159-
public func encode(to encoder: Encoder) throws {
160-
var container = encoder.singleValueContainer()
161-
162-
switch self {
163-
case let .index(index):
164-
try container.encode(index)
165-
case let .key(key):
166-
try container.encode(key)
107+
if !path.isEmpty {
108+
dictionary["path"] = path.map({ $0.map }).map
167109
}
168-
}
169-
}
170110

171-
extension IndexPathValue : IndexPathElement {
172-
public var indexPathValue: IndexPathValue {
173-
return self
174-
}
175-
}
176-
177-
extension IndexPathValue : CustomStringConvertible {
178-
public var description: String {
179-
switch self {
180-
case let .index(index):
181-
return index.description
182-
case let .key(key):
183-
return key.description
111+
if !locations.isEmpty {
112+
dictionary["locations"] = locations.map({
113+
return [
114+
"line": $0.line.map,
115+
"column": $0.column.map
116+
] as Map
117+
}).map
184118
}
185-
}
186-
}
187-
188-
public protocol IndexPathElement {
189-
var indexPathValue: IndexPathValue { get }
190-
}
191-
192-
extension IndexPathElement {
193-
var constructEmptyContainer: Map {
194-
switch indexPathValue {
195-
case .index: return []
196-
case .key: return [:]
197-
}
198-
}
199-
}
200-
201-
extension IndexPathElement {
202-
public var indexValue: Int? {
203-
if case .index(let index) = indexPathValue {
204-
return index
205-
}
206-
return nil
207-
}
208-
209-
public var keyValue: String? {
210-
if case .key(let key) = indexPathValue {
211-
return key
212-
}
213-
return nil
214-
}
215-
}
216-
217-
extension Int : IndexPathElement {
218-
public var indexPathValue: IndexPathValue {
219-
return .index(self)
220-
}
221-
}
222119

223-
extension String : IndexPathElement {
224-
public var indexPathValue: IndexPathValue {
225-
return .key(self)
120+
return .dictionary(dictionary)
226121
}
227122
}

Sources/GraphQL/Error/LocatedError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* GraphQL operation, produce a new GraphQLError aware of the location in the
44
* document responsible for the original Error.
55
*/
6-
func locatedError(originalError: Error, nodes: [Node], path: IndexPath) -> GraphQLError {
6+
func locatedError(originalError: Error, nodes: [Node], path: [IndexPathElement]) -> GraphQLError {
77
// Note: this uses a brand-check to support GraphQL errors originating from
88
// other contexts.
99
if let originalError = originalError as? GraphQLError {

0 commit comments

Comments
 (0)