Skip to content

Commit 4f01de2

Browse files
feat!: Uses specified rules by default
Adjusts argument order
1 parent bf8b942 commit 4f01de2

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

MIGRATION.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ With the conversion from NIO to Swift Concurrency, types used across async bound
2020

2121
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).
2222

23+
### `validationRules` argument reorder
24+
25+
The `validationRules` argument has been moved from the beginning of `graphql` and `graphqlSubscribe` to the end to better reflect its relative importance:
26+
27+
28+
```swift
29+
// Before
30+
let result = try await graphql(
31+
validationRules: [ruleABC],
32+
schema: schema,
33+
...
34+
)
35+
// After
36+
let result = try await graphql(
37+
schema: schema,
38+
...
39+
validationRules: [ruleABC]
40+
)
41+
```
2342

2443
### EventStream removal
2544

Sources/GraphQL/GraphQL.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ public struct GraphQLErrors: Error, Sendable {
8080
/// and there will be an error inside `errors` specifying the reason for the failure and the path of
8181
/// the failed field.
8282
public func graphql(
83-
validationRules: [@Sendable (ValidationContext) -> Visitor] = [],
8483
schema: GraphQLSchema,
8584
request: String,
8685
rootValue: (any Sendable) = (),
8786
context: (any Sendable) = (),
8887
variableValues: [String: Map] = [:],
89-
operationName: String? = nil
88+
operationName: String? = nil,
89+
validationRules: [@Sendable (ValidationContext) -> Visitor] = specifiedRules
9090
) async throws -> GraphQLResult {
9191
let source = Source(body: request, name: "GraphQL request")
9292
let documentAST = try parse(source: source)
@@ -192,13 +192,13 @@ public func graphql<Retrieval: PersistedQueryRetrieval>(
192192
/// will be an error inside `errors` specifying the reason for the failure and the path of the
193193
/// failed field.
194194
public func graphqlSubscribe(
195-
validationRules: [@Sendable (ValidationContext) -> Visitor] = [],
196195
schema: GraphQLSchema,
197196
request: String,
198197
rootValue: (any Sendable) = (),
199198
context: (any Sendable) = (),
200199
variableValues: [String: Map] = [:],
201-
operationName: String? = nil
200+
operationName: String? = nil,
201+
validationRules: [@Sendable (ValidationContext) -> Visitor] = specifiedRules
202202
) async throws -> Result<AsyncThrowingStream<GraphQLResult, Error>, GraphQLErrors> {
203203
let source = Source(body: request, name: "GraphQL Subscription request")
204204
let documentAST = try parse(source: source)

Sources/GraphQL/Validation/Validate.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/// Implements the "Validation" section of the spec.
2-
///
3-
/// Validation runs synchronously, returning an array of encountered errors, or
4-
/// an empty array if no errors were encountered and the document is valid.
5-
///
6-
/// - Parameters:
7-
/// execution, and field resolution stages.
8-
/// - schema: The GraphQL type system to use when validating and executing a query.
9-
/// - ast: A GraphQL document representing the requested operation.
10-
/// - Returns: zero or more errors
11-
public func validate(
12-
schema: GraphQLSchema,
13-
ast: Document
14-
) -> [GraphQLError] {
15-
return validate(schema: schema, ast: ast, rules: [])
16-
}
17-
181
/**
192
* Implements the "Validation" section of the spec.
203
*
@@ -31,7 +14,7 @@ public func validate(
3114
public func validate(
3215
schema: GraphQLSchema,
3316
ast: Document,
34-
rules: [@Sendable (ValidationContext) -> Visitor]
17+
rules: [@Sendable (ValidationContext) -> Visitor] = specifiedRules
3518
) -> [GraphQLError] {
3619
let typeInfo = TypeInfo(schema: schema)
3720
let rules = rules.isEmpty ? specifiedRules : rules

0 commit comments

Comments
 (0)