Skip to content

Commit 05f3483

Browse files
docs: Adds type/func documentation
Also removes unhelpful comments
1 parent 0950aa7 commit 05f3483

5 files changed

Lines changed: 10 additions & 19 deletions

File tree

Package.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,30 @@ let package = Package(
2525
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0"),
2626
],
2727
targets: [
28-
// Build plugin that discovers .graphql files and invokes the generator
2928
.plugin(
3029
name: "GraphQLGeneratorPlugin",
3130
capability: .buildTool(),
3231
dependencies: ["GraphQLGenerator"]
3332
),
34-
35-
// CLI executable that performs code generation
3633
.executableTarget(
3734
name: "GraphQLGenerator",
3835
dependencies: [
3936
"GraphQLGeneratorCore",
4037
.product(name: "ArgumentParser", package: "swift-argument-parser"),
4138
]
4239
),
43-
44-
// Core library with parsing and generation logic
4540
.target(
4641
name: "GraphQLGeneratorCore",
4742
dependencies: [
4843
.product(name: "GraphQL", package: "GraphQL"),
4944
]
5045
),
51-
52-
// Runtime library for generated code
5346
.target(
5447
name: "GraphQLGeneratorRuntime",
5548
dependencies: [
5649
.product(name: "GraphQL", package: "GraphQL"),
5750
]
5851
),
59-
60-
// Tests
6152
.testTarget(
6253
name: "GraphQLGeneratorCoreTests",
6354
dependencies: [

Sources/GraphQLGenerator/GraphQLGeneratorCommand.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,32 @@ struct GraphQLGeneratorCommand: ParsableCommand {
2626
print("Output directory: \(outputDirectory)")
2727
}
2828

29-
// Validate input files exist
3029
for filePath in schemaFiles {
3130
let fileURL = URL(fileURLWithPath: filePath)
3231
guard FileManager.default.fileExists(atPath: fileURL.path) else {
3332
throw ValidationError("Schema file not found: \(filePath)")
3433
}
3534
}
3635

37-
// Create output directory if it doesn't exist
3836
let outputURL = URL(fileURLWithPath: outputDirectory)
3937
try FileManager.default.createDirectory(at: outputURL, withIntermediateDirectories: true)
4038

4139
if verbose {
4240
print("Parsing schema files...")
4341
}
44-
45-
/// Read GraphQL schema files and combine them into a single schema
4642
var combinedSource = ""
4743
for filePath in schemaFiles {
4844
let url = URL(fileURLWithPath: filePath)
4945
let content = try String(contentsOf: url, encoding: .utf8)
5046
combinedSource += content + "\n"
5147
}
5248

53-
// Generate code
5449
let generator = CodeGenerator()
5550
let files = try generator.generate(source: combinedSource)
5651

57-
// Write generated files
5852
for (filename, content) in files {
5953
let fileURL = outputURL.appendingPathComponent(filename)
6054
try content.write(to: fileURL, atomically: true, encoding: .utf8)
61-
6255
if verbose {
6356
print("Generated: \(fileURL.path)")
6457
}

Sources/GraphQLGeneratorCore/Generator/CodeGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import GraphQL
55
package struct CodeGenerator {
66
package init() {}
77

8-
/// Generate all Swift files from the schema
8+
/// Generate all Swift files from the schema source string.
99
/// Returns a dictionary of filename -> file content
1010
package func generate(source: String) throws -> [String: String] {
1111
let schema = try GraphQL.buildSchema(source: source)

Sources/GraphQLGeneratorRuntime/GraphQLScalar.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import GraphQL
22
import OrderedCollections
33

4+
/// A type that can act as a GraphQL scalar value
45
public protocol GraphQLScalar: Sendable, Codable {
6+
/// Given an instance of this type, it defines how to convert the instance into a GraphQL JSON Map
57
static func serialize(this: Self) throws -> Map
8+
9+
/// Given any GraphQL JSON Map value, validate and conform it to a Map that represents this scalar
610
static func parseValue(map: Map) throws -> Map
11+
12+
/// Given a literal value, validate it and return the corresponding GraphQL JSON Map
713
static func parseLiteral(value: any Value) throws -> Map
814
}
915

10-
// Graphiti provides default serializations that the underlying type's Codability requirements, but they are very
11-
// inefficient. They typically pass through a full serialize/deserialize step on each call.
16+
// Graphiti provides default serializations that use the underlying type's Codability requirements, but they are
17+
// somewhat inefficient. They typically pass through a full serialize/deserialize step on each call.
1218
// Because of this, we have chosen not to vend defaults to force the user to implement more performant versions.
1319

1420
public extension GraphQLScalar {

Sources/GraphQLGeneratorRuntime/ResolverHelpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import GraphQL
22

3+
/// Cast an `any Sendable` to the input type, or throw a GraphQL error.
34
public func cast<T: Sendable>(_ anySendable: any Sendable, to _: T.Type) throws -> T {
45
guard let result = anySendable as? T else {
56
throw GraphQLError(

0 commit comments

Comments
 (0)