Skip to content

Commit

Permalink
Remove configurable layer support.
Browse files Browse the repository at this point in the history
We have decided to use plugins exclusively for now. The reason for this is that there was much confusion about when a layer should be used vs a plugin.
It also means that users will be steered towards service builder when adding functionality.
  • Loading branch information
bryn committed Mar 9, 2022
1 parent 3ad7de2 commit c5f9559
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 309 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- propagate:
matching: ".*"
```
- **Remove configurable layers** ([PR #603](https://github.com/apollographql/router/pull/603))
Having plugins and layers as configurable items in yaml was creating confusion as to when it was appropriate to
use a layer vs a plugin. As the layer API is a subset of the plugin API the layer option has been removed.
## 🚀 Features
## 🐛 Fixes
## 🛠 Maintenance
Expand Down
100 changes: 0 additions & 100 deletions apollo-router-core/src/layer.rs

This file was deleted.

2 changes: 0 additions & 2 deletions apollo-router-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ mod cache;
mod context;
mod error;
mod json_ext;
mod layer;
mod layers;
mod naive_introspection;
pub mod plugin;
Expand All @@ -45,7 +44,6 @@ pub use cache::*;
pub use context::*;
pub use error::*;
pub use json_ext::*;
pub use layer::*;
pub use layers::*;
pub use naive_introspection::*;
pub use plugin::*;
Expand Down
81 changes: 8 additions & 73 deletions apollo-router/src/configuration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! Logic for loading configuration in to an object model
use apollo_router_core::plugins;
use apollo_router_core::prelude::*;
use apollo_router_core::{layers, plugins};
use derivative::Derivative;
use displaydoc::Display;
use schemars::gen::SchemaGenerator;
use schemars::schema::{
ArrayValidation, ObjectValidation, Schema, SchemaObject, SingleOrVec, SubschemaValidation,
};
use schemars::schema::{ObjectValidation, Schema, SchemaObject, SubschemaValidation};
use schemars::{JsonSchema, Set};
use serde::{Deserialize, Serialize};
use serde_json::Map;
Expand Down Expand Up @@ -81,18 +79,7 @@ impl Configuration {
pub fn load_subgraphs(&self, schema: &graphql::Schema) -> HashMap<String, SubgraphConf> {
schema
.subgraphs()
.map(|(name, _subgraph_url)| {
(
name.to_owned(),
SubgraphConf {
layers: self
.subgraphs
.get(name)
.map(|s| s.layers.clone())
.unwrap_or_default(),
},
)
})
.map(|(name, _subgraph_url)| (name.to_owned(), SubgraphConf {}))
.collect()
}

Expand Down Expand Up @@ -161,69 +148,17 @@ impl JsonSchema for Plugins {

/// Configuration for a subgraph.
#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder)]
pub struct SubgraphConf {
/// Layer configuration
#[serde(default)]
#[builder(default)]
pub layers: Vec<Value>,
}
pub struct SubgraphConf {}

impl JsonSchema for SubgraphConf {
fn schema_name() -> String {
stringify!(Subgraph).to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
// This is a manual implementation of Subgraph schema to allow layers that have been registered at
// compile time to be picked up.
let mut subgraph = SchemaObject::default();

let layers = layers()
.iter()
.map(|(name, factory)| (name.to_string(), factory.create_schema(gen)))
.collect::<schemars::Map<String, Schema>>();
let layer_refs = layers
.keys()
.map(|name| {
Schema::Object(SchemaObject {
object: Some(Box::new(ObjectValidation {
required: Set::from([name.to_string()]),
..Default::default()
})),
..Default::default()
})
})
.collect::<Vec<_>>();

let layer_object = SchemaObject {
object: Some(Box::new(ObjectValidation {
properties: layers,
..Default::default()
})),
subschemas: Some(Box::new(SubschemaValidation {
one_of: Some(layer_refs),
..Default::default()
})),
..Default::default()
};

let layer_array = ArrayValidation {
items: Some(SingleOrVec::Single(Box::new(Schema::Object(layer_object)))),
..Default::default()
};

let layers_property = SchemaObject {
array: Some(Box::new(layer_array)),
..SchemaObject::default()
};

subgraph.object = Some(Box::new(ObjectValidation {
properties: schemars::Map::from([(
"layers".to_string(),
Schema::Object(layers_property),
)]),
..Default::default()
}));
let subgraph = SchemaObject::default();
Schema::Object(subgraph)
}
}
Expand Down Expand Up @@ -506,8 +441,8 @@ mod tests {
let configuration = Configuration::builder()
.subgraphs(
[
("inventory".to_string(), SubgraphConf { layers: Vec::new() }),
("products".to_string(), SubgraphConf { layers: Vec::new() }),
("inventory".to_string(), SubgraphConf {}),
("products".to_string(), SubgraphConf {}),
]
.iter()
.cloned()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 498
assertion_line: 395
expression: config

---
Expand All @@ -20,7 +20,6 @@ server:
- foo
- bar
subgraphs:
example:
layers: []
example: {}
plugins: {}

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 499
assertion_line: 396
expression: config

---
server:
listen: "1.2.3.4:5"
cors: ~
subgraphs:
example:
layers: []
example: {}
plugins: {}

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 500
assertion_line: 397
expression: config

---
server:
listen: "1.2.3.4:5"
cors: ~
subgraphs:
example:
layers: []
example: {}
plugins: {}

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 497
assertion_line: 394
expression: config

---
server:
listen: "1.2.3.4:5"
cors: ~
subgraphs:
example:
layers: []
example: {}
plugins: {}

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 526
assertion_line: 423
expression: config

---
server:
listen: "1.2.3.4:5"
cors: ~
subgraphs:
example:
layers: []
example: {}
plugins: {}

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 525
assertion_line: 422
expression: config

---
server:
listen: "1.2.3.4:5"
cors: ~
subgraphs:
example:
layers: []
example: {}
plugins: {}

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: apollo-router/src/configuration/mod.rs
assertion_line: 539
assertion_line: 436
expression: config

---
server:
listen: "1.2.3.4:5"
cors: ~
subgraphs:
example:
layers: []
example: {}
plugins: {}

Loading

0 comments on commit c5f9559

Please sign in to comment.