Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumps minimum version to Swift 5.8 #146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
swift: ["5.7", "5.8", "5.9", "5.10"]
swift: ["5.8", "5.9", "5.10"]
steps:
- uses: swift-actions/setup-swift@v2
with:
Expand All @@ -70,17 +70,3 @@ jobs:
- name: Test
run: swift test --parallel

# Swift versions older than 5.7 don't have builds for ubuntu 22.04. https://www.swift.org/download/
backcompat-ubuntu-20_04:
name: Test Swift ${{ matrix.swift }} on Ubuntu 20.04
runs-on: ubuntu-20.04
strategy:
matrix:
swift: ["5.4", "5.5", "5.6"]
steps:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v3
- name: Test
run: swift test --parallel
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
"repositoryURL": "https://github.com/apple/swift-collections",
"state": {
"branch": null,
"revision": "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version": "1.1.0"
"revision": "671108c96644956dddcd89dd59c203dcdb36cec7",
"version": "1.1.4"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version": "2.64.0"
"revision": "914081701062b11e3bb9e21accc379822621995e",
"version": "2.76.1"
}
},
{
"package": "swift-system",
"repositoryURL": "https://github.com/apple/swift-system.git",
"state": {
"branch": null,
"revision": "025bcb1165deab2e20d4eaba79967ce73013f496",
"version": "1.2.1"
"revision": "c8a44d836fe7913603e246acab7c528c2e780168",
"version": "1.4.0"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.4
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ one that you've created yourself.

For a progressive walkthrough, see the [Usage Guide](UsageGuide.md). The [Star Wars API](Tests/GraphitiTests/StarWarsAPI/StarWarsAPI.swift) provides a fairly complete example.

## Support

This package supports Swift versions in [alignment with Swift NIO](https://github.com/apple/swift-nio?tab=readme-ov-file#swift-versions).

## Contributing

This repo uses [SwiftFormat](https://github.com/nicklockwood/SwiftFormat), and includes lint checks to enforce these formatting standards.
Expand Down
146 changes: 71 additions & 75 deletions Sources/Graphiti/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,82 +80,78 @@ public extension API {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)

public extension API {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func execute(
request: String,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
variables: [String: Map] = [:],
operationName: String? = nil,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> GraphQLResult {
return try await schema.execute(
request: request,
resolver: resolver,
context: context,
eventLoopGroup: eventLoopGroup,
variables: variables,
operationName: operationName,
validationRules: validationRules
).get()
}

@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func execute(
request: GraphQLRequest,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> GraphQLResult {
return try await execute(
request: request.query,
context: context,
on: eventLoopGroup,
variables: request.variables,
operationName: request.operationName,
validationRules: validationRules
)
}
public extension API {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func execute(
request: String,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
variables: [String: Map] = [:],
operationName: String? = nil,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> GraphQLResult {
return try await schema.execute(
request: request,
resolver: resolver,
context: context,
eventLoopGroup: eventLoopGroup,
variables: variables,
operationName: operationName,
validationRules: validationRules
).get()
}

@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func subscribe(
request: String,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
variables: [String: Map] = [:],
operationName: String? = nil,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> SubscriptionResult {
return try await schema.subscribe(
request: request,
resolver: resolver,
context: context,
eventLoopGroup: eventLoopGroup,
variables: variables,
operationName: operationName,
validationRules: validationRules
).get()
}
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func execute(
request: GraphQLRequest,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> GraphQLResult {
return try await execute(
request: request.query,
context: context,
on: eventLoopGroup,
variables: request.variables,
operationName: request.operationName,
validationRules: validationRules
)
}

@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func subscribe(
request: GraphQLRequest,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> SubscriptionResult {
return try await subscribe(
request: request.query,
context: context,
on: eventLoopGroup,
variables: request.variables,
operationName: request.operationName,
validationRules: validationRules
)
}
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func subscribe(
request: String,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
variables: [String: Map] = [:],
operationName: String? = nil,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> SubscriptionResult {
return try await schema.subscribe(
request: request,
resolver: resolver,
context: context,
eventLoopGroup: eventLoopGroup,
variables: variables,
operationName: operationName,
validationRules: validationRules
).get()
}

#endif
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
func subscribe(
request: GraphQLRequest,
context: ContextType,
on eventLoopGroup: EventLoopGroup,
validationRules: [(ValidationContext) -> Visitor] = []
) async throws -> SubscriptionResult {
return try await subscribe(
request: request.query,
context: context,
on: eventLoopGroup,
variables: request.variables,
operationName: request.operationName,
validationRules: validationRules
)
}
}
42 changes: 19 additions & 23 deletions Sources/Graphiti/Federation/Key/Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,26 @@ public class Key<ObjectType, Resolver, Context, Arguments: Codable>: KeyComponen
}
}

#if compiler(>=5.5) && canImport(_Concurrency)

public extension Key {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
convenience init(
arguments: [ArgumentComponent<Arguments>],
concurrentResolve: @escaping ConcurrentResolve<
Resolver,
Context,
Arguments,
ObjectType?
>
) {
let asyncResolve: AsyncResolve<Resolver, Context, Arguments, ObjectType?> = { type in
{ context, arguments, eventLoopGroup in
let promise = eventLoopGroup.next().makePromise(of: ObjectType?.self)
promise.completeWithTask {
try await concurrentResolve(type)(context, arguments)
}
return promise.futureResult
public extension Key {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
convenience init(
arguments: [ArgumentComponent<Arguments>],
concurrentResolve: @escaping ConcurrentResolve<
Resolver,
Context,
Arguments,
ObjectType?
>
) {
let asyncResolve: AsyncResolve<Resolver, Context, Arguments, ObjectType?> = { type in
{ context, arguments, eventLoopGroup in
let promise = eventLoopGroup.next().makePromise(of: ObjectType?.self)
promise.completeWithTask {
try await concurrentResolve(type)(context, arguments)
}
return promise.futureResult
}
self.init(arguments: arguments, asyncResolve: asyncResolve)
}
self.init(arguments: arguments, asyncResolve: asyncResolve)
}

#endif
}
70 changes: 33 additions & 37 deletions Sources/Graphiti/Federation/Key/Type+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,38 @@ public extension Type {
}
}

#if compiler(>=5.5) && canImport(_Concurrency)

public extension Type {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key value. The name of this argument must match a Type field.
/// - Returns: Self for chaining.
func key<Arguments: Codable>(
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
) -> Self {
keys.append(Key(arguments: [argument()], concurrentResolve: function))
return self
}

@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key values. The names of these arguments must match Type fields.
/// - Returns: Self for chaining.
func key<Arguments: Codable>(
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>]
) -> Self {
keys.append(Key(arguments: arguments(), concurrentResolve: function))
return self
}
public extension Type {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key value. The name of this argument must match a Type field.
/// - Returns: Self for chaining.
func key<Arguments: Codable>(
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
) -> Self {
keys.append(Key(arguments: [argument()], concurrentResolve: function))
return self
}

#endif
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key values. The names of these arguments must match Type fields.
/// - Returns: Self for chaining.
func key<Arguments: Codable>(
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>]
) -> Self {
keys.append(Key(arguments: arguments(), concurrentResolve: function))
return self
}
}
Loading
Loading