Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks/StarWarsData.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import GraphQL

/**
/*
* This defines a basic set of data for our Star Wars Schema.
*
* This data is hard coded for the sake of the demo, but you could imagine
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks/Benchmarks/StarWarsSchema.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import GraphQL

/**
/*
* This is designed to be an end-to-end test, demonstrating
* the full GraphQL stack.
*
Expand All @@ -11,7 +11,7 @@ import GraphQL
* Wars trilogy.
*/

/**
/*
* Using our shorthand to describe type systems, the type system for our
* Star Wars example is:
*
Expand Down
4 changes: 1 addition & 3 deletions Sources/GraphQL/Error/SyntaxError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import Foundation
func syntaxError(source: Source, position: Int, description: String) -> GraphQLError {
let location = getLocation(source: source, position: position)

let error = GraphQLError(
return GraphQLError(
message:
"Syntax Error \(source.name) (\(location.line):\(location.column)) " +
description + "\n\n" +
highlightSourceAtLocation(source: source, location: location),
source: source,
positions: [position]
)

return error
}

/**
Expand Down
27 changes: 11 additions & 16 deletions Sources/GraphQL/Execution/Execute.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Dispatch
import OrderedCollections

/**
/*
* Terminology
*
* "Definitions" are the generic name for top-level statements in the document.
Expand Down Expand Up @@ -632,8 +632,8 @@ public func resolveField(
)
}

// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
// function. Returns the result of `resolve` or the abrupt-return Error object.
/// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
/// function. Returns the result of `resolve` or the abrupt-return Error object.
func resolveOrError(
resolve: GraphQLFieldResolve,
source: any Sendable,
Expand All @@ -649,8 +649,8 @@ func resolveOrError(
}
}

// This is a small wrapper around completeValue which detects and logs errors
// in the execution context.
/// This is a small wrapper around completeValue which detects and logs errors
/// in the execution context.
func completeValueCatchingError(
exeContext: ExecutionContext,
returnType: GraphQLType,
Expand Down Expand Up @@ -693,8 +693,8 @@ func completeValueCatchingError(
}
}

// This is a small wrapper around completeValue which annotates errors with
// location information.
/// This is a small wrapper around completeValue which annotates errors with
/// location information.
func completeValueWithLocatedError(
exeContext: ExecutionContext,
returnType: GraphQLType,
Expand Down Expand Up @@ -886,11 +886,9 @@ func completeLeafValue(returnType: GraphQLLeafType, result: (any Sendable)?) thr
guard let result = result else {
return .null
}
let serializedResult = try returnType.serialize(value: result)
return try returnType.serialize(value: result)

// Do not check for serialization to null here. Some scalars may model literals as `Map.null`.

return serializedResult
}

/**
Expand Down Expand Up @@ -1048,16 +1046,13 @@ func defaultResolve(
}

if let subscriptable = source as? KeySubscriptable {
let value = subscriptable[info.fieldName]
return value
return subscriptable[info.fieldName]
}
if let subscriptable = source as? [String: any Sendable] {
let value = subscriptable[info.fieldName]
return value
return subscriptable[info.fieldName]
}
if let subscriptable = source as? OrderedDictionary<String, any Sendable> {
let value = subscriptable[info.fieldName]
return value
return subscriptable[info.fieldName]
}

let mirror = Mirror(reflecting: source)
Expand Down
2 changes: 1 addition & 1 deletion Sources/GraphQL/GraphQLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct GraphQLRequest: Equatable, Codable, Sendable {
self.variables = variables
}

// To handle decoding with a default of variables = []
/// To handle decoding with a default of variables = []
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
query = try container.decode(String.self, forKey: .query)
Expand Down
6 changes: 2 additions & 4 deletions Sources/GraphQL/Language/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func createLexer(source: Source, noLocation: Bool = false) -> Lexer {
value: nil
)

let lexer = Lexer(
return Lexer(
source: source,
noLocation: noLocation,
lastToken: startOfFileToken,
Expand All @@ -25,8 +25,6 @@ func createLexer(source: Source, noLocation: Bool = false) -> Lexer {
lineStart: 0,
advance: advanceLexer
)

return lexer
}

func advanceLexer(lexer: Lexer) throws -> Token {
Expand Down Expand Up @@ -866,7 +864,7 @@ func readBlockString(
)
}

/**
/*
* blockStringValue(rawValue: String)
*
* Transcription of the algorithm specified in the [spec](http://spec.graphql.org/draft/#BlockStringValue())
Expand Down
7 changes: 3 additions & 4 deletions Sources/GraphQL/Language/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public func parse(
) throws -> Document {
do {
let lexer = createLexer(source: source, noLocation: noLocation)
let document = try parseDocument(lexer: lexer)
return document
return try parseDocument(lexer: lexer)
} catch let error as GraphQLError {
throw error
}
Expand Down Expand Up @@ -111,7 +110,7 @@ func peekDescription(lexer: Lexer) -> Bool {
return peek(lexer: lexer, kind: .string) || peek(lexer: lexer, kind: .blockstring)
}

/**
/*
* Description is optional StringValue
*/

Expand Down Expand Up @@ -586,7 +585,7 @@ func parseObjectField(lexer: Lexer, isConst: Bool) throws -> ObjectField {
)
}

/**
/*
* parseStringLiteral
*/

