Struct async_graphql::dynamic::TypeRef
source · pub struct TypeRef(_);
Available on crate feature
dynamic-schema
only.Expand description
A type reference
Implementations§
source§impl TypeRef
impl TypeRef
sourcepub fn named(type_name: impl Into<String>) -> TypeRef
pub fn named(type_name: impl Into<String>) -> TypeRef
Returns the nullable type reference
GraphQL Type: T
sourcepub fn named_nn(type_name: impl Into<String>) -> TypeRef
pub fn named_nn(type_name: impl Into<String>) -> TypeRef
Returns the non-null type reference
GraphQL Type: T!
sourcepub fn named_list(type_name: impl Into<String>) -> TypeRef
pub fn named_list(type_name: impl Into<String>) -> TypeRef
Returns a nullable list of nullable members type reference
GraphQL Type: [T]
sourcepub fn named_nn_list(type_name: impl Into<String>) -> TypeRef
pub fn named_nn_list(type_name: impl Into<String>) -> TypeRef
Returns a nullable list of non-null members type reference
GraphQL Type: [T!]
sourcepub fn named_list_nn(type_name: impl Into<String>) -> TypeRef
pub fn named_list_nn(type_name: impl Into<String>) -> TypeRef
Returns a non-null list of nullable members type reference
GraphQL Type: [T]!
Examples found in repository?
src/dynamic/resolve.rs (line 175)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
fn collect_fields<'a>(
fields: &mut Vec<BoxFieldFuture<'a>>,
schema: &'a Schema,
object: &'a Object,
ctx: &ContextSelectionSet<'a>,
parent_value: &'a FieldValue,
) -> ServerResult<()> {
for selection in &ctx.item.node.items {
match &selection.node {
Selection::Field(field) => {
if field.node.name.node == "__typename" {
if matches!(
ctx.schema_env.registry.introspection_mode,
IntrospectionMode::Enabled | IntrospectionMode::IntrospectionOnly
) && matches!(
ctx.query_env.introspection_mode,
IntrospectionMode::Enabled | IntrospectionMode::IntrospectionOnly,
) {
fields.push(
async move {
Ok((
field.node.response_key().node.clone(),
Value::from(object.name.as_str()),
))
}
.boxed(),
)
} else {
fields.push(
async move { Ok((field.node.response_key().node.clone(), Value::Null)) }.boxed(),
)
}
continue;
}
if object.name == schema.0.env.registry.query_type
&& matches!(
ctx.schema_env.registry.introspection_mode,
IntrospectionMode::Enabled | IntrospectionMode::IntrospectionOnly
)
&& matches!(
ctx.query_env.introspection_mode,
IntrospectionMode::Enabled | IntrospectionMode::IntrospectionOnly,
)
{
// is query root
if field.node.name.node == "__schema" {
let ctx = ctx.clone();
fields.push(
async move {
let ctx_field = ctx.with_field(field);
let mut ctx_obj =
ctx.with_selection_set(&ctx_field.item.node.selection_set);
ctx_obj.is_for_introspection = true;
let visible_types =
ctx.schema_env.registry.find_visible_types(&ctx_field);
let value = crate::OutputType::resolve(
&crate::model::__Schema::new(
&ctx.schema_env.registry,
&visible_types,
),
&ctx_obj,
ctx_field.item,
)
.await?;
Ok((field.node.response_key().node.clone(), value))
}
.boxed(),
);
continue;
} else if field.node.name.node == "__type" {
let ctx = ctx.clone();
fields.push(
async move {
let ctx_field = ctx.with_field(field);
let (_, type_name) =
ctx_field.param_value::<String>("name", None)?;
let mut ctx_obj =
ctx.with_selection_set(&ctx_field.item.node.selection_set);
ctx_obj.is_for_introspection = true;
let visible_types =
ctx.schema_env.registry.find_visible_types(&ctx_field);
let value = crate::OutputType::resolve(
&ctx.schema_env
.registry
.types
.get(&type_name)
.filter(|_| visible_types.contains(type_name.as_str()))
.map(|ty| {
crate::model::__Type::new_simple(
&ctx.schema_env.registry,
&visible_types,
ty,
)
}),
&ctx_obj,
ctx_field.item,
)
.await?;
Ok((field.node.response_key().node.clone(), value))
}
.boxed(),
);
continue;
} else if ctx.schema_env.registry.enable_federation
&& field.node.name.node == "_service"
{
let sdl = ctx
.schema_env
.registry
.export_sdl(SDLExportOptions::new().federation());
fields.push(
async move {
Ok((field.node.response_key().node.clone(), Value::from(sdl)))
}
.boxed(),
);
continue;
} else if ctx.schema_env.registry.enable_federation
&& field.node.name.node == "_entities"
{
let ctx = ctx.clone();
fields.push(
async move {
let ctx_field = ctx.with_field(field);
let entity_resolver =
schema.0.entity_resolver.as_ref().ok_or_else(|| {
ctx_field.set_error_path(
Error::new("internal: missing entity resolver")
.into_server_error(ctx_field.item.pos),
)
})?;
let entity_type = TypeRef::named_list_nn("_Entity");
let arguments = ObjectAccessor(Cow::Owned(
field
.node
.arguments
.iter()
.map(|(name, value)| {
ctx_field
.resolve_input_value(value.clone())
.map(|value| (name.node.clone(), value))
})
.collect::<ServerResult<IndexMap<Name, Value>>>()?,
));
let field_value = (entity_resolver)(ResolverContext {
ctx: &ctx_field,
args: arguments,
parent_value,
})
.0
.await
.map_err(|err| err.into_server_error(field.pos))?;
let value = resolve(
schema,
&ctx_field,
&entity_type.0,
field_value.as_ref(),
)
.await?
.unwrap_or_default();
Ok((field.node.response_key().node.clone(), value))
}
.boxed(),
);
continue;
}
}
if ctx.schema_env.registry.introspection_mode
== IntrospectionMode::IntrospectionOnly
|| ctx.query_env.introspection_mode == IntrospectionMode::IntrospectionOnly
{
fields.push(
async move { Ok((field.node.response_key().node.clone(), Value::Null)) }
.boxed(),
);
continue;
}
if let Some(field_def) = object.fields.get(field.node.name.node.as_str()) {
let ctx = ctx.clone();
fields.push(
async move {
let ctx_field = ctx.with_field(field);
let arguments = ObjectAccessor(Cow::Owned(
field
.node
.arguments
.iter()
.map(|(name, value)| {
ctx_field
.resolve_input_value(value.clone())
.map(|value| (name.node.clone(), value))
})
.collect::<ServerResult<IndexMap<Name, Value>>>()?,
));
let resolve_info = ResolveInfo {
path_node: ctx_field.path_node.as_ref().unwrap(),
parent_type: &object.name,
return_type: &field_def.ty.to_string(),
name: &field.node.name.node,
alias: field.node.alias.as_ref().map(|alias| &*alias.node),
is_for_introspection: ctx_field.is_for_introspection,
};
let resolve_fut = async {
let field_value = (field_def.resolver_fn)(ResolverContext {
ctx: &ctx_field,
args: arguments,
parent_value,
})
.0
.await
.map_err(|err| err.into_server_error(field.pos))?;
let value = resolve(
schema,
&ctx_field,
&field_def.ty.0,
field_value.as_ref(),
)
.await?;
Ok(value)
};
futures_util::pin_mut!(resolve_fut);
let res_value = ctx_field
.query_env
.extensions
.resolve(resolve_info, &mut resolve_fut)
.await?
.unwrap_or_default();
Ok((field.node.response_key().node.clone(), res_value))
}
.boxed(),
);
}
}
selection => {
let (type_condition, selection_set) = match selection {
Selection::Field(_) => unreachable!(),
Selection::FragmentSpread(spread) => {
let fragment = ctx.query_env.fragments.get(&spread.node.fragment_name.node);
let fragment = match fragment {
Some(fragment) => fragment,
None => {
return Err(ServerError::new(
format!(
"Unknown fragment \"{}\".",
spread.node.fragment_name.node
),
Some(spread.pos),
));
}
};
(
Some(&fragment.node.type_condition),
&fragment.node.selection_set,
)
}
Selection::InlineFragment(fragment) => (
fragment.node.type_condition.as_ref(),
&fragment.node.selection_set,
),
};
let type_condition =
type_condition.map(|condition| condition.node.on.node.as_str());
let introspection_type_name = &object.name;
if type_condition.is_none() || type_condition == Some(introspection_type_name) {
collect_fields(
fields,
schema,
object,
&ctx.with_selection_set(selection_set),
parent_value,
)?;
}
}
}
}
Ok(())
}
sourcepub fn named_nn_list_nn(type_name: impl Into<String>) -> TypeRef
pub fn named_nn_list_nn(type_name: impl Into<String>) -> TypeRef
Returns a non-null list of non-null members type reference
GraphQL Type: [T!]!
Trait Implementations§
impl Eq for TypeRef
impl StructuralEq for TypeRef
impl StructuralPartialEq for TypeRef
Auto Trait Implementations§
impl RefUnwindSafe for TypeRef
impl Send for TypeRef
impl Sync for TypeRef
impl Unpin for TypeRef
impl UnwindSafe for TypeRef
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.