forked from grafbase/grafbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
149 lines (140 loc) · 4.86 KB
/
lib.rs
File metadata and controls
149 lines (140 loc) · 4.86 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use federated_graph::FederatedGraphV1;
use latest::{HeaderForward, HeaderInsert, HeaderRule, HeaderRuleId};
// The specific version modules should be kept private, users of this crate
// should only access types via `latest`
mod v2;
mod v3;
mod v4;
mod v5;
/// The latest version of the configuration.
///
/// Users of the crate should always use this verison, and we can keep the details
/// of older versions isolated in this crate.
pub mod latest {
// If you introduce a new version you should update this export to the latest
pub use super::v5::*;
}
/// Configuration for engine-v2
///
/// This made up of a FederatedGraph and any additional configuration required by
/// engine-v2.
///
/// It's serialised and stored as JSON so we need to maintain backwards compatability
/// when making changes (or introduce a new version).
#[derive(serde::Serialize, serde::Deserialize)]
pub enum VersionedConfig {
/// The initial version of our configuration only contained the FederatedGraph.
V1(FederatedGraphV1),
/// V2 introduced some other configuration concerns
V2(v2::Config),
/// V3 is like V2 but with FederatedGraphV2
V3(v3::Config),
/// V4 is like V3 but with FederatedGraphV3
V4(v4::Config),
/// V5 is like V4, but with new header handling
V5(v5::Config),
}
impl VersionedConfig {
/// Converts a config of any version into whatever the latest version is.
pub fn into_latest(self) -> latest::Config {
match self {
VersionedConfig::V1(graph) => VersionedConfig::V2(v2::Config {
graph,
strings: Default::default(),
headers: Default::default(),
default_headers: Default::default(),
subgraph_configs: Default::default(),
cache: Default::default(),
auth: None,
operation_limits: Default::default(),
})
.into_latest(),
VersionedConfig::V2(v2::Config {
graph,
strings,
headers,
default_headers,
subgraph_configs,
cache,
auth,
operation_limits,
}) => VersionedConfig::V3(v3::Config {
graph: graph.into(),
strings,
headers,
default_headers,
subgraph_configs,
cache,
auth,
operation_limits,
disable_introspection: Default::default(),
})
.into_latest(),
VersionedConfig::V3(v3::Config {
graph,
strings,
headers,
default_headers,
subgraph_configs,
cache,
auth,
operation_limits,
disable_introspection,
}) => VersionedConfig::V4(v4::Config {
graph: graph.into(),
strings,
headers,
default_headers,
subgraph_configs,
cache,
auth,
operation_limits,
disable_introspection,
})
.into_latest(),
VersionedConfig::V4(v4::Config {
graph,
strings,
headers,
default_headers,
subgraph_configs,
cache,
auth,
operation_limits,
disable_introspection,
}) => {
let header_rules = headers
.into_iter()
.map(|header| match header.value {
v4::HeaderValue::Forward(value) => HeaderRule::Forward(HeaderForward {
name: header.name.into(),
default: None,
rename: Some(value),
}),
v4::HeaderValue::Static(value) => HeaderRule::Insert(HeaderInsert {
name: header.name,
value,
}),
})
.collect();
let default_header_rules = default_headers.into_iter().map(|id| HeaderRuleId(id.0)).collect();
v5::Config {
graph,
strings,
paths: Vec::new(),
header_rules,
default_header_rules,
subgraph_configs,
cache,
auth,
operation_limits,
disable_introspection,
rate_limit: Default::default(),
timeout: None,
entity_caching: Default::default(),
}
}
VersionedConfig::V5(latest) => latest,
}
}
}