Skip to content

Commit dfa0a60

Browse files
feat!: Validates schema on execute
1 parent 4f01de2 commit dfa0a60

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/GraphQL/GraphQL.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,27 @@ public func graphql(
8888
operationName: String? = nil,
8989
validationRules: [@Sendable (ValidationContext) -> Visitor] = specifiedRules
9090
) async throws -> GraphQLResult {
91+
// Validate schema
92+
let schemaValidationErrors = try validateSchema(schema: schema)
93+
guard schemaValidationErrors.isEmpty else {
94+
return GraphQLResult(errors: schemaValidationErrors)
95+
}
96+
97+
// Parse
9198
let source = Source(body: request, name: "GraphQL request")
9299
let documentAST = try parse(source: source)
100+
101+
// Validate
93102
let validationErrors = validate(
94103
schema: schema,
95104
ast: documentAST,
96105
rules: validationRules
97106
)
98-
99107
guard validationErrors.isEmpty else {
100108
return GraphQLResult(errors: validationErrors)
101109
}
102110

111+
// Execute
103112
return try await execute(
104113
schema: schema,
105114
documentAST: documentAST,

0 commit comments

Comments
 (0)