Skip to content

Commit ebdb549

Browse files
Merge pull request #7 from GraphQLSwift/refactor/formatting
refactor: Fixes formatting
2 parents 8b50c6b + 81fbabe commit ebdb549

6 files changed

Lines changed: 36 additions & 27 deletions

File tree

Examples/HelloWorldServer/Sources/HelloWorldServer/Resolvers.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import GraphQL
33
import GraphQLGeneratorRuntime
44

5-
// Must be created by user and named `GraphQLContext`.
5+
/// Must be created by user and named `GraphQLContext`.
66
class GraphQLContext: @unchecked Sendable {
77
// User can choose structure
88
var users: [String: User]
@@ -22,8 +22,8 @@ class GraphQLContext: @unchecked Sendable {
2222
}
2323
}
2424

25-
// Scalars must be represented by a Swift type of the same name in the GraphQLScalars namespace, conforming to
26-
// the GraphQLScalar protocol
25+
/// Scalars must be represented by a Swift type of the same name in the GraphQLScalars namespace, conforming to
26+
/// the GraphQLScalar protocol
2727
extension GraphQLScalars {
2828
struct EmailAddress: GraphQLScalar {
2929
let email: String
@@ -32,7 +32,7 @@ extension GraphQLScalars {
3232
self.email = email
3333
}
3434

35-
// Codability conformance. Required for usage in InputObject
35+
/// Codability conformance. Required for usage in InputObject
3636
init(from decoder: any Decoder) throws {
3737
email = try decoder.singleValueContainer().decode(String.self)
3838
}
@@ -41,7 +41,7 @@ extension GraphQLScalars {
4141
try email.encode(to: encoder)
4242
}
4343

44-
// Scalar conformance. Not necessary, but default methods are very inefficient.
44+
/// Scalar conformance. Not necessary, but default methods are very inefficient.
4545
static func serialize(this: Self) throws -> Map {
4646
return .string(this.email)
4747
}
@@ -67,7 +67,7 @@ extension GraphQLScalars {
6767
}
6868
}
6969

70-
// Now create types that conform to the expected protocols
70+
/// Now create types that conform to the expected protocols
7171
struct Resolvers: GraphQLGenerated.Resolvers {
7272
typealias Query = HelloWorldServer.Query
7373
typealias Mutation = HelloWorldServer.Mutation
@@ -82,7 +82,7 @@ struct User: GraphQLGenerated.User {
8282
let age: Int?
8383
let role: GraphQLGenerated.Role?
8484

85-
// Required implementations
85+
/// Required implementations
8686
func id(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> String {
8787
return id
8888
}
@@ -105,10 +105,10 @@ struct User: GraphQLGenerated.User {
105105
}
106106

107107
struct Contact: GraphQLGenerated.Contact {
108-
// User can choose structure
108+
/// User can choose structure
109109
let email: String
110110

111-
// Required implementations
111+
/// Required implementations
112112
func email(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> GraphQLScalars.EmailAddress {
113113
return .init(email: email)
114114
}
@@ -121,7 +121,7 @@ struct Post: GraphQLGenerated.Post {
121121
let content: String
122122
let authorId: String
123123

124-
// Required implementations
124+
/// Required implementations
125125
func id(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> String {
126126
return id
127127
}
@@ -140,7 +140,7 @@ struct Post: GraphQLGenerated.Post {
140140
}
141141

142142
struct Query: GraphQLGenerated.Query {
143-
// Required implementations
143+
/// Required implementations
144144
static func user(id: String, context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> (any GraphQLGenerated.User)? {
145145
return context.users[id]
146146
}
@@ -163,7 +163,7 @@ struct Query: GraphQLGenerated.Query {
163163
}
164164

165165
struct Mutation: GraphQLGenerated.Mutation {
166-
// Required implementations
166+
/// Required implementations
167167
static func upsertUser(userInfo: GraphQLGenerated.UserInfo, context: GraphQLContext, info _: GraphQLResolveInfo) -> any GraphQLGenerated.User {
168168
let user = User(
169169
id: userInfo.id,
@@ -178,7 +178,7 @@ struct Mutation: GraphQLGenerated.Mutation {
178178
}
179179

180180
struct Subscription: GraphQLGenerated.Subscription {
181-
// Required implementations
181+
/// Required implementations
182182
static func watchUser(id: String, context: GraphQLContext, info _: GraphQLResolveInfo) async throws -> AnyAsyncSequence<(any GraphQLGenerated.User)?> {
183183
return AsyncStream<(any GraphQLGenerated.User)?> { continuation in
184184
context.onTriggerWatch = { [weak context] in

Examples/HelloWorldServer/Tests/HelloWorldServerTests/HelloWorldServerTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import GraphQL
2-
import Testing
3-
42
@testable import HelloWorldServer
3+
import Testing
54

65
@Suite
76
struct HelloWorldServerTests {

Sources/GraphQLGeneratorCore/Utilities/SafeNameGenerator.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ struct DefensiveSafeNameGenerator: SafeNameGenerator {
115115
}
116116

117117
extension SafeNameGenerator where Self == DefensiveSafeNameGenerator {
118-
static var defensive: DefensiveSafeNameGenerator { DefensiveSafeNameGenerator() }
118+
static var defensive: DefensiveSafeNameGenerator {
119+
DefensiveSafeNameGenerator()
120+
}
119121
}
120122

121123
/// Returns a string sanitized to be usable as a Swift identifier, and tries to produce UpperCamelCase
@@ -129,8 +131,14 @@ struct IdiomaticSafeNameGenerator: SafeNameGenerator {
129131
/// The defensive strategy to use as fallback.
130132
var defensive: DefensiveSafeNameGenerator
131133

132-
func swiftTypeName(for documentedName: String) -> String { swiftName(for: documentedName, capitalize: true) }
133-
func swiftMemberName(for documentedName: String) -> String { swiftName(for: documentedName, capitalize: false) }
134+
func swiftTypeName(for documentedName: String) -> String {
135+
swiftName(for: documentedName, capitalize: true)
136+
}
137+
138+
func swiftMemberName(for documentedName: String) -> String {
139+
swiftName(for: documentedName, capitalize: false)
140+
}
141+
134142
private func swiftName(for documentedName: String, capitalize: Bool) -> String {
135143
if documentedName.isEmpty { return capitalize ? "_Empty_" : "_empty_" }
136144

@@ -302,5 +310,7 @@ struct IdiomaticSafeNameGenerator: SafeNameGenerator {
302310
}
303311

304312
extension SafeNameGenerator where Self == DefensiveSafeNameGenerator {
305-
static var idiomatic: IdiomaticSafeNameGenerator { IdiomaticSafeNameGenerator(defensive: .defensive) }
313+
static var idiomatic: IdiomaticSafeNameGenerator {
314+
IdiomaticSafeNameGenerator(defensive: .defensive)
315+
}
306316
}

Tests/GraphQLGeneratorCoreTests/IndentTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import Testing
33

44
@Suite
55
struct IndentTests {
6-
@Test func singleLine() async throws {
6+
@Test func singleLine() {
77
#expect("abc".indent(1, includeFirst: false) == "abc")
88
#expect("abc".indent(1, includeFirst: true) == " abc")
99
#expect("abc".indent(2, includeFirst: true) == " abc")
1010
}
1111

12-
@Test func multiLine() async throws {
12+
@Test func multiLine() {
1313
#expect(
1414
"""
1515
abc

Tests/GraphQLGeneratorCoreTests/SchemaGeneratorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Testing
66
struct SchemaGeneratorTests {
77
let generator = BuildGraphQLSchemaGenerator()
88

9-
@Test func generateSchema() async throws {
9+
@Test func generateSchema() throws {
1010
let bar = try GraphQLObjectType(
1111
name: "Bar",
1212
description: "bar",

Tests/GraphQLGeneratorCoreTests/TypeGeneratorTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct TypeGeneratorTests {
88

99
// MARK: - Enum Tests
1010

11-
@Test func generateEnum() async throws {
11+
@Test func generateEnum() throws {
1212
let actual = try generator.generateEnum(
1313
for: .init(
1414
name: "Foo",
@@ -137,7 +137,7 @@ struct TypeGeneratorTests {
137137
#expect(result == expected)
138138
}
139139

140-
@Test func generateInterfaceProtocol() async throws {
140+
@Test func generateInterfaceProtocol() throws {
141141
let interfaceA = try GraphQLInterfaceType(
142142
name: "A",
143143
description: "A"
@@ -184,7 +184,7 @@ struct TypeGeneratorTests {
184184
)
185185
}
186186

187-
@Test func generateTypeProtocol() async throws {
187+
@Test func generateTypeProtocol() throws {
188188
let interfaceA = try GraphQLInterfaceType(
189189
name: "A",
190190
description: "A"
@@ -248,7 +248,7 @@ struct TypeGeneratorTests {
248248
)
249249
}
250250

251-
@Test func generateRootTypeProtocolForQuery() async throws {
251+
@Test func generateRootTypeProtocolForQuery() throws {
252252
let bar = try GraphQLObjectType(
253253
name: "Bar",
254254
description: "bar",
@@ -329,7 +329,7 @@ struct TypeGeneratorTests {
329329
#expect(result == expected)
330330
}
331331

332-
@Test func generateRootTypeProtocolForSubscription() async throws {
332+
@Test func generateRootTypeProtocolForSubscription() throws {
333333
let subscription = try GraphQLObjectType(
334334
name: "Subscription",
335335
fields: [

0 commit comments

Comments
 (0)