sui_graphql_rpc/types/
json.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::fmt;
5
6use async_graphql::*;
7
8/// Arbitrary JSON data.
9#[derive(Debug)]
10pub(crate) struct Json(Value);
11
12#[Scalar(name = "JSON", use_type_description = true)]
13impl ScalarType for Json {
14    fn parse(value: Value) -> InputValueResult<Self> {
15        Ok(Self(value))
16    }
17
18    fn to_value(&self) -> Value {
19        self.0.clone()
20    }
21}
22
23impl Description for Json {
24    fn description() -> &'static str {
25        "Arbitrary JSON data."
26    }
27}
28
29impl From<Value> for Json {
30    fn from(value: Value) -> Self {
31        Self(value)
32    }
33}
34
35impl fmt::Display for Json {
36    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37        self.0.fmt(f)
38    }
39}