libgraphql_core/operation/
inline_fragment.rs

1use crate::DirectiveAnnotation;
2use crate::loc;
3use crate::operation::SelectionSet;
4use crate::schema::Schema;
5use crate::types::GraphQLType;
6use crate::types::NamedGraphQLTypeRef;
7
8#[derive(Clone, Debug, PartialEq)]
9pub struct InlineFragment<'schema> {
10    pub(super) def_location: loc::SourceLocation,
11    pub(super) directives: Vec<DirectiveAnnotation>,
12    pub(super) selection_set: SelectionSet<'schema>,
13    pub(super) type_condition: Option<NamedGraphQLTypeRef>,
14}
15impl<'schema> InlineFragment<'schema> {
16    pub fn def_location(&self) -> &loc::SourceLocation {
17        &self.def_location
18    }
19
20    pub fn directives(&self) -> &Vec<DirectiveAnnotation> {
21        &self.directives
22    }
23
24    pub fn selection_set(&self) -> &SelectionSet<'schema> {
25        &self.selection_set
26    }
27
28    pub fn type_condition(
29        &self,
30        schema: &'schema Schema,
31    ) -> Option<&'schema GraphQLType> {
32        self.type_condition
33            .as_ref()
34            .map(|graphql_type| {
35                graphql_type.deref(schema).expect(
36                    "type is present in schema",
37                )
38            })
39    }
40
41    pub fn type_condition_name(&self) -> Option<&str> {
42        self.type_condition
43            .as_ref()
44            .map(|type_ref| type_ref.name())
45    }
46}