pub enum Value {
Null,
Boolean(bool),
Int(i32),
BigInt(Box<i128>),
Float(f64),
String(Arc<str>),
Enum(Arc<str>),
List(Vec<Value>),
Object(Arc<Object>),
External(External),
}Expand description
A GraphQL input or result value.
Variants§
Null
The explicit null value.
Boolean(bool)
A boolean.
Int(i32)
A 32-bit signed integer. GraphQL’s built-in Int is 32-bit.
BigInt(Box<i128>)
An integer that does not fit in GraphQL’s built-in 32-bit Int.
Document literals can carry integers up to i128 and JSON transports preserve 64-bit
integers. Keeping them as an exact integer lets a custom scalar receive them unchanged,
lets Float widen them to a double, and lets ID render them as a decimal string.
The built-in Int scalar rejects a BigInt outside its 32-bit range at coercion time.
The value is boxed so this variant does not widen Value on every other value and
stack frame; use Value::integer to construct one and Value::as_i128 to read it.
Float(f64)
A 64-bit IEEE-754 floating point number.
String(Arc<str>)
A string.
Enum(Arc<str>)
The name of an enum value.
List(Vec<Value>)
An ordered list.
Object(Arc<Object>)
An object: an ordered sequence of distinct field names and values.
External(External)
An opaque Rust value produced by a higher-level API.
Executors never serialize this variant directly. It exists so a type-safe schema builder
can pass its own model types (for example a User struct) between resolvers while the
engine stays completely generic. An object type with a resolver accepts it as the parent
value; the high-level layer downcasts it with External::downcast_ref.
Implementations§
Source§impl Value
impl Value
Sourcepub fn string(value: impl Into<Arc<str>>) -> Value
pub fn string(value: impl Into<Arc<str>>) -> Value
Construct a string value from anything string-like.
Sourcepub fn enumeration(value: impl Into<Arc<str>>) -> Value
pub fn enumeration(value: impl Into<Arc<str>>) -> Value
Construct an enum value from an enum variant name.
Sourcepub fn integer(value: i128) -> Value
pub fn integer(value: i128) -> Value
Construct an integer value, narrowing to Value::Int when it fits.
Sourcepub const fn kind(&self) -> &'static str
pub const fn kind(&self) -> &'static str
The name of the value’s GraphQL-ish kind, used in error messages.
Sourcepub const fn as_i32(&self) -> Option<i32>
pub const fn as_i32(&self) -> Option<i32>
Borrow the value as an i32.
A Value::BigInt also converts when it fits, so callers that accept the built-in Int
range do not have to spell out both variants.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Borrow the value as an f64.
Integers widen exactly as the Float scalar does. Values outside i128 are not
representable by this type at all.
Sourcepub fn as_object_mut(&mut self) -> Option<&mut Object>
pub fn as_object_mut(&mut self) -> Option<&mut Object>
Mutably borrow the value as an object.
Sourcepub const fn is_external(&self) -> bool
pub const fn is_external(&self) -> bool
Whether this is an opaque model value.
Sourcepub fn as_external<T>(&self) -> Option<&T>where
T: Any,
pub fn as_external<T>(&self) -> Option<&T>where
T: Any,
Borrow an opaque model value as a concrete type.
Sourcepub fn into_string(self) -> Option<Arc<str>>
pub fn into_string(self) -> Option<Arc<str>>
Turn the value into a string, if it is one.
Trait Implementations§
Source§impl Serialize for Value
Available on crate feature serde only.
impl Serialize for Value
serde only.