From c7e253bbf9dc3038980789e7bf41e321f862eeec Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Fri, 20 Jun 2025 14:23:53 -0600 Subject: [PATCH 1/4] ci: Add ci stage that checks wasm compilation. Add WASI badge to README. --- .github/workflows/wasm.yaml | 24 ++++++++++++++++++++++++ Package.resolved | 13 +++++++------ Package.swift | 5 ++++- README.md | 1 + 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/wasm.yaml diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml new file mode 100644 index 0000000..684b1c9 --- /dev/null +++ b/.github/workflows/wasm.yaml @@ -0,0 +1,24 @@ +name: wasm + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + # NOTE: swift tests won't compile due to usage + # of NIOPosix. But we can at least test that wasm compilation + # works, to prevent future breakages. + wasm: + name: Test wasm compilation + runs-on: ubuntu-latest + container: swift:6.1.0 + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: swiftwasm/setup-swiftwasm@v2 + with: + target: "wasm32-unknown-wasip1-threads" + - run: swift build --swift-sdk wasm32-unknown-wasip1-threads diff --git a/Package.resolved b/Package.resolved index 1465c14..49de830 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,4 +1,5 @@ { + "originHash" : "34f315fb9047f350b535493d2e79e60dfd40675b4bfc9f7a8e4b8d79bb3dd6c5", "pins" : [ { "identity" : "async-collections", @@ -39,10 +40,10 @@ { "identity" : "swift-nio", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio.git", + "location" : "https://github.com/PassiveLogic/swift-nio.git", "state" : { - "revision" : "34d486b01cd891297ac615e40d5999536a1e138d", - "version" : "2.83.0" + "branch" : "main", + "revision" : "8d2347a56b812083fe547e584de023f2668fe6fe" } }, { @@ -59,10 +60,10 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system.git", "state" : { - "revision" : "c8a44d836fe7913603e246acab7c528c2e780168", - "version" : "1.4.0" + "revision" : "61e4ca4b81b9e09e2ec863b00c340eb13497dac6", + "version" : "1.5.0" } } ], - "version" : 2 + "version" : 3 } diff --git a/Package.swift b/Package.swift index 71dc6ba..074c5e1 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,10 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"), .package(url: "https://github.com/adam-fowler/async-collections", from: "0.0.1"), - .package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"), + + // TODO: SM: Revert before merging. Temporarily using PL nio to test fix for NIOCore. + // .package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"), + .package(url: "https://github.com/PassiveLogic/swift-nio.git", branch: "main"), ], targets: [ .target( diff --git a/README.md b/README.md index 23fbb5f..193ef2e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://tldrlegal.com/license/mit-license) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FGraphQLSwift%2FDataLoader%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/GraphQLSwift/DataLoader) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FGraphQLSwift%2FDataLoader%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/GraphQLSwift/DataLoader) +[![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) 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. From 94ac8d60117e2d8e6a3f150610161378d2431a71 Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Mon, 23 Jun 2025 13:17:59 -0600 Subject: [PATCH 2/4] ci: Bump swift version from 5.8 to 5.10.0, which is the new minimum for the latest swift-nio dependency. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 074c5e1..1c9ebdc 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.8 +// swift-tools-version:5.10.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription From ed8b79523e8e1378545051e0f379cf6b1588e2ae Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Mon, 28 Jul 2025 09:08:28 -0600 Subject: [PATCH 3/4] chore: Update swift-nio minimum version to a version where NIOCore compiles for wasm. --- Package.resolved | 12 ++++++------ Package.swift | 5 +---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Package.resolved b/Package.resolved index 49de830..1c1dc60 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "34f315fb9047f350b535493d2e79e60dfd40675b4bfc9f7a8e4b8d79bb3dd6c5", + "originHash" : "34ed11cdeebef1b2864a6db79a150ffe000d97cca7e36c30e30939d14f609619", "pins" : [ { "identity" : "async-collections", @@ -40,10 +40,10 @@ { "identity" : "swift-nio", "kind" : "remoteSourceControl", - "location" : "https://github.com/PassiveLogic/swift-nio.git", + "location" : "https://github.com/apple/swift-nio.git", "state" : { - "branch" : "main", - "revision" : "8d2347a56b812083fe547e584de023f2668fe6fe" + "revision" : "a5fea865badcb1c993c85b0f0e8d05a4bd2270fb", + "version" : "2.85.0" } }, { @@ -60,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system.git", "state" : { - "revision" : "61e4ca4b81b9e09e2ec863b00c340eb13497dac6", - "version" : "1.5.0" + "revision" : "41daa93a5d229e1548ec86ab527ce4783ca84dda", + "version" : "1.6.0" } } ], diff --git a/Package.swift b/Package.swift index 1c9ebdc..67bd8e7 100644 --- a/Package.swift +++ b/Package.swift @@ -13,10 +13,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"), .package(url: "https://github.com/adam-fowler/async-collections", from: "0.0.1"), - - // TODO: SM: Revert before merging. Temporarily using PL nio to test fix for NIOCore. - // .package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"), - .package(url: "https://github.com/PassiveLogic/swift-nio.git", branch: "main"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.84.0"), ], targets: [ .target( From 0c379af1960e984fe62fff7e7ac9a822aa6b5f99 Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Thu, 12 Feb 2026 18:11:18 -0700 Subject: [PATCH 4/4] chore: Address lint --- Tests/AsyncDataLoaderTests/DataLoaderAbuseTests.swift | 3 +-- Tests/AsyncDataLoaderTests/DataLoaderTests.swift | 9 ++++----- Tests/DataLoaderTests/DataLoaderAbuseTests.swift | 3 +-- Tests/DataLoaderTests/DataLoaderAsyncTests.swift | 9 ++++----- Tests/DataLoaderTests/DataLoaderTests.swift | 11 +++++------ 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Tests/AsyncDataLoaderTests/DataLoaderAbuseTests.swift b/Tests/AsyncDataLoaderTests/DataLoaderAbuseTests.swift index d6b6b9b..4224a44 100644 --- a/Tests/AsyncDataLoaderTests/DataLoaderAbuseTests.swift +++ b/Tests/AsyncDataLoaderTests/DataLoaderAbuseTests.swift @@ -1,6 +1,5 @@ -import XCTest - @testable import AsyncDataLoader +import XCTest /// Provides descriptive error messages for API abuse class DataLoaderAbuseTests: XCTestCase { diff --git a/Tests/AsyncDataLoaderTests/DataLoaderTests.swift b/Tests/AsyncDataLoaderTests/DataLoaderTests.swift index 3a89376..daa52a5 100644 --- a/Tests/AsyncDataLoaderTests/DataLoaderTests.swift +++ b/Tests/AsyncDataLoaderTests/DataLoaderTests.swift @@ -1,6 +1,5 @@ -import XCTest - @testable import AsyncDataLoader +import XCTest let sleepConstant = UInt64(2_000_000) @@ -53,7 +52,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(empty.isEmpty) } - // Batches multiple requests + /// Batches multiple requests func testMultipleRequests() async throws { let loadCalls = Concurrent<[[Int]]>([]) @@ -178,7 +177,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(calls.map { $0.sorted() } == [[1]]) } - // Caches repeated requests + /// Caches repeated requests func testCachesRepeatedRequests() async throws { let loadCalls = Concurrent<[[String]]>([]) @@ -399,7 +398,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(calls2.map { $0.sorted() } == [["A", "B"], ["A", "B"]]) } - // Allows priming the cache + /// Allows priming the cache func testAllowsPrimingTheCache() async throws { let loadCalls = Concurrent<[[String]]>([]) diff --git a/Tests/DataLoaderTests/DataLoaderAbuseTests.swift b/Tests/DataLoaderTests/DataLoaderAbuseTests.swift index 4802b3f..561aa11 100644 --- a/Tests/DataLoaderTests/DataLoaderAbuseTests.swift +++ b/Tests/DataLoaderTests/DataLoaderAbuseTests.swift @@ -1,8 +1,7 @@ +@testable import DataLoader import NIOPosix import XCTest -@testable import DataLoader - /// Provides descriptive error messages for API abuse class DataLoaderAbuseTests: XCTestCase { func testFuntionWithNoValues() throws { diff --git a/Tests/DataLoaderTests/DataLoaderAsyncTests.swift b/Tests/DataLoaderTests/DataLoaderAsyncTests.swift index c96733b..19633a4 100644 --- a/Tests/DataLoaderTests/DataLoaderAsyncTests.swift +++ b/Tests/DataLoaderTests/DataLoaderAsyncTests.swift @@ -1,8 +1,7 @@ +@testable import DataLoader import NIOPosix import XCTest -@testable import DataLoader - #if compiler(>=5.5) && canImport(_Concurrency) @available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) @@ -70,7 +69,7 @@ import XCTest XCTAssertTrue(empty.isEmpty) } - // Batches multiple requests + /// Batches multiple requests func testMultipleRequests() async throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { @@ -96,8 +95,8 @@ import XCTest async let value1 = identityLoader.load(key: 1, on: eventLoopGroup) async let value2 = identityLoader.load(key: 2, on: eventLoopGroup) - /// Have to wait for a split second because Tasks may not be executed before this - /// statement + // Have to wait for a split second because Tasks may not be executed before this + // statement try await Task.sleep(nanoseconds: 500_000_000) XCTAssertNoThrow(try identityLoader.execute()) diff --git a/Tests/DataLoaderTests/DataLoaderTests.swift b/Tests/DataLoaderTests/DataLoaderTests.swift index 9e64539..8b7d648 100644 --- a/Tests/DataLoaderTests/DataLoaderTests.swift +++ b/Tests/DataLoaderTests/DataLoaderTests.swift @@ -1,9 +1,8 @@ +@testable import DataLoader import NIOCore import NIOPosix import XCTest -@testable import DataLoader - /// Primary API final class DataLoaderTests: XCTestCase { /// Builds a really really simple data loader' @@ -48,7 +47,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(empty.isEmpty) } - // Batches multiple requests + /// Batches multiple requests func testMultipleRequests() throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { @@ -144,7 +143,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(loadCalls == [[1]]) } - // Caches repeated requests + /// Caches repeated requests func testCachesRepeatedRequests() throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { @@ -270,7 +269,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(loadCalls == [["A", "B"], ["A", "B"]]) } - // Allows priming the cache + /// Allows priming the cache func testAllowsPrimingTheCache() throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { @@ -384,7 +383,7 @@ final class DataLoaderTests: XCTestCase { XCTAssertTrue(loadCalls == [["B"]]) } - // Caches repeated requests, even if initiated asyncronously + /// Caches repeated requests, even if initiated asyncronously func testCacheConcurrency() throws { let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer {