Skip to content

Commit 7fa1bb6

Browse files
Merge pull request #9 from GraphQLSwift/refactor/swift-format
Converts to swift-format
2 parents 753015a + 10e5195 commit 7fa1bb6

17 files changed

Lines changed: 325 additions & 197 deletions

.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/HelloWorld/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: "HelloWorld",
77
platforms: [
8-
.macOS(.v13),
8+
.macOS(.v13)
99
],
1010
dependencies: [
1111
.package(name: "graphql-vapor", path: "../../"),
@@ -22,6 +22,6 @@ let package = Package(
2222
.product(name: "GraphQL", package: "GraphQL"),
2323
.product(name: "Vapor", package: "vapor"),
2424
]
25-
),
25+
)
2626
]
2727
)

Examples/HelloWorld/Sources/HelloWorld/HelloWorld.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct HelloWorld {
1919
resolve: { _, _, _, _ in
2020
"World"
2121
}
22-
),
22+
)
2323
]
2424
),
2525
subscription: GraphQLObjectType(
@@ -34,11 +34,14 @@ struct HelloWorld {
3434
subscribe: { _, _, _, _ in
3535
let clock = ContinuousClock()
3636
let start = clock.now
37-
return AsyncTimerSequence(interval: .seconds(3), clock: ContinuousClock()).map { instant in
37+
return AsyncTimerSequence(
38+
interval: .seconds(3),
39+
clock: ContinuousClock()
40+
).map { instant in
3841
"World at \(start.duration(to: instant))"
3942
}
4043
}
41-
),
44+
)
4245
]
4346
)
4447
)

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import PackageDescription
55
let package = Package(
66
name: "GraphQLVapor",
77
platforms: [
8-
.macOS(.v13),
8+
.macOS(.v13)
99
],
1010
products: [
1111
.library(
1212
name: "GraphQLVapor",
1313
targets: ["GraphQLVapor"]
14-
),
14+
)
1515
],
1616
dependencies: [
1717
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "4.0.0"),

Sources/GraphQLVapor/Content/GraphQLJSONEncoder+ContentEncoder.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@ import GraphQL
22
import Vapor
33

