Skip to main content

wesley_core/domain/
operation.rs

1//! GraphQL operation analysis data.
2
3use indexmap::IndexMap;
4use serde::{Deserialize, Serialize};
5
6use super::ir::TypeReference;
7
8/// Arguments extracted from a directive attached to a GraphQL operation.
9#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
10#[serde(rename_all = "camelCase")]
11pub struct OperationDirectiveArgs {
12    /// Directive name without the leading `@`.
13    pub directive_name: String,
14    /// Directive arguments represented as JSON-compatible values.
15    pub arguments: IndexMap<String, serde_json::Value>,
16}
17
18/// GraphQL root operation type.
19#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
20#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
21pub enum OperationType {
22    /// GraphQL query root field.
23    Query,
24    /// GraphQL mutation root field.
25    Mutation,
26    /// GraphQL subscription root field.
27    Subscription,
28}
29
30/// A field argument on a schema root operation.
31#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
32#[serde(rename_all = "camelCase")]
33pub struct OperationArgument {
34    /// Argument name.
35    pub name: String,
36    /// Argument type reference.
37    pub r#type: TypeReference,
38    /// Default value, if the schema declares one.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub default_value: Option<serde_json::Value>,
41    /// Generic map of directives attached to the argument.
42    pub directives: IndexMap<String, serde_json::Value>,
43}
44
45/// A root schema operation field described as domain-empty data.
46#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
47#[serde(rename_all = "camelCase")]
48pub struct SchemaOperation {
49    /// Root operation kind for the field.
50    pub operation_type: OperationType,
51    /// Root GraphQL object type that owns this operation field.
52    pub root_type_name: String,
53    /// Root field name.
54    pub field_name: String,
55    /// Root field arguments.
56    pub arguments: Vec<OperationArgument>,
57    /// Root field result type.
58    pub result_type: TypeReference,
59    /// Generic map of directives attached to the root field.
60    pub directives: IndexMap<String, serde_json::Value>,
61}