1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
//! Custom scalar trait and validation for user-defined scalars.
//!
//! This module provides a trait-based system for defining custom GraphQL scalars
//! at runtime, allowing applications to implement their own validation logic.
//!
//! # Example
//!
//! ```
//! use fraiseql_core::validation::CustomScalar;
//! use fraiseql_core::error::{FraiseQLError, Result};
//! use serde_json::Value;
//!
//! #[derive(Debug)]
//! struct Email;
//!
//! impl CustomScalar for Email {
//! fn name(&self) -> &str {
//! "Email"
//! }
//!
//! fn serialize(&self, value: &Value) -> Result<Value> {
//! Ok(value.clone())
//! }
//!
//! fn parse_value(&self, value: &Value) -> Result<Value> {
//! let str_val = value.as_str()
//! .ok_or_else(|| FraiseQLError::parse("expected string"))?;
//!
//! if !str_val.contains('@') {
//! return Err(FraiseQLError::validation(
//! format!("invalid email format: {}", str_val)
//! ));
//! }
//!
//! Ok(Value::String(str_val.to_string()))
//! }
//!
//! fn parse_literal(&self, ast: &Value) -> Result<Value> {
//! self.parse_value(ast)
//! }
//! }
//!
//! let email = Email;
//! assert_eq!(email.name(), "Email");
//! ```
use fmt;
use Value;
use crateResult;
/// Trait for implementing custom GraphQL scalar types.
///
/// Implement this trait to create custom scalars with validation logic.
/// Each method represents a different validation context in GraphQL.
/// Result of custom scalar validation.
pub type CustomScalarResult = ;