apollo_supergraph_config/subgraph.rs
1use camino::Utf8PathBuf;
2use serde::{Deserialize, Serialize};
3use url::Url;
4
5/// Config for a single [subgraph](https://www.apollographql.com/docs/federation/subgraphs/)
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct SubgraphConfig {
8 /// The routing URL for the subgraph.
9 /// This will appear in supergraph SDL and
10 /// instructs the graph router to send all requests
11 /// for this subgraph to this URL.
12 pub routing_url: Option<String>,
13
14 /// The location of the subgraph's SDL
15 pub schema: SchemaSource,
16}
17
18impl SubgraphConfig {
19 /// Returns SDL from the configuration file if it exists.
20 /// Returns None if the configuration does not include raw SDL.
21 pub fn get_sdl(&self) -> Option<String> {
22 if let SchemaSource::Sdl { sdl } = &self.schema {
23 Some(sdl.to_owned())
24 } else {
25 None
26 }
27 }
28}
29
30/// Options for getting SDL:
31/// the graph registry, a file, or an introspection URL.
32///
33/// NOTE: Introspection strips all comments and directives
34/// from the SDL.
35#[derive(Debug, Clone, Serialize, Deserialize)]
36// this is untagged, meaning its fields will be flattened into the parent
37// struct when de/serialized. There is no top level `schema_source`
38// in the configuration.
39#[serde(untagged)]
40pub enum SchemaSource {
41 File { file: Utf8PathBuf },
42 SubgraphIntrospection { subgraph_url: Url },
43 Subgraph { graphref: String, subgraph: String },
44 Sdl { sdl: String },
45}