Skip to content

Commit

Permalink
Merge branch 'main' into refactor/config_module
Browse files Browse the repository at this point in the history
  • Loading branch information
bnchi committed Jun 23, 2024
2 parents 0facc99 + 78b6cac commit 4cc0c52
Show file tree
Hide file tree
Showing 158 changed files with 428 additions and 502 deletions.
264 changes: 127 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benches/bench_synth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::Criterion;
use tailcall::core::ir::common::JsonPlaceholder;
use tailcall::core::jit::common::JsonPlaceholder;

pub fn bench_synth_nested(c: &mut Criterion) {
c.bench_function("synth_nested", |b| {
Expand Down
2 changes: 2 additions & 0 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
},
"protected": {
"description": "Marks field as protected by auth provider",
"default": null,
"anyOf": [
{
"$ref": "#/definitions/Protected"
Expand Down Expand Up @@ -1334,6 +1335,7 @@
},
"protected": {
"description": "Marks field as protected by auth providers",
"default": null,
"anyOf": [
{
"$ref": "#/definitions/Protected"
Expand Down
2 changes: 0 additions & 2 deletions src/cli/generator/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ pub struct UnResolved {}
pub struct Schema {
#[serde(skip_serializing_if = "Option::is_none")]
pub query: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mutation: Option<String>,
}

impl Output<UnResolved> {
Expand Down
13 changes: 10 additions & 3 deletions src/cli/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,19 @@ impl Generator {
pub async fn generate(self) -> anyhow::Result<ConfigModule> {
let config = self.read().await?;
let path = config.output.path.0.to_owned();
let query_type = config.schema.query.clone();
let preset: config::transformer::Preset = config.preset.clone().unwrap_or_default().into();
let input_samples = self.resolve_io(config).await?;
let config = ConfigGenerator::default()

let mut config_gen = ConfigGenerator::default()
.inputs(input_samples)
.transformers(vec![Box::new(preset)])
.generate(true)?;
.transformers(vec![Box::new(preset)]);
if let Some(query_type_name) = query_type {
// presently only query opeartion is supported.
config_gen = config_gen.operation_name(query_type_name);
}

let config = config_gen.generate(true)?;

self.write(&config, &path).await?;
Ok(config)
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::core::blueprint::Type::ListType;
use crate::core::blueprint::*;
use crate::core::config::{Config, Enum, Field, GraphQLOperationType, Protected, Union};
use crate::core::directive::DirectiveCodec;
use crate::core::ir::model::{Cache, Context, IR};
use crate::core::ir::model::{Cache, IR};
use crate::core::try_fold::TryFold;
use crate::core::valid::{Valid, Validator};
use crate::core::{config, scalar};
Expand Down Expand Up @@ -300,7 +300,7 @@ fn update_resolver_from_path(

process_path(context.clone()).and_then(|of_type| {
let mut updated_base_field = base_field;
let resolver = IR::Context(Context::Path(context.path.to_owned()));
let resolver = IR::ContextPath(context.path.to_owned());
if has_index {
updated_base_field.of_type =
Type::NamedType { name: of_type.name().to_string(), non_null: false }
Expand Down
18 changes: 9 additions & 9 deletions src/core/blueprint/dynamic_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use serde_json::Value;
use crate::core::mustache::Mustache;

#[derive(Debug, Clone)]
pub enum DynamicValue {
Value(ConstValue),
pub enum DynamicValue<A> {
Value(A),
Mustache(Mustache),
Object(IndexMap<Name, DynamicValue>),
Array(Vec<DynamicValue>),
Object(IndexMap<Name, DynamicValue<A>>),
Array(Vec<DynamicValue<A>>),
}

impl TryFrom<&DynamicValue> for ConstValue {
impl TryFrom<&DynamicValue<ConstValue>> for ConstValue {
type Error = anyhow::Error;

fn try_from(value: &DynamicValue) -> Result<Self, Self::Error> {
fn try_from(value: &DynamicValue<ConstValue>) -> Result<Self, Self::Error> {
match value {
DynamicValue::Value(v) => Ok(v.to_owned()),
DynamicValue::Mustache(_) => Err(anyhow::anyhow!(
Expand All @@ -37,7 +37,7 @@ impl TryFrom<&DynamicValue> for ConstValue {
}
}

impl DynamicValue {
impl<A> DynamicValue<A> {
// Helper method to determine if the value is constant (non-mustache).
pub fn is_const(&self) -> bool {
match self {
Expand All @@ -49,7 +49,7 @@ impl DynamicValue {
}
}

impl TryFrom<&Value> for DynamicValue {
impl TryFrom<&Value> for DynamicValue<ConstValue> {
type Error = anyhow::Error;

fn try_from(value: &Value) -> Result<Self, Self::Error> {
Expand All @@ -63,7 +63,7 @@ impl TryFrom<&Value> for DynamicValue {
Ok(DynamicValue::Object(out))
}
Value::Array(arr) => {
let out: Result<Vec<DynamicValue>, Self::Error> =
let out: Result<Vec<DynamicValue<ConstValue>>, Self::Error> =
arr.iter().map(DynamicValue::try_from).collect();
Ok(DynamicValue::Array(out?))
}
Expand Down
6 changes: 1 addition & 5 deletions src/core/blueprint/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ use crate::core::blueprint::{
///
/// A read optimized index of all the fields in the Blueprint. Provide O(1)
/// access to getting any field information.
#[allow(unused)]

pub struct Index {
map: HashMap<String, (Definition, HashMap<String, QueryField>)>,
schema: SchemaDefinition,
}

#[allow(unused)]
#[derive(Debug)]
pub enum QueryField {
Field((FieldDefinition, HashMap<String, InputFieldDefinition>)),
InputField(InputFieldDefinition),
}

#[allow(unused)]
impl QueryField {
pub fn get_arg(&self, arg_name: &str) -> Option<&InputFieldDefinition> {
match self {
Expand All @@ -31,7 +29,6 @@ impl QueryField {
}

impl Index {
#[allow(unused)]
pub fn get_field(&self, type_name: &str, field_name: &str) -> Option<&QueryField> {
self.map
.get(type_name)
Expand All @@ -42,7 +39,6 @@ impl Index {
&self.schema.query
}

#[allow(unused)]
pub fn get_mutation(&self) -> Option<&str> {
self.schema.mutation.as_deref()
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/operators/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn compile_call(
)
.map(|(mut b_field, args_expr)| {
if !step.args.is_empty() {
b_field.map_expr(|expr| args_expr.clone().and_then(expr));
b_field.map_expr(|expr| args_expr.clone().pipe(expr));
}

b_field
Expand All @@ -120,7 +120,7 @@ fn compile_call(
b_field_next
.resolver
.as_ref()
.map(|other_expr| expr.clone().and_then(other_expr.clone()))
.map(|other_expr| expr.clone().pipe(other_expr.clone()))
.unwrap_or(expr)
});

Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/operators/modify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::blueprint::*;
use crate::core::config;
use crate::core::config::Field;
use crate::core::ir::model::{Context, IR};
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;

Expand All @@ -25,7 +25,7 @@ pub fn update_modify<'a>(
b_field.resolver = Some(
b_field
.resolver
.unwrap_or(IR::Context(Context::Path(vec![b_field.name.clone()]))),
.unwrap_or(IR::ContextPath(vec![b_field.name.clone()])),
);
b_field = b_field.name(new_name.clone());
}
Expand Down
11 changes: 6 additions & 5 deletions src/core/blueprint/operators/protected.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::blueprint::FieldDefinition;
use crate::core::config::{self, ConfigModule, Field};
use crate::core::ir::model::{Context, IR};
use crate::core::ir::model::IR;
use crate::core::try_fold::TryFold;
use crate::core::valid::Valid;

Expand All @@ -27,10 +27,11 @@ pub fn update_protected<'a>(
);
}

b_field.resolver =
Some(IR::Protect(Box::new(b_field.resolver.unwrap_or(
IR::Context(Context::Path(vec![b_field.name.clone()])),
))));
b_field.resolver = Some(IR::Protect(Box::new(
b_field
.resolver
.unwrap_or(IR::ContextPath(vec![b_field.name.clone()])),
)));
}

Valid::succeed(b_field)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/config/transformer/ambiguous_type.rs
expression: config_module.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/config/transformer/ambiguous_type.rs
expression: config_module.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: src/core/generator/tests/json_to_config_spec.rs
expression: cfg_module.config.to_sdl()
expression: config.to_sdl()
---
schema @server @upstream {
query: Query
Expand Down
30 changes: 10 additions & 20 deletions src/core/ir/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::pin::Pin;
use async_graphql_value::ConstValue;

use super::eval_io::eval_io;
use super::model::{Cache, CacheKey, Context, Map, IR};
use super::model::{Cache, CacheKey, Map, IR};
use super::{Error, EvalContext, ResolverContextLike};
use crate::core::json::JsonLike;
use crate::core::serde_value_ext::ValueExt;
Expand All @@ -21,25 +21,10 @@ impl IR {
{
Box::pin(async move {
match self {
IR::Context(op) => match op {
Context::Value => {
Ok(ctx.value().cloned().unwrap_or(async_graphql::Value::Null))
}
Context::Path(path) => Ok(ctx
.path_value(path)
.map(|a| a.into_owned())
.unwrap_or(async_graphql::Value::Null)),
Context::PushArgs { expr, and_then } => {
let args = expr.eval(&mut ctx.clone()).await?;
let ctx = &mut ctx.with_args(args);
and_then.eval(ctx).await
}
Context::PushValue { expr, and_then } => {
let value = expr.eval(&mut ctx.clone()).await?;
ctx.with_value(value);
and_then.eval(ctx).await
}
},
IR::ContextPath(path) => Ok(ctx
.path_value(path)
.map(|a| a.into_owned())
.unwrap_or(async_graphql::Value::Null)),
IR::Path(input, path) => {
let inp = &input.eval(ctx).await?;
Ok(inp
Expand Down Expand Up @@ -93,6 +78,11 @@ impl IR {
))
}
}
IR::Pipe(first, second) => {
let args = first.eval(&mut ctx.clone()).await?;
let ctx = &mut ctx.with_args(args);
second.eval(ctx).await
}
}
})
}
Expand Down
Loading

0 comments on commit 4cc0c52

Please sign in to comment.