Skip to content

Commit dbe2cef

Browse files
Merge pull request #26 from PassiveLogic/feat/add-swift-wasm-to-ci
feat: Add swift wasm CI targets to DataLoader
2 parents 6cbaae0 + 0c379af commit dbe2cef

File tree

9 files changed

+48
-27
lines changed

9 files changed

+48
-27
lines changed

.github/workflows/wasm.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: wasm
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
# NOTE: swift tests won't compile due to usage
12+
# of NIOPosix. But we can at least test that wasm compilation
13+
# works, to prevent future breakages.
14+
wasm:
15+
name: Test wasm compilation
16+
runs-on: ubuntu-latest
17+
container: swift:6.1.0
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- uses: swiftwasm/setup-swiftwasm@v2
22+
with:
23+
target: "wasm32-unknown-wasip1-threads"
24+
- run: swift build --swift-sdk wasm32-unknown-wasip1-threads

Package.resolved

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.10.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -13,7 +13,7 @@ let package = Package(
1313
dependencies: [
1414
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
1515
.package(url: "https://github.com/adam-fowler/async-collections", from: "0.0.1"),
16-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
16+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.84.0"),
1717
],
1818
targets: [
1919
.target(

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://tldrlegal.com/license/mit-license)
44
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FGraphQLSwift%2FDataLoader%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/GraphQLSwift/DataLoader)
55
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FGraphQLSwift%2FDataLoader%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/GraphQLSwift/DataLoader)
6+
[![WASI 0.1](https://github.com/GraphQLSwift/DataLoader/actions/workflows/wasm.yml/badge.svg?branch=main)](https://github.com/GraphQLSwift/DataLoader/actions/workflows/wasm.yml)
67

78
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
89

Tests/AsyncDataLoaderTests/DataLoaderAbuseTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import XCTest
2-
31
@testable import AsyncDataLoader
2+
import XCTest
43

54
/// Provides descriptive error messages for API abuse
65
class DataLoaderAbuseTests: XCTestCase {

Tests/AsyncDataLoaderTests/DataLoaderTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import XCTest
2-
31
@testable import AsyncDataLoader
2+
import XCTest
43

54
let sleepConstant = UInt64(2_000_000)
65

@@ -53,7 +52,7 @@ final class DataLoaderTests: XCTestCase {
5352
XCTAssertTrue(empty.isEmpty)
5453
}
5554

56-
// Batches multiple requests
55+
/// Batches multiple requests
5756
func testMultipleRequests() async throws {
5857
let loadCalls = Concurrent<[[Int]]>([])
5958

@@ -178,7 +177,7 @@ final class DataLoaderTests: XCTestCase {
178177
XCTAssertTrue(calls.map { $0.sorted() } == [[1]])
179178
}
180179

181-
// Caches repeated requests
180+
/// Caches repeated requests
182181
func testCachesRepeatedRequests() async throws {
183182
let loadCalls = Concurrent<[[String]]>([])
184183

@@ -399,7 +398,7 @@ final class DataLoaderTests: XCTestCase {
399398
XCTAssertTrue(calls2.map { $0.sorted() } == [["A", "B"], ["A", "B"]])
400399
}
401400

402-
// Allows priming the cache
401+
/// Allows priming the cache
403402
func testAllowsPrimingTheCache() async throws {
404403
let loadCalls = Concurrent<[[String]]>([])
405404

Tests/DataLoaderTests/DataLoaderAbuseTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
@testable import DataLoader
12
import NIOPosix
23
import XCTest
34

4-
@testable import DataLoader
5-
65
/// Provides descriptive error messages for API abuse
76
class DataLoaderAbuseTests: XCTestCase {
87
func testFuntionWithNoValues() throws {

Tests/DataLoaderTests/DataLoaderAsyncTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
@testable import DataLoader
12
import NIOPosix
23
import XCTest
34

4-
@testable import DataLoader
5-
65
#if compiler(>=5.5) && canImport(_Concurrency)
76

87
@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *)
@@ -70,7 +69,7 @@ import XCTest
7069
XCTAssertTrue(empty.isEmpty)
7170
}
7271

73-
// Batches multiple requests
72+
/// Batches multiple requests
7473
func testMultipleRequests() async throws {
7574
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
7675
defer {
@@ -96,8 +95,8 @@ import XCTest
9695
async let value1 = identityLoader.load(key: 1, on: eventLoopGroup)
9796
async let value2 = identityLoader.load(key: 2, on: eventLoopGroup)
9897

99-
/// Have to wait for a split second because Tasks may not be executed before this
100-
/// statement
98+
// Have to wait for a split second because Tasks may not be executed before this
99+
// statement
101100
try await Task.sleep(nanoseconds: 500_000_000)
102101

103102
XCTAssertNoThrow(try identityLoader.execute())

Tests/DataLoaderTests/DataLoaderTests.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
@testable import DataLoader
12
import NIOCore
23
import NIOPosix
34
import XCTest
45

5-
@testable import DataLoader
6-
76
/// Primary API
87
final class DataLoaderTests: XCTestCase {
98
/// Builds a really really simple data loader'
@@ -48,7 +47,7 @@ final class DataLoaderTests: XCTestCase {
4847
XCTAssertTrue(empty.isEmpty)
4948
}
5049

51-
// Batches multiple requests
50+
/// Batches multiple requests
5251
func testMultipleRequests() throws {
5352
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
5453
defer {
@@ -144,7 +143,7 @@ final class DataLoaderTests: XCTestCase {
144143
XCTAssertTrue(loadCalls == [[1]])
145144
}
146145

147-
// Caches repeated requests
146+
/// Caches repeated requests
148147
func testCachesRepeatedRequests() throws {
149148
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
150149
defer {
@@ -270,7 +269,7 @@ final class DataLoaderTests: XCTestCase {
270269
XCTAssertTrue(loadCalls == [["A", "B"], ["A", "B"]])
271270
}
272271

273-
// Allows priming the cache
272+
/// Allows priming the cache
274273
func testAllowsPrimingTheCache() throws {
275274
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
276275
defer {
@@ -384,7 +383,7 @@ final class DataLoaderTests: XCTestCase {
384383
XCTAssertTrue(loadCalls == [["B"]])
385384
}
386385

387-
// Caches repeated requests, even if initiated asyncronously
386+
/// Caches repeated requests, even if initiated asyncronously
388387
func testCacheConcurrency() throws {
389388
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
390389
defer {

0 commit comments

Comments
 (0)