Expand Down
60 changes: 45 additions & 15 deletions Sources/GraphQL/Language/Printer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ private protocol Printable {
private let MAX_LINE_LENGTH = 80

extension Name: Printable {
var printed: String { value }
var printed: String {
value
}
}

extension Variable: Printable {
var printed: String { "$" + name }
var printed: String {
"$" + name
}
}

// MARK: - Document
Expand Down Expand Up @@ -108,7 +112,9 @@ extension Argument: Printable {
// MARK: - Fragments

extension FragmentSpread: Printable {
var printed: String { "..." + name + wrap(" ", join(directives, " ")) }
var printed: String {
"..." + name + wrap(" ", join(directives, " "))
}
}

extension InlineFragment: Printable {
Expand All @@ -132,11 +138,15 @@ extension FragmentDefinition: Printable {
// MARK: - Value

extension IntValue: Printable {
var printed: String { value }
var printed: String {
value
}
}

extension FloatValue: Printable {
var printed: String { value }
var printed: String {
value
}
}

extension StringValue: Printable {
Expand All @@ -146,15 +156,21 @@ extension StringValue: Printable {
}

extension BooleanValue: Printable {
var printed: String { value ? "true" : "false" }
var printed: String {
value ? "true" : "false"
}
}

extension NullValue: Printable {
var printed: String { "null" }
var printed: String {
"null"
}
}

extension EnumValue: Printable {
var printed: String { value }
var printed: String {
value
}
}

extension ListValue: Printable {
Expand Down Expand Up @@ -183,27 +199,37 @@ extension ObjectValue: Printable {
}

extension ObjectField: Printable {
var printed: String { name + ": " + value.printed }
var printed: String {
name + ": " + value.printed
}
}

// MARK: - Directive

extension Directive: Printable {
var printed: String { "@" + name + wrap("(", join(arguments, ", "), ")") }
var printed: String {
"@" + name + wrap("(", join(arguments, ", "), ")")
}
}

// MARK: - Type

extension NamedType: Printable {
var printed: String { name.printed }
var printed: String {
name.printed
}
}

extension ListType: Printable {
var printed: String { "[" + type.printed + "]" }
var printed: String {
"[" + type.printed + "]"
}
}

extension NonNullType: Printable {
var printed: String { type.printed + "!" }
var printed: String {
type.printed + "!"
}
}

// MARK: - Type System Definitions
Expand All @@ -216,7 +242,9 @@ extension SchemaDefinition: Printable {
}

extension OperationTypeDefinition: Printable {
var printed: String { operation.rawValue + ": " + type }
var printed: String {
operation.rawValue + ": " + type
}
}

extension ScalarTypeDefinition: Printable {
Expand Down Expand Up @@ -423,7 +451,9 @@ private func + (lhs: Printable, rhs: String) -> String {
}

extension String: Printable {
fileprivate var printed: String { self }
fileprivate var printed: String {
self
}
}

private extension Node {
Expand Down
9 changes: 1 addition & 8 deletions Sources/GraphQL/Language/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Note that since Source parsing is heavily UTF8 dependent, the body
* is converted into contiguous UTF8 bytes if necessary for optimal performance.
*/
public struct Source: Hashable, Sendable {
public struct Source: Hashable, Equatable, Sendable {
public let body: String
public let name: String

Expand All @@ -19,10 +19,3 @@ public struct Source: Hashable, Sendable {
self.name = name
}
}

extension Source: Equatable {
public static func == (lhs: Source, rhs: Source) -> Bool {
return lhs.body == rhs.body &&
lhs.name == rhs.name
}
}
2 changes: 1 addition & 1 deletion Sources/GraphQL/SwiftUtilities/IsNullish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Optional: OptionalProtocol {
}
}

/**
/*
* Returns true if a value is null, or nil.
*/
// func isNullish(_ value: Any?) -> Bool {
Expand Down
9 changes: 4 additions & 5 deletions Sources/GraphQL/Type/Definition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,17 @@ public final class GraphQLScalarType: Sendable {
self.parseLiteral = parseLiteral ?? defaultParseLiteral
}

// Serializes an internal value to include in a response.
/// Serializes an internal value to include in a response.
public func serialize(value: Any) throws -> Map {
return try serialize(value)
}

// Parses an externally provided value to use as an input.
/// Parses an externally provided value to use as an input.
public func parseValue(value: Map) throws -> Map {
return try parseValue(value)
}

// Parses an externally provided literal value to use as an input.
/// Parses an externally provided literal value to use as an input.
public func parseLiteral(valueAST: Value) throws -> Map {
return try parseLiteral(valueAST)
}
Expand Down Expand Up @@ -586,8 +586,7 @@ public final class GraphQLField: @unchecked Sendable {
self.astNode = astNode

_resolve = { source, args, context, info in
let result = try resolve(source, args, context, info)
return result
try resolve(source, args, context, info)
}
_subscribe = nil
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/GraphQL/Type/Introspection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ let __Type: GraphQLObjectType = {
}

let fieldMap = try type.getFields()
let fields = Array(fieldMap.values).sorted(by: { $0.name < $1.name })
return fields
return Array(fieldMap.values).sorted(by: { $0.name < $1.name })
}
),
"ofType": GraphQLField(type: __Type),
Expand Down Expand Up @@ -483,7 +482,7 @@ let __TypeKind = try! GraphQLEnumType(
]
)

/**
/*
* Note that these are GraphQLFieldDefinition and not GraphQLField,
* so the format for args is different.
*/
Expand Down
Loading