AsyncObjectValue

Trait AsyncObjectValue 

Source
pub trait AsyncObjectValue: Send {
    // Required methods
    fn type_name(&self) -> &str;
    fn resolve_field<'a>(
        &'a self,
        info: &'a ResolveInfo<'a>,
    ) -> BoxFuture<'a, Result<AsyncResolvedValue<'a>, FieldError>>;

    // Provided method
    fn unknown_field_error(&self, info: &ResolveInfo<'_>) -> FieldError { ... }
}
Expand description

A concrete GraphQL object whose fields can be resolved asynchronously during execution.

Required Methods§

Source

fn type_name(&self) -> &str

Returns the name of the concrete object type

That name expected to be that of an object type defined in the schema.

Source

fn resolve_field<'a>( &'a self, info: &'a ResolveInfo<'a>, ) -> BoxFuture<'a, Result<AsyncResolvedValue<'a>, FieldError>>

Resolves a concrete field of this object

The resolved value is expected to match the type of the corresponding field definition in the schema.

This is not called for introspection meta-fields __typename, __type, or __schema: those are handled separately.

A typical implementation might look like:

Box::pin(async move {
    match info.field_name() {
        "field1" => Ok(AsyncResolvedValue::leaf(self.resolve_field1().await)),
        "field2" => Ok(AsyncResolvedValue::list(self.resolve_field2().await)),
        _ => Err(self.unknown_field_error(info)),
    }
})

Provided Methods§

Source

fn unknown_field_error(&self, info: &ResolveInfo<'_>) -> FieldError

Generate a resolve error for resolve_field to return in case of an unexpected field name.

In many cases this should never happen, such as when writing resolvers for a fixed, known schema. Still, this method generates a GraphQL field error without Rust panick in case of a bug.

Implementors§