Skip to content

Commit 47267e6

Browse files
test: Adds non-editing visitor tests
1 parent 9a31a89 commit 47267e6

File tree

4 files changed

+834
-5
lines changed

4 files changed

+834
-5
lines changed

Sources/GraphQL/Error/GraphQLError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ extension IndexPath: ExpressibleByArrayLiteral {
197197
}
198198
}
199199

200-
public enum IndexPathValue: Codable {
200+
public enum IndexPathValue: Codable, Equatable {
201201
case index(Int)
202202
case key(String)
203203

@@ -242,7 +242,7 @@ extension IndexPathValue: CustomStringConvertible {
242242
}
243243
}
244244

245-
public protocol IndexPathElement {
245+
public protocol IndexPathElement: CustomStringConvertible {
246246
var indexPathValue: IndexPathValue { get }
247247
}
248248

Sources/GraphQL/Language/AST.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Contains a range of UTF-8 character offsets and token references that
33
* identify the region of the source from which the AST derived.
44
*/
5-
public struct Location {
5+
public struct Location: Equatable {
66
/**
77
* The character offset at which this Node begins.
88
*/
@@ -159,6 +159,21 @@ public enum NodeResult {
159159
}
160160
return false
161161
}
162+
163+
func get(key: IndexPathElement) -> NodeResult? {
164+
switch self {
165+
case let .node(node):
166+
guard let key = key.keyValue else {
167+
return nil
168+
}
169+
return node.get(key: key)
170+
case let .array(array):
171+
guard let key = key.indexValue else {
172+
return nil
173+
}
174+
return .node(array[key])
175+
}
176+
}
162177
}
163178

164179
/**

Sources/GraphQL/Language/Kinds.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public enum Kind: CaseIterable {
1+
public enum Kind: String, CaseIterable {
22
case name
33
case document
44
case operationDefinition

0 commit comments

Comments
 (0)