44
extension GraphQLJSONEncoder: @retroactive ContentEncoder {
5-
public func encode<E: Encodable>(_ encodable: E, to body: inout NIOCore.ByteBuffer, headers: inout NIOHTTP1.HTTPHeaders) throws {
5+
public func encode<E: Encodable>(
6+
_ encodable: E,
7+
to body: inout NIOCore.ByteBuffer,
8+
headers: inout NIOHTTP1.HTTPHeaders
9+
) throws {
610
try encode(encodable, to: &body, headers: &headers, userInfo: [:])
711
}
812

9-
public func encode<E: Encodable>(_ encodable: E, to body: inout ByteBuffer, headers: inout HTTPHeaders, userInfo: [CodingUserInfoKey: Sendable]) throws {
13+
public func encode<E: Encodable>(
14+
_ encodable: E,
15+
to body: inout ByteBuffer,
16+
headers: inout HTTPHeaders,
17+
userInfo: [CodingUserInfoKey: Sendable]
18+
) throws {
1019
headers.contentType = .jsonGraphQL
1120

12-
if !userInfo.isEmpty { // Changing a coder's userInfo is a thread-unsafe mutation, operate on a copy
21+
if !userInfo.isEmpty { // Changing a coder's userInfo is a thread-unsafe mutation, operate on a copy
1322
let encoder = GraphQLJSONEncoder.custom(
1423
dates: dateEncodingStrategy,
1524
data: dataEncodingStrategy,
1625
keys: keyEncodingStrategy,
1726
format: outputFormatting,
1827
floats: nonConformingFloatEncodingStrategy
19-
) // don't use userInfo parameter of `JSONEncoder.custom()` until Swift 6.2 is required
28+
) // don't use userInfo parameter of `JSONEncoder.custom()` until Swift 6.2 is required
2029
encoder.userInfo = self.userInfo.merging(userInfo) { $1 }
2130
try body.writeBytes(encoder.encode(encodable))
2231
} else {
@@ -25,7 +34,7 @@ extension GraphQLJSONEncoder: @retroactive ContentEncoder {
2534
}
2635
}
2736

28-
public extension GraphQLJSONEncoder {
37+
extension GraphQLJSONEncoder {
2938
/// Convenience for creating a customized ``Foundation/GraphQLJSONEncoder``.
3039
///
3140
/// let encoder: GraphQLJSONEncoder = .custom(dates: .millisecondsSince1970)
@@ -38,7 +47,7 @@ public extension GraphQLJSONEncoder {
3847
/// - floats: Non-conforming float encoding strategy.
3948
/// - userInfo: Coder userInfo.
4049
/// - Returns: Newly created ``Foundation/JSONEncoder``.
41-
static func custom(
50+
public static func custom(
4251
dates dateStrategy: GraphQLJSONEncoder.DateEncodingStrategy? = nil,
4352
data dataStrategy: GraphQLJSONEncoder.DataEncodingStrategy? = nil,
4453
keys keyStrategy: GraphQLJSONEncoder.KeyEncodingStrategy? = nil,
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import Vapor
22

3-
public extension HTTPMediaType {
4-
static let jsonGraphQL = HTTPMediaType(type: "application", subType: "graphql-response+json", parameters: ["charset": "utf-8"])
3+
extension HTTPMediaType {
4+
public static let jsonGraphQL = HTTPMediaType(
5+
type: "application",
6+
subType: "graphql-response+json",
7+
parameters: ["charset": "utf-8"]
8+
)
59
}

Sources/GraphQLVapor/GraphQLConfig.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public struct GraphQLConfig<
8585
/// authorization using the `payload` field of the `connection_init` message.
8686
/// Throw from this closure to indicate that authorization has failed.
8787
public init(
88-
onWebSocketInit: @Sendable @escaping (WebSocketInit, Request) async throws -> WebSocketInitResult = { (_: EmptyWebSocketInit, _: Request) in }
88+
onWebSocketInit:
89+
@Sendable @escaping (WebSocketInit, Request) async throws -> WebSocketInitResult = {
90+
(_: EmptyWebSocketInit, _: Request) in
91+
}
8992
) {
9093
self.onWebSocketInit = onWebSocketInit
9194
}

Sources/GraphQLVapor/GraphQLHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ struct GraphQLHandler<
99
let schema: GraphQLSchema
1010
let rootValue: any Sendable
1111
let config: GraphQLConfig<WebSocketInit, WebSocketInitResult>
12-
let computeContext: @Sendable (GraphQLContextComputationInputs<WebSocketInitResult>) async throws -> Context
12+
let computeContext:
13+
@Sendable (GraphQLContextComputationInputs<WebSocketInitResult>) async throws -> Context
1314
}

Sources/GraphQLVapor/HTTP/GraphQLHandler+HTTP.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ extension GraphQLHandler {
7373
// This indicates a request parsing error
7474
return GraphQLResult(data: nil, errors: [error])
7575
} catch {
76-
return GraphQLResult(data: nil, errors: [GraphQLError(message: error.localizedDescription)])
76+
return GraphQLResult(
77+
data: nil,
78+
errors: [GraphQLError(message: error.localizedDescription)]
79+
)
7780
}
7881
return result
7982
}

Sources/GraphQLVapor/IDEs/GraphiQLHandler.swift

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -14,89 +14,89 @@ enum GraphiQLHandler {
1414
graphiQLFetcherArgs += ", subscriptionUrl: '\(subscriptionUrl)'"
1515
}
1616
return """
17-
<!doctype html>
18-
<html lang="en">
19-
<head>
20-
<meta charset="UTF-8" />
21-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
22-
<title>GraphiQL 5 with React 19 and GraphiQL Explorer</title>
23-
<style>
24-
body {
25-
margin: 0;
26-
}
17+
<!doctype html>
18+
<html lang="en">
19+
<head>
20+
<meta charset="UTF-8" />
21+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
22+
<title>GraphiQL 5 with React 19 and GraphiQL Explorer</title>
23+
<style>
24+
body {
25+
margin: 0;
26+
}
2727
28-
#graphiql {
29-
height: 100dvh;
30-
}
28+
#graphiql {
29+
height: 100dvh;
30+
}
3131
32-
.loading {
33-
height: 100%;
34-
display: flex;
35-
align-items: center;
36-
justify-content: center;
37-
font-size: 4rem;
38-
}
39-
</style>
40-
<link rel="stylesheet" href="https://esm.sh/graphiql/dist/style.css" />
41-
<link
42-
rel="stylesheet"
43-
href="https://esm.sh/@graphiql/plugin-explorer/dist/style.css"
44-
/>
45-
<!--
46-
* Note:
47-
* The ?standalone flag bundles the module along with all of its `dependencies`, excluding `peerDependencies`, into a single JavaScript file.
48-
* `@emotion/is-prop-valid` is a shim to remove the console error ` module "@emotion /is-prop-valid" not found`. Upstream issue: https://github.com/motiondivision/motion/issues/3126
49-
-->
50-
<script type="importmap">
51-
{
52-
"imports": {
53-
"react": "https://esm.sh/react@19.1.0",
54-
"react/": "https://esm.sh/react@19.1.0/",
32+
.loading {
33+
height: 100%;
34+
display: flex;
35+
align-items: center;
36+
justify-content: center;
37+
font-size: 4rem;
38+
}
39+
</style>
40+
<link rel="stylesheet" href="https://esm.sh/graphiql/dist/style.css" />
41+
<link
42+
rel="stylesheet"
43+
href="https://esm.sh/@graphiql/plugin-explorer/dist/style.css"
44+
/>
45+
<!--
46+
* Note:
47+
* The ?standalone flag bundles the module along with all of its `dependencies`, excluding `peerDependencies`, into a single JavaScript file.
48+
* `@emotion/is-prop-valid` is a shim to remove the console error ` module "@emotion /is-prop-valid" not found`. Upstream issue: https://github.com/motiondivision/motion/issues/3126
49+
-->
50+
<script type="importmap">
51+
{
52+
"imports": {
53+
"react": "https://esm.sh/react@19.1.0",
54+
"react/": "https://esm.sh/react@19.1.0/",
5555
56-
"react-dom": "https://esm.sh/react-dom@19.1.0",
57-
"react-dom/": "https://esm.sh/react-dom@19.1.0/",
56+
"react-dom": "https://esm.sh/react-dom@19.1.0",
57+
"react-dom/": "https://esm.sh/react-dom@19.1.0/",
5858
59-
"graphiql": "https://esm.sh/graphiql?standalone&external=react,react-dom,@graphiql/react,graphql",
60-
"graphiql/": "https://esm.sh/graphiql/",
61-
"@graphiql/plugin-explorer": "https://esm.sh/@graphiql/plugin-explorer?standalone&external=react,@graphiql/react,graphql",
62-
"@graphiql/react": "https://esm.sh/@graphiql/react?standalone&external=react,react-dom,graphql,@graphiql/toolkit,@emotion/is-prop-valid",
59+
"graphiql": "https://esm.sh/graphiql?standalone&external=react,react-dom,@graphiql/react,graphql",
60+
"graphiql/": "https://esm.sh/graphiql/",
61+
"@graphiql/plugin-explorer": "https://esm.sh/@graphiql/plugin-explorer?standalone&external=react,@graphiql/react,graphql",
62+
"@graphiql/react": "https://esm.sh/@graphiql/react?standalone&external=react,react-dom,graphql,@graphiql/toolkit,@emotion/is-prop-valid",
6363
64-
"@graphiql/toolkit": "https://esm.sh/@graphiql/toolkit?standalone&external=graphql",
65-
"graphql": "https://esm.sh/graphql@16.11.0",
66-
"@emotion/is-prop-valid": "data:text/javascript,"
67-
}
68-
}
69-
</script>
70-
<script type="module">
71-
import React from 'react';
72-
import ReactDOM from 'react-dom/client';
73-
import { GraphiQL, HISTORY_PLUGIN } from 'graphiql';
74-
import { createGraphiQLFetcher } from '@graphiql/toolkit';
75-
import { explorerPlugin } from '@graphiql/plugin-explorer';
76-
import 'graphiql/setup-workers/esm.sh';
64+
"@graphiql/toolkit": "https://esm.sh/@graphiql/toolkit?standalone&external=graphql",
65+
"graphql": "https://esm.sh/graphql@16.11.0",
66+
"@emotion/is-prop-valid": "data:text/javascript,"
67+
}
68+
}
69+
</script>
70+
<script type="module">
71+
import React from 'react';
72+
import ReactDOM from 'react-dom/client';
73+
import { GraphiQL, HISTORY_PLUGIN } from 'graphiql';
74+
import { createGraphiQLFetcher } from '@graphiql/toolkit';
75+
import { explorerPlugin } from '@graphiql/plugin-explorer';
76+
import 'graphiql/setup-workers/esm.sh';
7777
78-
const fetcher = createGraphiQLFetcher({\(graphiQLFetcherArgs)});
79-
const plugins = [HISTORY_PLUGIN, explorerPlugin()];
78+
const fetcher = createGraphiQLFetcher({\(graphiQLFetcherArgs)});
79+
const plugins = [HISTORY_PLUGIN, explorerPlugin()];
8080
81-
function App() {
82-
return React.createElement(GraphiQL, {
83-
fetcher,
84-
plugins,
85-
defaultEditorToolsVisibility: true,
86-
});
87-
}
81+
function App() {
82+
return React.createElement(GraphiQL, {
83+
fetcher,
84+
plugins,
85+
defaultEditorToolsVisibility: true,
86+
});
87+
}
8888
89-
const container = document.getElementById('graphiql');
90-
const root = ReactDOM.createRoot(container);
91-
root.render(React.createElement(App));
92-
</script>
93-
</head>
94-
<body>
95-
<div id="graphiql">
96-
<div class="loading">Loading…</div>
97-
</div>
98-
</body>
99-
</html>
100-
"""
89+
const container = document.getElementById('graphiql');
90+
const root = ReactDOM.createRoot(container);
91+
root.render(React.createElement(App));
92+
</script>
93+
</head>
94+
<body>
95+
<div id="graphiql">
96+
<div class="loading">Loading…</div>
97+
</div>
98+
</body>
99+
</html>
100+
"""
101101
}
102102
}

0 commit comments

Comments
 (0)