Skip to content

Commit 097888c

Browse files
committed
tidy up
1 parent f6896f5 commit 097888c

27 files changed

+391
-493
lines changed

Sources/GraphQL/Error/GraphQLError.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
/**
22
* A GraphQLError describes an Error found during the parse, validate, or
33
* execute phases of performing a GraphQL operation. In addition to a message
4-
* and stack trace, it also includes information about the locations in a
5-
* GraphQL document and/or execution result that correspond to the Error.
4+
* it also includes information about the locations in a
5+
* GraphQL document and/or execution result that correspond to the error.
66
*/
77
public struct GraphQLError : Error {
88

99
/**
1010
* A message describing the Error for debugging purposes.
1111
*
12-
* Enumerable, and appears in the result of JSON.stringify().
12+
* Appears in the result of `description`.
1313
*/
1414
let message: String
1515

1616
/**
17-
* An array of { line, column } locations within the source GraphQL document
17+
* An array of (line: Int, column: Int) locations within the source GraphQL document
1818
* which correspond to this error.
1919
*
2020
* Errors during validation often contain multiple locations, for example to
2121
* point out two things with the same name. Errors during execution include a
2222
* single location, the field which produced the error.
2323
*
24-
* Enumerable, and appears in the result of JSON.stringify().
24+
* Appears in the result of `description`.
2525
*/
2626
let locations: [SourceLocation]
2727

2828
/**
29-
* An array describing the JSON-path into the execution response which
29+
* An array describing the index path into the execution response which
3030
* corresponds to this error. Only included for errors during execution.
3131
*
32-
* Enumerable, and appears in the result of JSON.stringify().
32+
* Appears in the result of `description`.
3333
*/
3434
let path: [IndexPathElement]
3535

Sources/GraphQL/Execution/Execute.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ final class ExecutionContext {
5656
/**
5757
* Implements the "Evaluating requests" section of the GraphQL specification.
5858
*
59-
* Returns a Promise that will eventually be resolved and never rejected.
60-
*
6159
* If the arguments to this func do not result in a legal execution context,
6260
* a GraphQLError will be thrown immediately explaining the invalid input.
6361
*/
@@ -69,7 +67,6 @@ func execute(
6967
variableValues: [String: Map] = [:],
7068
operationName: String? = nil
7169
) throws -> Map {
72-
7370
// If a valid context cannot be created due to incorrect arguments,
7471
// this will throw an error.
7572
let context = try buildExecutionContext(
@@ -489,7 +486,7 @@ func resolveField(
489486
let returnType = fieldDef.type
490487
let resolve = fieldDef.resolve ?? defaultResolve
491488

492-
// Build a JS object of arguments from the field.arguments AST, using the
489+
// Build a Map object of arguments from the field.arguments AST, using the
493490
// variables scope to fulfill any variable references.
494491
// TODO: find a way to memoize, in case this field is within a List type.
495492
let args = try getArgumentValues(
@@ -544,7 +541,7 @@ enum ResultOrError {
544541
}
545542

546543
// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
547-
// function. Returns the result of resolveFn or the abrupt-return Error object.
544+
// function. Returns the result of `resolve` or the abrupt-return Error object.
548545
func resolveOrError(
549546
resolve: GraphQLFieldResolve,
550547
source: MapRepresentable,
@@ -597,7 +594,7 @@ func completeValueCatchingError(
597594
return completed
598595
} catch let error as GraphQLError {
599596
// If `completeValueWithLocatedError` returned abruptly (threw an error),
600-
// log the error and return null.
597+
// log the error and return .null.
601598
exeContext.errors.append(error)
602599
return Map.null
603600
} catch {
@@ -669,7 +666,7 @@ func completeValue(
669666
throw error
670667
case .result(let result):
671668
// If field type is NonNull, complete for inner type, and throw field error
672-
// if result is null.
669+
// if result is nullish.
673670
if let returnType = returnType as? GraphQLNonNull {
674671
let completed = try completeValue(
675672
exeContext: exeContext,
@@ -689,7 +686,7 @@ func completeValue(
689686
return completed
690687
}
691688

692-
// If result value is null-ish (null, undefined, or NaN) then return null.
689+
// If result value is null-ish (nil or .null) then return .null.
693690
if isNullish(result) {
694691
return Map.null
695692
}
@@ -707,7 +704,7 @@ func completeValue(
707704
}
708705

709706
// If field type is a leaf type, Scalar or Enum, serialize to a valid value,
710-
// returning null if serialization is not possible.
707+
// returning .null if serialization is not possible.
711708
if let returnType = returnType as? GraphQLLeafType {
712709
return try completeLeafValue(returnType: returnType, result: result)
713710
}
@@ -759,7 +756,7 @@ func completeListValue(
759756
guard let result = result as? [MapRepresentable] else {
760757
throw GraphQLError(
761758
message:
762-
"Expected Iterable, but did not find one for field " +
759+
"Expected array, but did not find one for field " +
763760
"\(info.parentType.name).\(info.fieldName)."
764761
)
765762
}
@@ -789,7 +786,7 @@ func completeListValue(
789786

790787
/**
791788
* Complete a Scalar or Enum by serializing to a valid value, returning
792-
* null if serialization is not possible.
789+
* .null if serialization is not possible.
793790
*/
794791
func completeLeafValue(returnType: GraphQLLeafType, result: MapRepresentable) throws -> Map {
795792
let serializedResult = try returnType.serialize(value: result)
@@ -802,7 +799,7 @@ func completeLeafValue(returnType: GraphQLLeafType, result: MapRepresentable) th
802799
)
803800
}
804801

805-
return serializedResult!
802+
return serializedResult
806803
}
807804

808805
/**

Sources/GraphQL/Execution/Values.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func coerceValue(type: GraphQLInputType, value: Map) throws -> Map? {
159159
}
160160

161161
guard let type = type as? GraphQLLeafType else {
162-
fatalError("Must be input type")
162+
throw GraphQLError(message: "Must be input type")
163163
}
164164

165165
let parsed = try type.parseValue(value: value)

Sources/GraphQL/GraphQL.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/// - parameter schema: The GraphQL type system to use when validating and executing a query.
1010
/// - parameter request: A GraphQL language formatted string representing the requested operation.
1111
/// - parameter rootValue: The value provided as the first argument to resolver functions on the top level type (e.g. the query object type).
12-
/// - parameter contextValue: contextValue description
12+
/// - parameter contextValue: A context value provided to all resolver functions functions
1313
/// - parameter variableValues: A mapping of variable name to runtime value to use for all variables defined in the `request`.
1414
/// - parameter operationName: The name of the operation to use if `request` contains multiple possible operations. Can be omitted if `request` contains only one operation.
1515
///
16-
/// - throws: throws value description
16+
/// - throws: throws GraphQLError if an error occurs while parsing the `request`.
1717
///
18-
/// - returns: return value description
18+
/// - returns: returns a `Map` dictionary containing the result of the query inside the key `data` and any validation or execution errors inside the key `errors`. The value of `data` might be `null` if, for example, the query is invalid. It's possible to have both `data` and `errors` if an error occurs only in a specific field. If that happens the value of that field will be `null` and there will be an error inside `errors` specifying the reason for the failure and the path of the failed field.
1919
public func graphql(
2020
schema: GraphQLSchema,
2121
request: String,

Sources/GraphQL/Language/AST.swift

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -171,42 +171,42 @@ extension Node {
171171
}
172172
}
173173

174-
extension Name : Node {}
175-
extension Document : Node {}
176-
extension OperationDefinition : Node {}
177-
extension VariableDefinition : Node {}
178-
extension Variable : Node {}
179-
extension SelectionSet : Node {}
180-
extension Field : Node {}
181-
extension Argument : Node {}
182-
extension FragmentSpread : Node {}
183-
extension InlineFragment : Node {}
184-
extension FragmentDefinition : Node {}
185-
extension IntValue : Node {}
186-
extension FloatValue : Node {}
187-
extension StringValue : Node {}
188-
extension BooleanValue : Node {}
189-
extension EnumValue : Node {}
190-
extension ListValue : Node {}
191-
extension ObjectValue : Node {}
192-
extension ObjectField : Node {}
193-
extension Directive : Node {}
194-
extension NamedType : Node {}
195-
extension ListType : Node {}
196-
extension NonNullType : Node {}
197-
extension SchemaDefinition : Node {}
198-
extension OperationTypeDefinition : Node {}
199-
extension ScalarTypeDefinition : Node {}
200-
extension ObjectTypeDefinition : Node {}
201-
extension FieldDefinition : Node {}
202-
extension InputValueDefinition : Node {}
203-
extension InterfaceTypeDefinition : Node {}
204-
extension UnionTypeDefinition : Node {}
205-
extension EnumTypeDefinition : Node {}
206-
extension EnumValueDefinition : Node {}
174+
extension Name : Node {}
175+
extension Document : Node {}
176+
extension OperationDefinition : Node {}
177+
extension VariableDefinition : Node {}
178+
extension Variable : Node {}
179+
extension SelectionSet : Node {}
180+
extension Field : Node {}
181+
extension Argument : Node {}
182+
extension FragmentSpread : Node {}
183+
extension InlineFragment : Node {}
184+
extension FragmentDefinition : Node {}
185+
extension IntValue : Node {}
186+
extension FloatValue : Node {}
187+
extension StringValue : Node {}
188+
extension BooleanValue : Node {}
189+
extension EnumValue : Node {}
190+
extension ListValue : Node {}
191+
extension ObjectValue : Node {}
192+
extension ObjectField : Node {}
193+
extension Directive : Node {}
194+
extension NamedType : Node {}
195+
extension ListType : Node {}
196+
extension NonNullType : Node {}
197+
extension SchemaDefinition : Node {}
198+
extension OperationTypeDefinition : Node {}
199+
extension ScalarTypeDefinition : Node {}
200+
extension ObjectTypeDefinition : Node {}
201+
extension FieldDefinition : Node {}
202+
extension InputValueDefinition : Node {}
203+
extension InterfaceTypeDefinition : Node {}
204+
extension UnionTypeDefinition : Node {}
205+
extension EnumTypeDefinition : Node {}
206+
extension EnumValueDefinition : Node {}
207207
extension InputObjectTypeDefinition : Node {}
208-
extension TypeExtensionDefinition : Node {}
209-
extension DirectiveDefinition : Node {}
208+
extension TypeExtensionDefinition : Node {}
209+
extension DirectiveDefinition : Node {}
210210

211211
final class Name {
212212
let kind: Kind = .name
@@ -264,9 +264,9 @@ extension Document : Equatable {
264264
}
265265
}
266266

267-
protocol Definition : Node {}
267+
protocol Definition : Node {}
268268
extension OperationDefinition : Definition {}
269-
extension FragmentDefinition : Definition {}
269+
extension FragmentDefinition : Definition {}
270270

271271
func == (lhs: Definition, rhs: Definition) -> Bool {
272272
switch lhs {
@@ -469,8 +469,8 @@ extension SelectionSet : Hashable {
469469
}
470470
}
471471

472-
protocol Selection : Node {}
473-
extension Field : Selection {}
472+
protocol Selection : Node {}
473+
extension Field : Selection {}
474474
extension FragmentSpread : Selection {}
475475
extension InlineFragment : Selection {}
476476

@@ -578,9 +578,9 @@ extension Argument : Equatable {
578578
}
579579
}
580580

581-
protocol Fragment : Selection {}
582-
extension FragmentSpread : Fragment {}
583-
extension InlineFragment : Fragment {}
581+
protocol Fragment : Selection {}
582+
extension FragmentSpread : Fragment {}
583+
extension InlineFragment : Fragment {}
584584

585585
final class FragmentSpread {
586586
let kind: Kind = .fragmentSpread
@@ -721,15 +721,15 @@ extension FragmentDefinition : Hashable {
721721
}
722722
}
723723

724-
public protocol Value : Node {}
725-
extension Variable : Value {}
726-
extension IntValue : Value {}
727-
extension FloatValue : Value {}
728-
extension StringValue : Value {}
724+
public protocol Value : Node {}
725+
extension Variable : Value {}
726+
extension IntValue : Value {}
727+
extension FloatValue : Value {}
728+
extension StringValue : Value {}
729729
extension BooleanValue : Value {}
730-
extension EnumValue : Value {}
731-
extension ListValue : Value {}
732-
extension ObjectValue : Value {}
730+
extension EnumValue : Value {}
731+
extension ListValue : Value {}
732+
extension ObjectValue : Value {}
733733

734734
public func == (lhs: Value, rhs: Value) -> Bool {
735735
switch lhs {
@@ -941,9 +941,9 @@ extension Directive : Equatable {
941941
}
942942
}
943943

944-
protocol Type : Node {}
945-
extension NamedType : Type {}
946-
extension ListType : Type {}
944+
protocol Type : Node {}
945+
extension NamedType : Type {}
946+
extension ListType : Type {}
947947
extension NonNullType : Type {}
948948

949949
func == (lhs: Type, rhs: Type) -> Bool {
@@ -1042,10 +1042,10 @@ extension NonNullType : Equatable {
10421042

10431043
// Type System Definition
10441044
// experimental non-spec addition.
1045-
protocol TypeSystemDefinition : Definition {}
1046-
extension SchemaDefinition : TypeSystemDefinition {}
1045+
protocol TypeSystemDefinition : Definition {}
1046+
extension SchemaDefinition : TypeSystemDefinition {}
10471047
extension TypeExtensionDefinition : TypeSystemDefinition {}
1048-
extension DirectiveDefinition : TypeSystemDefinition {}
1048+
extension DirectiveDefinition : TypeSystemDefinition {}
10491049

10501050
func == (lhs: TypeSystemDefinition, rhs: TypeSystemDefinition) -> Bool {
10511051
switch lhs {
@@ -1112,13 +1112,13 @@ extension OperationTypeDefinition : Equatable {
11121112
}
11131113
}
11141114

1115-
protocol TypeDefinition : TypeSystemDefinition {}
1116-
extension ScalarTypeDefinition : TypeDefinition {}
1117-
extension ObjectTypeDefinition : TypeDefinition {}
1118-
extension InterfaceTypeDefinition : TypeDefinition {}
1119-
extension UnionTypeDefinition : TypeDefinition {}
1120-
extension EnumTypeDefinition : TypeDefinition {}
1121-
extension InputObjectTypeDefinition : TypeDefinition {}
1115+
protocol TypeDefinition : TypeSystemDefinition {}
1116+
extension ScalarTypeDefinition : TypeDefinition {}
1117+
extension ObjectTypeDefinition : TypeDefinition {}
1118+
extension InterfaceTypeDefinition : TypeDefinition {}
1119+
extension UnionTypeDefinition : TypeDefinition {}
1120+
extension EnumTypeDefinition : TypeDefinition {}
1121+
extension InputObjectTypeDefinition : TypeDefinition {}
11221122

11231123
func == (lhs: TypeDefinition, rhs: TypeDefinition) -> Bool {
11241124
switch lhs {

Sources/GraphQL/Language/Lexer.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,38 +120,6 @@ extension String {
120120
}
121121
}
122122

123-
/**
124-
* Helper function for constructing the Token object.
125-
*/
126-
//function Tok(
127-
// kind,
128-
// start: number,
129-
// end: number,
130-
// line: number,
131-
// column: number,
132-
// prev: Token | null,
133-
// value?: string
134-
//) {
135-
// this.kind = kind
136-
// this.start = start
137-
// this.end = end
138-
// this.line = line
139-
// this.column = column
140-
// this.value = value
141-
// this.prev = prev
142-
// this.next = null
143-
//}
144-
145-
// Print a simplified form when appearing in JSON/util.inspect.
146-
//Tok.prototype.toJSON = Tok.prototype.inspect = function toJSON() {
147-
// return {
148-
// kind: this.kind,
149-
// value: this.value,
150-
// line: this.line,
151-
// column: this.column
152-
// }
153-
//}
154-
155123
func character(_ code: UInt8) -> Character {
156124
return Character(UnicodeScalar(code))
157125
}

0 commit comments

Comments
 (0)