pub trait ObjectValue {
// Required methods
fn type_name(&self) -> &str;
fn resolve_field<'a>(
&'a self,
info: &'a ResolveInfo<'a>,
) -> Result<ResolvedValue<'a>, FieldError>;
// Provided method
fn unknown_field_error(&self, info: &ResolveInfo<'_>) -> FieldError { ... }
}
Expand description
A concrete GraphQL object whose fields can be resolved during execution.
Required Methods§
Sourcefn type_name(&self) -> &str
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.
Sourcefn resolve_field<'a>(
&'a self,
info: &'a ResolveInfo<'a>,
) -> Result<ResolvedValue<'a>, FieldError>
fn resolve_field<'a>( &'a self, info: &'a ResolveInfo<'a>, ) -> Result<ResolvedValue<'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:
match info.field_name() {
"field1" => Ok(ResolvedValue::leaf(self.resolve_field1())),
"field2" => Ok(ResolvedValue::list(self.resolve_field2())),
_ => Err(self.unknown_field_error(info)),
}
Provided Methods§
Sourcefn unknown_field_error(&self, info: &ResolveInfo<'_>) -> FieldError
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.