pub struct Scalar { /* private fields */ }
Available on crate feature dynamic-schema only.
Expand description

A GraphQL scalar type

Examples

use async_graphql::{dynamic::*, value, Value};

let my_scalar = Scalar::new("MyScalar");

let query = Object::new("Query").field(Field::new("value", TypeRef::named_nn(my_scalar.type_name()), |ctx| {
    FieldFuture::new(async move { Ok(Some(Value::from("abc"))) })
}));


let schema = Schema::build(query.type_name(), None, None)
    .register(my_scalar)
    .register(query)
    .finish()?;

assert_eq!(
   schema
       .execute("{ value }")
       .await
       .into_result()
       .unwrap()
       .data,
   value!({ "value": "abc" })
);

Implementations§

Create a GraphQL scalar type

Examples found in repository?
src/dynamic/schema.rs (line 159)
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
    pub fn finish(mut self) -> Result<Schema, SchemaError> {
        let mut registry = Registry {
            types: Default::default(),
            directives: Default::default(),
            implements: Default::default(),
            query_type: self.query_type,
            mutation_type: self.mutation_type,
            subscription_type: self.subscription_type,
            introspection_mode: self.introspection_mode,
            enable_federation: false,
            federation_subscription: false,
            ignore_name_conflicts: Default::default(),
            enable_suggestions: self.enable_suggestions,
        };
        registry.add_system_types();

        for ty in self.types.values() {
            ty.register(&mut registry)?;
        }
        update_interface_possible_types(&mut self.types, &mut registry);

        // create system scalars
        for ty in ["Int", "Float", "Boolean", "String", "ID"] {
            self.types
                .insert(ty.to_string(), Type::Scalar(Scalar::new(ty)));
        }

        // create introspection types
        if matches!(
            self.introspection_mode,
            IntrospectionMode::Enabled | IntrospectionMode::IntrospectionOnly
        ) {
            registry.create_introspection_types();
        }

        // create entity types
        if self.enable_federation || registry.has_entities() {
            registry.enable_federation = true;
            registry.create_federation_types();
        }

        let inner = SchemaInner {
            env: SchemaEnv(Arc::new(SchemaEnvInner {
                registry,
                data: self.data,
                custom_directives: Default::default(),
            })),
            extensions: self.extensions,
            types: self.types,
            recursive_depth: self.recursive_depth,
            complexity: self.complexity,
            depth: self.depth,
            validation_mode: self.validation_mode,
            entity_resolver: self.entity_resolver,
        };
        inner.check()?;
        Ok(Schema(Arc::new(inner)))
    }

Set the description

Indicate that an enum is not accessible from a supergraph when using Apollo Federation

Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#inaccessible

Arbitrary string metadata that will be propagated to the supergraph when using Apollo Federation. This attribute is repeatable

Reference: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#applying-metadata

Set the validator

Set the specified by url

Returns the type name

Trait Implementations§

Formats the value using the given formatter. Read more
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more