Skip to content

Commit cedafbc

Browse files
Merge pull request #150 from NoDevOrg/federated-resolvers
2 parents 6357451 + 7e442e1 commit cedafbc

File tree

7 files changed

+270
-49
lines changed

7 files changed

+270
-49
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,38 @@ jobs:
3232
xcode-version: latest-stable
3333
- uses: actions/checkout@v3
3434
- name: Build and test
35-
run: swift test --parallel --enable-test-discovery
35+
run: swift test --parallel
3636

3737
linux:
38-
name: Test on Linux
38+
name: Test Swift ${{ matrix.swift }}
3939
runs-on: ubuntu-latest
40-
steps:
41-
- uses: swift-actions/setup-swift@v2
42-
- uses: actions/checkout@v3
43-
- name: Test
44-
run: swift test --parallel --enable-code-coverage
45-
- name: Get test coverage html
46-
run: |
47-
llvm-cov show \
48-
$(swift build --show-bin-path)/GraphitiPackageTests.xctest \
49-
--instr-profile $(swift build --show-bin-path)/codecov/default.profdata \
50-
--ignore-filename-regex="\.build|Tests" \
51-
--format html \
52-
--output-dir=.test-coverage
53-
- name: Upload test coverage html
54-
uses: actions/upload-artifact@v3
55-
with:
56-
name: test-coverage-report
57-
path: .test-coverage
58-
59-
backcompat-ubuntu-22_04:
60-
name: Test Swift ${{ matrix.swift }} on Ubuntu 22.04
61-
runs-on: ubuntu-22.04
40+
container:
41+
image: swift:${{ matrix.swift }}
6242
strategy:
6343
matrix:
64-
swift: ["5.8", "5.9", "5.10"]
44+
swift: ["5.8", "5.9", "5.10", "6.0", "6.1"]
6545
steps:
66-
- uses: swift-actions/setup-swift@v2
67-
with:
68-
swift-version: ${{ matrix.swift }}
6946
- uses: actions/checkout@v3
7047
- name: Test
7148
run: swift test --parallel
7249

50+
# TODO: Add test coverage upload but it's currently not working with Swift 6.1.0/Ubuntu-latest
51+
# test-coverage:
52+
# runs-on: ubuntu-latest
53+
# steps:
54+
# - uses: actions/checkout@v3
55+
# - name: Test
56+
# run: swift test --parallel --enable-code-coverage
57+
# - name: Get test coverage html
58+
# run: |
59+
# llvm-cov show \
60+
# $(swift build --show-bin-path)/GraphitiPackageTests.xctest \
61+
# --instr-profile $(swift build --show-bin-path)/codecov/default.profdata \
62+
# --ignore-filename-regex="\.build|Tests" \
63+
# --format html \
64+
# --output-dir=.test-coverage
65+
# - name: Upload test coverage html
66+
# uses: actions/upload-artifact@v4
67+
# with:
68+
# name: test-coverage-report
69+
# path: .test-coverage

Sources/Graphiti/Federation/Key/Type+Key.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import GraphQL
22

