Skip to content

Commit

Permalink
fix: drop to_sdl from ConfigModule (#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed Jun 27, 2024
1 parent 9411c2c commit 9264f22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;

use super::telemetry::Telemetry;
use super::{ConfigModule, KeyValue, Link, Server, Upstream};
use super::{KeyValue, Link, Server, Upstream};
use crate::core::config::from_document::from_document;
use crate::core::config::source::Source;
use crate::core::directive::DirectiveCodec;
Expand Down Expand Up @@ -694,8 +694,9 @@ impl Config {
}
}

/// Renders current config to graphQL string
pub fn to_sdl(&self) -> String {
ConfigModule::from(self.clone()).to_sdl()
crate::core::document::print(self.into())
}

pub fn query(mut self, query: &str) -> Self {
Expand Down
5 changes: 0 additions & 5 deletions src/core/config/config_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ impl ConfigModule {
}
}

/// Renders current config to graphQL string
pub fn to_sdl(&self) -> String {
crate::core::document::print(self.into())
}

/// Normalizes current config with default preset
pub fn normalize_default(self) -> Valid<Self, String> {
// TODO: migrate to preset. That will change many snapshots in repo
Expand Down
14 changes: 8 additions & 6 deletions src/core/config/into_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_graphql::parser::types::*;
use async_graphql::{Pos, Positioned};
use async_graphql_value::{ConstValue, Name};

use super::ConfigModule;
use super::Config;
use crate::core::blueprint::TypeLike;
use crate::core::directive::DirectiveCodec;

Expand All @@ -14,7 +14,7 @@ fn transform_default_value(value: Option<serde_json::Value>) -> Option<ConstValu
value.map(ConstValue::from_json).and_then(Result::ok)
}

fn config_document(config: &ConfigModule) -> ServiceDocument {
fn config_document(config: &Config) -> ServiceDocument {
let mut definitions = Vec::new();
let mut directives = vec![
pos(config.server.to_directive()),
Expand Down Expand Up @@ -58,8 +58,10 @@ fn config_document(config: &ConfigModule) -> ServiceDocument {
.map(|name| pos(Name::new(name))),
};
definitions.push(TypeSystemDefinition::Schema(pos(schema_definition)));
let interface_types = config.interface_types();
let input_types = config.input_types();
for (type_name, type_def) in config.types.iter() {
let kind = if config.interface_types().contains(type_name) {
let kind = if interface_types.contains(type_name) {
TypeKind::Interface(InterfaceType {
implements: type_def
.implements
Expand Down Expand Up @@ -91,7 +93,7 @@ fn config_document(config: &ConfigModule) -> ServiceDocument {
})
.collect::<Vec<Positioned<FieldDefinition>>>(),
})
} else if config.input_types().contains(type_name) {
} else if input_types.contains(type_name) {
TypeKind::InputObject(InputObjectType {
fields: type_def
.fields
Expand Down Expand Up @@ -279,8 +281,8 @@ fn get_directives(field: &crate::core::config::Field) -> Vec<Positioned<ConstDir
directives.into_iter().flatten().collect()
}

impl From<&ConfigModule> for ServiceDocument {
fn from(value: &ConfigModule) -> Self {
impl From<&Config> for ServiceDocument {
fn from(value: &Config) -> Self {
config_document(value)
}
}

1 comment on commit 9264f22

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.80ms 3.10ms 94.82ms 73.01%
Req/Sec 3.72k 144.06 4.80k 89.00%

444048 requests in 30.02s, 2.23GB read

Requests/sec: 14792.97

Transfer/sec: 75.93MB

Please sign in to comment.