async_graphql/dynamic/
macros.rs

1macro_rules! impl_set_description {
2    () => {
3        /// Set the description
4        #[inline]
5        pub fn description(self, description: impl Into<String>) -> Self {
6            Self {
7                description: Some(description.into()),
8                ..self
9            }
10        }
11    };
12}
13
14macro_rules! impl_set_deprecation {
15    () => {
16        /// Set the description
17        #[inline]
18        pub fn deprecation(self, reason: Option<&str>) -> Self {
19            Self {
20                deprecation: Deprecation::Deprecated {
21                    reason: reason.map(Into::into),
22                },
23                ..self
24            }
25        }
26    };
27}
28
29macro_rules! impl_set_extends {
30    () => {
31        /// Indicates that an object or interface definition is an extension of another
32        /// definition of that same type.
33        #[inline]
34        pub fn extends(self) -> Self {
35            Self {
36                extends: true,
37                ..self
38            }
39        }
40    };
41}
42
43macro_rules! impl_set_inaccessible {
44    () => {
45        /// Indicate that an enum is not accessible from a supergraph when using
46        /// Apollo Federation
47        ///
48        /// Reference: <https://www.apollographql.com/docs/federation/federated-types/federated-directives/#inaccessible>
49        #[inline]
50        pub fn inaccessible(self) -> Self {
51            Self {
52                inaccessible: true,
53                ..self
54            }
55        }
56    };
57}
58
59macro_rules! impl_set_interface_object {
60    () => {
61        /// During composition, the fields of every `@interfaceObject` are added
62        /// both to their corresponding interface definition and to all
63        /// entity types that implement that interface.
64        ///
65        /// Reference: <https://www.apollographql.com/docs/federation/federated-types/federated-directives/#interfaceobject>
66        #[inline]
67        pub fn interface_object(self) -> Self {
68            Self {
69                interface_object: true,
70                ..self
71            }
72        }
73    };
74}
75
76macro_rules! impl_set_tags {
77    () => {
78        /// Arbitrary string metadata that will be propagated to the supergraph
79        /// when using Apollo Federation. This attribute is repeatable
80        ///
81        /// Reference: <https://www.apollographql.com/docs/federation/federated-types/federated-directives/#applying-metadata>
82        #[inline]
83        pub fn tags<I: IntoIterator<Item = T>, T: Into<String>>(self, tags: I) -> Self {
84            Self {
85                tags: tags.into_iter().map(Into::into).collect(),
86                ..self
87            }
88        }
89    };
90}
91
92macro_rules! impl_set_external {
93    () => {
94        /// Mark a field as owned by another service. This allows service A to use
95        /// fields from service B while also knowing at runtime the types of that
96        /// field.
97        #[inline]
98        pub fn external(self) -> Self {
99            Self {
100                external: true,
101                ..self
102            }
103        }
104    };
105}
106
107macro_rules! impl_set_requires {
108    () => {
109        /// Annotate the required input fieldset from a base type for a resolver. It
110        /// is used to develop a query plan where the required fields may not be
111        /// needed by the client, but the service may need additional information
112        /// from other services.
113        #[inline]
114        pub fn requires(self, fields: impl Into<String>) -> Self {
115            Self {
116                requires: Some(fields.into()),
117                ..self
118            }
119        }
120    };
121}
122
123macro_rules! impl_set_provides {
124    () => {
125        /// Annotate the expected returned fieldset from a field on a base type that
126        /// is guaranteed to be selectable by the gateway.
127        #[inline]
128        pub fn provides(self, fields: impl Into<String>) -> Self {
129            Self {
130                provides: Some(fields.into()),
131                ..self
132            }
133        }
134    };
135}
136
137macro_rules! impl_set_shareable {
138    () => {
139        /// Indicate that an object type's field is allowed to be resolved by
140        /// multiple subgraphs
141        #[inline]
142        pub fn shareable(self) -> Self {
143            Self {
144                shareable: true,
145                ..self
146            }
147        }
148    };
149}
150
151macro_rules! impl_set_override_from {
152    () => {
153        /// Indicate that an object type's field is allowed to be resolved by
154        /// multiple subgraphs
155        #[inline]
156        pub fn override_from(self, name: impl Into<String>) -> Self {
157            Self {
158                override_from: Some(name.into()),
159                ..self
160            }
161        }
162    };
163}
164
165macro_rules! impl_directive {
166    () => {
167        /// Attach directive to the entity
168        #[inline]
169        pub fn directive(mut self, directive: Directive) -> Self {
170            self.directives.push(directive);
171
172            self
173        }
174    };
175}