libgraphql_core/operation/
graphql_operation.rs1use crate::loc;
2use crate::operation::Query;
3use crate::operation::Mutation;
4use crate::operation::Subscription;
5
6#[derive(Debug, PartialEq)]
7pub enum GraphQLOperation<'schema, 'fragreg> {
8 Query(Box<Query<'schema, 'fragreg>>),
9 Mutation(Box<Mutation<'schema, 'fragreg>>),
10 Subscription(Box<Subscription<'schema, 'fragreg>>),
11}
12impl<'schema, 'fragreg> GraphQLOperation<'schema, 'fragreg> {
13 pub fn as_query(&self) -> Option<&Query<'schema, 'fragreg>> {
14 if let Self::Query(op) = self {
15 Some(op)
16 } else {
17 None
18 }
19 }
20
21 pub fn as_mutation(&self) -> Option<&Mutation<'schema, 'fragreg>> {
22 if let Self::Mutation(op) = self {
23 Some(op)
24 } else {
25 None
26 }
27 }
28
29 pub fn as_subscription(&self) -> Option<&Subscription<'schema, 'fragreg>> {
30 if let Self::Subscription(op) = self {
31 Some(op)
32 } else {
33 None
34 }
35 }
36
37 pub fn def_location(&self) -> &loc::SourceLocation {
38 match self {
39 Self::Query(query) => query.def_location(),
40 Self::Mutation(mutation) => mutation.def_location(),
41 Self::Subscription(subscription) => subscription.def_location(),
42 }
43 }
44
45 pub fn name(&self) -> Option<&str> {
46 match self {
47 Self::Query(query) => query.name(),
48 Self::Mutation(mutation) => mutation.name(),
49 Self::Subscription(subscription) => subscription.name(),
50 }
51 }
52}