Skip to content

Commit 74b6edc

Browse files
Merge pull request #9 from GraphQLSwift/refactor/swift-format
Converts to swift-format
2 parents 90c61c9 + 14e441e commit 74b6edc

25 files changed

Lines changed: 1655 additions & 906 deletions

File tree

.swift-format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"lineBreakBeforeEachArgument": true
7+
}

Examples/HelloWorldServer/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55
let package = Package(
66
name: "HelloWorldServer",
77
platforms: [
8-
.macOS(.v13),
8+
.macOS(.v13)
99
],
1010
dependencies: [
1111
.package(name: "graphql-generator", path: "../.."),
@@ -20,7 +20,7 @@ let package = Package(
2020
.product(name: "GraphQLGeneratorRuntime", package: "graphql-generator"),
2121
],
2222
plugins: [
23-
.plugin(name: "GraphQLGeneratorPlugin", package: "graphql-generator"),
23+
.plugin(name: "GraphQLGeneratorPlugin", package: "graphql-generator")
2424
]
2525
),
2626
.testTarget(

Examples/HelloWorldServer/Sources/HelloWorldServer/Resolvers.swift

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ extension GraphQLScalars {
5252
case .string:
5353
return map
5454
default:
55-
throw GraphQLError(message: "EmailAddress cannot represent non-string value: \(map)")
55+
throw GraphQLError(
56+
message: "EmailAddress cannot represent non-string value: \(map)"
57+
)
5658
}
5759
}
5860

@@ -89,7 +91,9 @@ struct User: GraphQLGenerated.User {
8991
// Can't use @graphQLResolver macro because we must convert from String to GraphQLScalars.EmailAddress
9092

9193
let email: String
92-
func email(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> GraphQLScalars.EmailAddress {
94+
func email(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws
95+
-> GraphQLScalars.EmailAddress
96+
{
9397
return .init(email: email)
9498
}
9599
}
@@ -99,7 +103,10 @@ struct Contact: GraphQLGenerated.Contact {
99103

100104
/// Required implementations
101105
let email: String
102-
func email(context _: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> GraphQLScalars.EmailAddress {
106+
func email(
107+
context _: GraphQLContext,
108+
info _: GraphQL.GraphQLResolveInfo
109+
) async throws -> GraphQLScalars.EmailAddress {
103110
return .init(email: email)
104111
}
105112
}
@@ -113,37 +120,63 @@ struct Post: GraphQLGenerated.Post {
113120

114121
/// Required implementations
115122
let authorId: String
116-
func author(context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> any GraphQLGenerated.User {
123+
func author(
124+
context: GraphQLContext,
125+
info _: GraphQL.GraphQLResolveInfo
126+
) async throws -> any GraphQLGenerated.User {
117127
return context.users[authorId]!
118128
}
119129
}
120130

121131
struct Query: GraphQLGenerated.Query {
122132
/// Required implementations
123-
static func user(id: String, context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> (any GraphQLGenerated.User)? {
133+
static func user(
134+
id: String,
135+
context: GraphQLContext,
136+
info _: GraphQL.GraphQLResolveInfo
137+
) async throws -> (any GraphQLGenerated.User)? {
124138
return context.users[id]
125139
}
126140

127-
static func users(context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> [any GraphQLGenerated.User] {
141+
static func users(
142+
context: GraphQLContext,
143+
info _: GraphQL.GraphQLResolveInfo
144+
) async throws -> [any GraphQLGenerated.User] {
128145
return context.users.values.map { $0 as any GraphQLGenerated.User }
129146
}
130147

131-
static func post(id: String, context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> (any GraphQLGenerated.Post)? {
148+
static func post(
149+
id: String,
150+
context: GraphQLContext,
151+
info _: GraphQL.GraphQLResolveInfo
152+
) async throws -> (any GraphQLGenerated.Post)? {
132153
return context.posts[id]
133154
}
134155

135-
static func posts(limit _: Int?, context: GraphQLContext, info _: GraphQL.GraphQLResolveInfo) async throws -> [any GraphQLGenerated.Post] {
156+
static func posts(
157+
limit _: Int?,
158+
context: GraphQLContext,
159+
info _: GraphQL.GraphQLResolveInfo
160+
) async throws -> [any GraphQLGenerated.Post] {
136161
return context.posts.values.map { $0 as any GraphQLGenerated.Post }
137162
}
138163

139-
static func userOrPost(id: String, context: GraphQLContext, info _: GraphQLResolveInfo) async throws -> (any GraphQLGenerated.UserOrPost)? {
164+
static func userOrPost(
165+
id: String,
166+
context: GraphQLContext,
167+
info _: GraphQLResolveInfo
168+
) async throws -> (any GraphQLGenerated.UserOrPost)? {
140169
return context.users[id] ?? context.posts[id]
141170
}
142171
}
143172

144173
struct Mutation: GraphQLGenerated.Mutation {
145174
/// Required implementations
146-
static func upsertUser(userInfo: GraphQLGenerated.UserInfo, context: GraphQLContext, info _: GraphQLResolveInfo) -> any GraphQLGenerated.User {
175+
static func upsertUser(
176+
userInfo: GraphQLGenerated.UserInfo,
177+
context: GraphQLContext,
178+
info _: GraphQLResolveInfo
179+
) -> any GraphQLGenerated.User {
147180
let user = User(
148181
id: userInfo.id,
149182
name: userInfo.name,
@@ -158,7 +191,11 @@ struct Mutation: GraphQLGenerated.Mutation {
158191

159192
struct Subscription: GraphQLGenerated.Subscription {
160193
/// Required implementations
161-
static func watchUser(id: String, context: GraphQLContext, info _: GraphQLResolveInfo) async throws -> AnyAsyncSequence<(any GraphQLGenerated.User)?> {
194+
static func watchUser(
195+
id: String,
196+
context: GraphQLContext,
197+
info _: GraphQLResolveInfo
198+
) async throws -> AnyAsyncSequence<(any GraphQLGenerated.User)?> {
162199
return AsyncStream<(any GraphQLGenerated.User)?> { continuation in
163200
context.onTriggerWatch = { [weak context] in
164201
continuation.yield(context?.users[id])
Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import GraphQL
2-
@testable import HelloWorldServer
32
import Testing
43

4+
@testable import HelloWorldServer
5+
56
@Suite
67
struct HelloWorldServerTests {
78
@Test func query() async throws {
89
let schema = try buildGraphQLSchema(resolvers: Resolvers.self)
910
let context = GraphQLContext(
10-
users: ["1": .init(id: "1", name: "John", age: 18, role: .user, email: "john@example.com")],
11+
users: [
12+
"1": .init(id: "1", name: "John", age: 18, role: .user, email: "john@example.com")
13+
],
1114
posts: ["1": .init(id: "1", title: "Foo", content: "bar", authorId: "1")]
1215
)
1316
let actual = try await graphql(
1417
schema: schema,
1518
request: """
16-
{
17-
posts {
18-
id
19-
title
20-
content
21-
author {
19+
{
20+
posts {
2221
id
23-
name
24-
email
25-
age
26-
role
22+
title
23+
content
24+
author {
25+
id
26+
name
27+
email
28+
age
29+
role
30+
}
2731
}
2832
}
29-
}
30-
""",
33+
""",
3134
context: context
3235
)
3336
let expected = GraphQLResult(
@@ -44,8 +47,8 @@ struct HelloWorldServerTests {
4447
"age": 18,
4548
"role": "USER",
4649
],
47-
],
48-
],
50+
]
51+
]
4952
]
5053
)
5154
#expect(actual == expected)
@@ -60,16 +63,16 @@ struct HelloWorldServerTests {
6063
let actual = try await graphql(
6164
schema: schema,
6265
request: """
63-
mutation {
64-
upsertUser(userInfo: {id: "2", name: "Jane", email: "jane@example.com"}) {
65-
id
66-
name
67-
email
68-
age
69-
role
66+
mutation {
67+
upsertUser(userInfo: {id: "2", name: "Jane", email: "jane@example.com"}) {
68+
id
69+
name
70+
email
71+
age
72+
role
73+
}
7074
}
71-
}
72-
""",
75+
""",
7376
context: context
7477
)
7578
let expected = GraphQLResult(
@@ -80,7 +83,7 @@ struct HelloWorldServerTests {
8083
"email": "jane@example.com",
8184
"age": nil,
8285
"role": "USER",
83-
],
86+
]
8487
]
8588
)
8689
#expect(actual == expected)
@@ -89,55 +92,59 @@ struct HelloWorldServerTests {
8992
@Test func subscription() async throws {
9093
let schema = try buildGraphQLSchema(resolvers: Resolvers.self)
9194
let context = GraphQLContext(
92-
users: ["1": .init(id: "1", name: "John", age: 18, role: .user, email: "john@example.com")],
95+
users: [
96+
"1": .init(id: "1", name: "John", age: 18, role: .user, email: "john@example.com")
97+
],
9398
posts: [:]
9499
)
95100
let stream = try await graphqlSubscribe(
96101
schema: schema,
97102
request: """
98-
subscription {
99-
watchUser(id: "1") {
100-
id
101-
name
102-
email
103-
age
104-
role
103+
subscription {
104+
watchUser(id: "1") {
105+
id
106+
name
107+
email
108+
age
109+
role
110+
}
105111
}
106-
}
107-
""",
112+
""",
108113
context: context
109114
).get()
110115

111116
var iterator = stream.makeAsyncIterator()
112117

113118
context.triggerWatch()
114119
#expect(
115-
try await iterator.next() == GraphQLResult(
116-
data: [
117-
"watchUser": [
118-
"id": "1",
119-
"name": "John",
120-
"email": "john@example.com",
121-
"age": 18,
122-
"role": "USER",
123-
],
124-
]
125-
)
120+
try await iterator.next()
121+
== GraphQLResult(
122+
data: [
123+
"watchUser": [
124+
"id": "1",
125+
"name": "John",
126+
"email": "john@example.com",
127+
"age": 18,
128+
"role": "USER",
129+
]
130+
]
131+
)
126132
)
127133

128134
context.triggerWatch()
129135
#expect(
130-
try await iterator.next() == GraphQLResult(
131-
data: [
132-
"watchUser": [
133-
"id": "1",
134-
"name": "John",
135-
"email": "john@example.com",
136-
"age": 18,
137-
"role": "USER",
138-
],
139-
]
140-
)
136+
try await iterator.next()
137+
== GraphQLResult(
138+
data: [
139+
"watchUser": [
140+
"id": "1",
141+
"name": "John",
142+
"email": "john@example.com",
143+
"age": 18,
144+
"role": "USER",
145+
]
146+
]
147+
)
141148
)
142149
}
143150
}

Examples/StarWars/Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import PackageDescription
55
let package = Package(
66
name: "StarWars",
77
platforms: [
8-
.macOS(.v13),
8+
.macOS(.v13)
99
],
1010
products: [
1111
.library(
1212
name: "StarWars",
1313
targets: ["StarWars"]
14-
),
14+
)
1515
],
1616
dependencies: [
1717
.package(name: "graphql-generator", path: "../.."),
@@ -30,13 +30,13 @@ let package = Package(
3030
.product(name: "GraphQLGeneratorRuntime", package: "graphql-generator"),
3131
],
3232
plugins: [
33-
.plugin(name: "GraphQLGeneratorPlugin", package: "graphql-generator"),
33+
.plugin(name: "GraphQLGeneratorPlugin", package: "graphql-generator")
3434
]
3535
),
3636
.testTarget(
3737
name: "StarWarsTests",
3838
dependencies: [
39-
"StarWars",
39+
"StarWars"
4040
]
4141
),
4242
]

0 commit comments

Comments
 (0)