33
public extension Type {
4-
@discardableResult
54
/// Define and add the federated key to this type.
65
///
76
/// For more information, see https://www.apollographql.com/docs/federation/entities
87
/// - Parameters:
98
/// - function: The resolver function used to load this entity based on the key value.
109
/// - _: The key value. The name of this argument must match a Type field.
1110
/// - Returns: Self for chaining.
11+
@discardableResult
1212
func key<Arguments: Codable>(
1313
at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>,
1414
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
@@ -17,14 +17,14 @@ public extension Type {
1717
return self
1818
}
1919

20-
@discardableResult
2120
/// Define and add the federated key to this type.
2221
///
2322
/// For more information, see https://www.apollographql.com/docs/federation/entities
2423
/// - Parameters:
2524
/// - function: The resolver function used to load this entity based on the key value.
2625
/// - _: The key values. The names of these arguments must match Type fields.
2726
/// - Returns: Self for chaining.
27+
@discardableResult
2828
func key<Arguments: Codable>(
2929
at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>,
3030
@ArgumentComponentBuilder<Arguments> _ arguments: ()
@@ -34,14 +34,14 @@ public extension Type {
3434
return self
3535
}
3636

37-
@discardableResult
3837
/// Define and add the federated key to this type.
3938
///
4039
/// For more information, see https://www.apollographql.com/docs/federation/entities
4140
/// - Parameters:
4241
/// - function: The resolver function used to load this entity based on the key value.
4342
/// - _: The key value. The name of this argument must match a Type field.
4443
/// - Returns: Self for chaining.
44+
@discardableResult
4545
func key<Arguments: Codable>(
4646
at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>,
4747
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
@@ -50,14 +50,14 @@ public extension Type {
5050
return self
5151
}
5252

53-
@discardableResult
5453
/// Define and add the federated key to this type.
5554
///
5655
/// For more information, see https://www.apollographql.com/docs/federation/entities
5756
/// - Parameters:
5857
/// - function: The resolver function used to load this entity based on the key value.
5958
/// - _: The key values. The names of these arguments must match Type fields.
6059
/// - Returns: Self for chaining.
60+
@discardableResult
6161
func key<Arguments: Codable>(
6262
at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>,
6363
@ArgumentComponentBuilder<Arguments> _ arguments: ()
@@ -67,14 +67,14 @@ public extension Type {
6767
return self
6868
}
6969

70-
@discardableResult
7170
/// Define and add the federated key to this type.
7271
///
7372
/// For more information, see https://www.apollographql.com/docs/federation/entities
7473
/// - Parameters:
7574
/// - function: The resolver function used to load this entity based on the key value.
7675
/// - _: The key value. The name of this argument must match a Type field.
7776
/// - Returns: Self for chaining.
77+
@discardableResult
7878
func key<Arguments: Codable>(
7979
at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>,
8080
@ArgumentComponentBuilder<Arguments> _ arguments: ()
@@ -84,14 +84,14 @@ public extension Type {
8484
return self
8585
}
8686

87-
@discardableResult
8887
/// Define and add the federated key to this type.
8988
///
9089
/// For more information, see https://www.apollographql.com/docs/federation/entities
9190
/// - Parameters:
9291
/// - function: The resolver function used to load this entity based on the key value.
9392
/// - _: The key values. The names of these arguments must match Type fields.
9493
/// - Returns: Self for chaining.
94+
@discardableResult
9595
func key<Arguments: Codable>(
9696
at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>,
9797
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
@@ -102,15 +102,15 @@ public extension Type {
102102
}
103103

104104
public extension Type {
105-
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
106-
@discardableResult
107105
/// Define and add the federated key to this type.
108106
///
109107
/// For more information, see https://www.apollographql.com/docs/federation/entities
110108
/// - Parameters:
111109
/// - function: The resolver function used to load this entity based on the key value.
112110
/// - _: The key value. The name of this argument must match a Type field.
113111
/// - Returns: Self for chaining.
112+
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
113+
@discardableResult
114114
func key<Arguments: Codable>(
115115
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
116116
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
@@ -119,15 +119,15 @@ public extension Type {
119119
return self
120120
}
121121

122-
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
123-
@discardableResult
124122
/// Define and add the federated key to this type.
125123
///
126124
/// For more information, see https://www.apollographql.com/docs/federation/entities
127125
/// - Parameters:
128126
/// - function: The resolver function used to load this entity based on the key value.
129127
/// - _: The key values. The names of these arguments must match Type fields.
130128
/// - Returns: Self for chaining.
129+
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
130+
@discardableResult
131131
func key<Arguments: Codable>(
132132
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
133133
@ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>]

Sources/Graphiti/Schema/Schema.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import GraphQL
22
import NIO
33

4+
public struct SchemaError: Error, Equatable {
5+
let description: String
6+
}
7+
48
public final class Schema<Resolver, Context> {
59
public let schema: GraphQLSchema
610

@@ -16,11 +20,14 @@ public final class Schema<Resolver, Context> {
1620
try component.update(typeProvider: typeProvider, coders: coders)
1721
}
1822

19-
guard let query = typeProvider.query else {
20-
fatalError("Query type is required.")
23+
guard typeProvider.query != nil || !typeProvider.federatedResolvers.isEmpty else {
24+
throw SchemaError(
25+
description: "Schema must contain at least 1 query or federated resolver"
26+
)
2127
}
28+
2229
schema = try GraphQLSchema(
23-
query: query,
30+
query: typeProvider.query,
2431
mutation: typeProvider.mutation,
2532
subscription: typeProvider.subscription,
2633
types: typeProvider.types,

Sources/Graphiti/SchemaBuilders/SchemaBuilder.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public final class SchemaBuilder<Resolver, Context> {
2727
subscriptionFields = []
2828
}
2929

30-
@discardableResult
3130
/// Allows for setting API encoders and decoders with customized settings.
3231
/// - Parameter newCoders: The new coders to use
3332
/// - Returns: This object for method chaining
33+
@discardableResult
3434
public func setCoders(to newCoders: Coders) -> Self {
3535
coders = newCoders
3636
return self
3737
}
3838

39-
@discardableResult
4039
/// Allows for setting SDL for federated subgraphs.
4140
/// - Parameter newSDL: The new SDL to use
4241
/// - Returns: This object for method chaining
42+
@discardableResult
4343
public func setFederatedSDL(to newSDL: String) -> Self {
4444
federatedSDL = newSDL
4545
return self
@@ -63,10 +63,10 @@ public final class SchemaBuilder<Resolver, Context> {
6363
return self
6464
}
6565

66-
@discardableResult
6766
/// Adds multiple query operation definitions to the schema.
6867
/// - Parameter component: The query operations to add
6968
/// - Returns: This object for method chaining
69+
@discardableResult
7070
public func add(
7171
@TypeComponentBuilder<Resolver, Context> _ components: ()
7272
-> [TypeComponent<Resolver, Context>]
@@ -77,10 +77,10 @@ public final class SchemaBuilder<Resolver, Context> {
7777
return self
7878
}
7979

80-
@discardableResult
8180
/// Adds multiple query operation definitions to the schema.
8281
/// - Parameter component: The query operations to add
8382
/// - Returns: This object for method chaining
83+
@discardableResult
8484
public func addQuery(
8585
@FieldComponentBuilder<Resolver, Context> _ fields: ()
8686
-> [FieldComponent<Resolver, Context>]
@@ -91,10 +91,10 @@ public final class SchemaBuilder<Resolver, Context> {
9191
return self
9292
}
9393

94-
@discardableResult
9594
/// Adds multiple mutation operation definitions to the schema.
9695
/// - Parameter component: The query operations to add
9796
/// - Returns: This object for method chaining
97+
@discardableResult
9898
public func addMutation(
9999
@FieldComponentBuilder<Resolver, Context> _ fields: ()
100100
-> [FieldComponent<Resolver, Context>]
@@ -105,10 +105,10 @@ public final class SchemaBuilder<Resolver, Context> {
105105
return self
106106
}
107107

108-
@discardableResult
109108
/// Adds multiple subscription operation definitions to the schema.
110109
/// - Parameter component: The query operations to add
111110
/// - Returns: This object for method chaining
111+
@discardableResult
112112
public func addSubscription(
113113
@FieldComponentBuilder<Resolver, Context> _ fields: ()
114114
-> [FieldComponent<Resolver, Context>]
@@ -119,10 +119,10 @@ public final class SchemaBuilder<Resolver, Context> {
119119
return self
120120
}
121121

122-
@discardableResult
123122
/// Adds multiple type, query, mutation, and subscription definitions using partial schemas to the schema.
124123
/// - Parameter partials: Partial schemas that declare types, query, mutation, and/or subscription definiton
125124
/// - Returns: Thie object for method chaining
125+
@discardableResult
126126
public func use(partials: [PartialSchema<Resolver, Context>]) -> Self {
127127
for type in partials.flatMap({ $0.types }) {
128128
typeComponents.append(type)

0 commit comments

Comments
 (0)