Skip to content

Commit bf8b942

Browse files
feat!: Hides execution strategies, applying spec specified ones
1 parent 5c1e0be commit bf8b942

File tree

6 files changed

+8
-366
lines changed

6 files changed

+8
-366
lines changed

MIGRATION.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ The documentation here will be very helpful in the conversion: https://www.swift
1616

1717
With the conversion from NIO to Swift Concurrency, types used across async boundaries should conform to `Sendable` to avoid errors and warnings. This includes the Swift types and functions that back the GraphQL schema. For more details on the conversion, see the [Sendable documentation](https://developer.apple.com/documentation/swift/sendable).
1818

19-
### `ConcurrentDispatchFieldExecutionStrategy`
19+
### `ExecutionStrategy` argument removals
20+
21+
The `queryStrategy`, `mutationStrategy`, and `subscriptionStrategy` arguments have been removed from `graphql` and `graphqlSubscribe`. Instead Queries and Subscriptions are executed in parallel and Mutations are executed serially, [as required by the spec](https://spec.graphql.org/October2021/#sec-Mutation).
2022

21-
This was changed to `ConcurrentFieldExecutionStrategy`, and takes no parameters.
2223

2324
### EventStream removal
2425

Sources/GraphQL/Execution/Execute.swift

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ import OrderedCollections
2828
* and the fragments defined in the query document
2929
*/
3030
public final class ExecutionContext: @unchecked Sendable {
31-
let queryStrategy: QueryFieldExecutionStrategy
32-
let mutationStrategy: MutationFieldExecutionStrategy
33-
let subscriptionStrategy: SubscriptionFieldExecutionStrategy
31+
let queryStrategy: QueryFieldExecutionStrategy = ConcurrentFieldExecutionStrategy()
32+
let mutationStrategy: MutationFieldExecutionStrategy = SerialFieldExecutionStrategy()
33+
let subscriptionStrategy: SubscriptionFieldExecutionStrategy =
34+
ConcurrentFieldExecutionStrategy()
3435
public let schema: GraphQLSchema
3536
public let fragments: [String: FragmentDefinition]
3637
public let rootValue: any Sendable
@@ -59,9 +60,6 @@ public final class ExecutionContext: @unchecked Sendable {
5960
}
6061

6162
init(
62-
queryStrategy: QueryFieldExecutionStrategy,
63-
mutationStrategy: MutationFieldExecutionStrategy,
64-
subscriptionStrategy: SubscriptionFieldExecutionStrategy,
6563
schema: GraphQLSchema,
6664
fragments: [String: FragmentDefinition],
6765
rootValue: any Sendable,
@@ -70,9 +68,6 @@ public final class ExecutionContext: @unchecked Sendable {
7068
variableValues: [String: Map],
7169
errors: [GraphQLError]
7270
) {
73-
self.queryStrategy = queryStrategy
74-
self.mutationStrategy = mutationStrategy
75-
self.subscriptionStrategy = subscriptionStrategy
7671
self.schema = schema
7772
self.fragments = fragments
7873
self.rootValue = rootValue
@@ -179,10 +174,7 @@ public struct ConcurrentFieldExecutionStrategy: QueryFieldExecutionStrategy,
179174
* If the arguments to this func do not result in a legal execution context,
180175
* a GraphQLError will be thrown immediately explaining the invalid input.
181176
*/
182-
func execute(
183-
queryStrategy: QueryFieldExecutionStrategy,
184-
mutationStrategy: MutationFieldExecutionStrategy,
185-
subscriptionStrategy: SubscriptionFieldExecutionStrategy,
177+
public func execute(
186178
schema: GraphQLSchema,
187179
documentAST: Document,
188180
rootValue: any Sendable,
@@ -196,9 +188,6 @@ func execute(
196188
// If a valid context cannot be created due to incorrect arguments,
197189
// this will throw an error.
198190
buildContext = try buildExecutionContext(
199-
queryStrategy: queryStrategy,
200-
mutationStrategy: mutationStrategy,
201-
subscriptionStrategy: subscriptionStrategy,
202191
schema: schema,
203192
documentAST: documentAST,
204193
rootValue: rootValue,
@@ -247,9 +236,6 @@ func execute(
247236
* Throws a GraphQLError if a valid execution context cannot be created.
248237
*/
249238
func buildExecutionContext(
250-
queryStrategy: QueryFieldExecutionStrategy,
251-
mutationStrategy: MutationFieldExecutionStrategy,
252-
subscriptionStrategy: SubscriptionFieldExecutionStrategy,
253239
schema: GraphQLSchema,
254240
documentAST: Document,
255241
rootValue: any Sendable,
@@ -300,9 +286,6 @@ func buildExecutionContext(
300286
)
301287

302288
return ExecutionContext(
303-
queryStrategy: queryStrategy,
304-
mutationStrategy: mutationStrategy,
305-
subscriptionStrategy: subscriptionStrategy,
306289
schema: schema,
307290
fragments: fragments,
308291
rootValue: rootValue,

Sources/GraphQL/GraphQL.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ public struct GraphQLErrors: Error, Sendable {
5959
/// may wish to separate the validation and execution phases to a static time
6060
/// tooling step, and a server runtime step.
6161
///
62-
/// - parameter queryStrategy: The field execution strategy to use for query requests
63-
/// - parameter mutationStrategy: The field execution strategy to use for mutation requests
64-
/// - parameter subscriptionStrategy: The field execution strategy to use for subscription requests
6562
/// - parameter schema: The GraphQL type system to use when validating and executing a
6663
/// query.
6764
/// - parameter request: A GraphQL language formatted string representing the requested
@@ -83,9 +80,6 @@ public struct GraphQLErrors: Error, Sendable {
8380
/// and there will be an error inside `errors` specifying the reason for the failure and the path of
8481
/// the failed field.
8582
public func graphql(
86-
queryStrategy: QueryFieldExecutionStrategy = SerialFieldExecutionStrategy(),
87-
mutationStrategy: MutationFieldExecutionStrategy = SerialFieldExecutionStrategy(),
88-
subscriptionStrategy: SubscriptionFieldExecutionStrategy = SerialFieldExecutionStrategy(),
8983
validationRules: [@Sendable (ValidationContext) -> Visitor] = [],
9084
schema: GraphQLSchema,
9185
request: String,
@@ -107,9 +101,6 @@ public func graphql(
107101
}
108102

109103
return try await execute(
110-
queryStrategy: queryStrategy,
111-
mutationStrategy: mutationStrategy,
112-
subscriptionStrategy: subscriptionStrategy,
113104
schema: schema,
114105
documentAST: documentAST,
115106
rootValue: rootValue,
@@ -122,9 +113,6 @@ public func graphql(
122113
/// This is the primary entry point function for fulfilling GraphQL operations
123114
/// by using persisted queries.
124115
///
125-
/// - parameter queryStrategy: The field execution strategy to use for query requests
126-
/// - parameter mutationStrategy: The field execution strategy to use for mutation requests
127-
/// - parameter subscriptionStrategy: The field execution strategy to use for subscription requests
128116
/// - parameter queryRetrieval: The PersistedQueryRetrieval instance to use for looking up
129117
/// queries
130118
/// - parameter queryId: The id of the query to execute
@@ -145,9 +133,6 @@ public func graphql(
145133
/// and there will be an error inside `errors` specifying the reason for the failure and the path of
146134
/// the failed field.
147135
public func graphql<Retrieval: PersistedQueryRetrieval>(
148-
queryStrategy: QueryFieldExecutionStrategy = SerialFieldExecutionStrategy(),
149-
mutationStrategy: MutationFieldExecutionStrategy = SerialFieldExecutionStrategy(),
150-
subscriptionStrategy: SubscriptionFieldExecutionStrategy = SerialFieldExecutionStrategy(),
151136
queryRetrieval: Retrieval,
152137
queryId: Retrieval.Id,
153138
rootValue: (any Sendable) = (),
@@ -164,9 +149,6 @@ public func graphql<Retrieval: PersistedQueryRetrieval>(
164149
return GraphQLResult(errors: validationErrors)
165150
case let .result(schema, documentAST):
166151
return try await execute(
167-
queryStrategy: queryStrategy,
168-
mutationStrategy: mutationStrategy,
169-
subscriptionStrategy: subscriptionStrategy,
170152
schema: schema,
171153
documentAST: documentAST,
172154
rootValue: rootValue,
@@ -185,9 +167,6 @@ public func graphql<Retrieval: PersistedQueryRetrieval>(
185167
/// may wish to separate the validation and execution phases to a static time
186168
/// tooling step, and a server runtime step.
187169
///
188-
/// - parameter queryStrategy: The field execution strategy to use for query requests
189-
/// - parameter mutationStrategy: The field execution strategy to use for mutation requests
190-
/// - parameter subscriptionStrategy: The field execution strategy to use for subscription requests
191170
/// - parameter schema: The GraphQL type system to use when validating and executing a
192171
/// query.
193172
/// - parameter request: A GraphQL language formatted string representing the requested
@@ -213,9 +192,6 @@ public func graphql<Retrieval: PersistedQueryRetrieval>(
213192
/// will be an error inside `errors` specifying the reason for the failure and the path of the
214193
/// failed field.
215194
public func graphqlSubscribe(
216-
queryStrategy: QueryFieldExecutionStrategy = SerialFieldExecutionStrategy(),
217-
mutationStrategy: MutationFieldExecutionStrategy = SerialFieldExecutionStrategy(),
218-
subscriptionStrategy: SubscriptionFieldExecutionStrategy = SerialFieldExecutionStrategy(),
219195
validationRules: [@Sendable (ValidationContext) -> Visitor] = [],
220196
schema: GraphQLSchema,
221197
request: String,
@@ -237,9 +213,6 @@ public func graphqlSubscribe(
237213
}
238214

239215
return try await subscribe(
240-
queryStrategy: queryStrategy,
241-
mutationStrategy: mutationStrategy,
242-
subscriptionStrategy: subscriptionStrategy,
243216
schema: schema,
244217
documentAST: documentAST,
245218
rootValue: rootValue,

Sources/GraphQL/Subscription/Subscribe.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import OrderedCollections
1515
* representing the response stream.
1616
*/
1717
func subscribe(
18-
queryStrategy: QueryFieldExecutionStrategy,
19-
mutationStrategy: MutationFieldExecutionStrategy,
20-
subscriptionStrategy: SubscriptionFieldExecutionStrategy,
2118
schema: GraphQLSchema,
2219
documentAST: Document,
2320
rootValue: any Sendable,
@@ -26,9 +23,6 @@ func subscribe(
2623
operationName: String? = nil
2724
) async throws -> Result<AsyncThrowingStream<GraphQLResult, Error>, GraphQLErrors> {
2825
let sourceResult = try await createSourceEventStream(
29-
queryStrategy: queryStrategy,
30-
mutationStrategy: mutationStrategy,
31-
subscriptionStrategy: subscriptionStrategy,
3226
schema: schema,
3327
documentAST: documentAST,
3428
rootValue: rootValue,
@@ -49,9 +43,6 @@ func subscribe(
4943
// `marker protocol 'Sendable' cannot be used in a conditional cast`
5044
let rootValue = eventPayload as! (any Sendable)
5145
return try await execute(
52-
queryStrategy: queryStrategy,
53-
mutationStrategy: mutationStrategy,
54-
subscriptionStrategy: subscriptionStrategy,
5546
schema: schema,
5647
documentAST: documentAST,
5748
rootValue: rootValue,
@@ -87,9 +78,6 @@ func subscribe(
8778
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
8879
*/
8980
func createSourceEventStream(
90-
queryStrategy: QueryFieldExecutionStrategy,
91-
mutationStrategy: MutationFieldExecutionStrategy,
92-
subscriptionStrategy: SubscriptionFieldExecutionStrategy,
9381
schema: GraphQLSchema,
9482
documentAST: Document,
9583
rootValue: any Sendable,
@@ -100,9 +88,6 @@ func createSourceEventStream(
10088
// If a valid context cannot be created due to incorrect arguments,
10189
// this will throw an error.
10290
let exeContext = try buildExecutionContext(
103-
queryStrategy: queryStrategy,
104-
mutationStrategy: mutationStrategy,
105-
subscriptionStrategy: subscriptionStrategy,
10691
schema: schema,
10792
documentAST: documentAST,
10893
rootValue: rootValue,

0 commit comments

Comments
 (0)