Skip to content

Commit d42c638

Browse files
feature: Adds request operation type function
1 parent c265770 commit d42c638

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/GraphQL/GraphQLRequest.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public struct GraphQLRequest: Equatable, Codable {
2727
/// - Returns: True if request is a subscription, false if it is an atomic operation (like
2828
/// `query` or `mutation`)
2929
public func isSubscription() throws -> Bool {
30+
return try operationType() == .subscription
31+
}
32+
33+
/// The type of operation perfomed by the request.
34+
/// This operation performs an entire AST parse on the GraphQL request, so consider
35+
/// performance when calling multiple times.
36+
///
37+
/// - Returns: The operation type performed by the request
38+
public func operationType() throws -> OperationType {
3039
let documentAST = try GraphQL.parse(
3140
instrumentation: NoOpInstrumentation,
3241
source: Source(body: query, name: "GraphQL request")
@@ -35,6 +44,6 @@ public struct GraphQLRequest: Equatable, Codable {
3544
guard let operationType = firstOperation?.operation else {
3645
throw GraphQLError(message: "GraphQL operation type could not be determined")
3746
}
38-
return operationType == .subscription
47+
return operationType
3948
}
4049
}

0 commit comments

Comments
 (0)