Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored Aug 26, 2024
2 parents 61a1d28 + 648c018 commit be6bdac
Show file tree
Hide file tree
Showing 58 changed files with 562 additions and 349 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/core/blueprint/from_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};

use async_graphql::dynamic::SchemaBuilder;
use indexmap::IndexMap;

use self::telemetry::to_opentelemetry;
use super::{Server, TypeLike};
Expand Down Expand Up @@ -70,7 +71,7 @@ pub fn apply_batching(mut blueprint: Blueprint) -> Blueprint {
pub fn to_json_schema_for_field(field: &Field, config: &Config) -> JsonSchema {
to_json_schema(field, config)
}
pub fn to_json_schema_for_args(args: &BTreeMap<String, Arg>, config: &Config) -> JsonSchema {
pub fn to_json_schema_for_args(args: &IndexMap<String, Arg>, config: &Config) -> JsonSchema {
let mut schema_fields = BTreeMap::new();
for (name, arg) in args.iter() {
schema_fields.insert(name.clone(), to_json_schema(arg, config));
Expand Down
39 changes: 16 additions & 23 deletions src/core/blueprint/into_schema.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;
use std::sync::Arc;

use anyhow::{bail, Result};
use async_graphql::dynamic::{self, FieldFuture, FieldValue, SchemaBuilder};
use async_graphql::ErrorExtensions;
use async_graphql_value::ConstValue;
Expand All @@ -11,7 +10,7 @@ use tracing::Instrument;

use crate::core::blueprint::{Blueprint, Definition, Type};
use crate::core::http::RequestContext;
use crate::core::ir::{EvalContext, ResolverContext, TypeName};
use crate::core::ir::{EvalContext, ResolverContext, TypedValue};
use crate::core::scalar;

fn to_type_ref(type_of: &Type) -> dynamic::TypeRef {
Expand Down Expand Up @@ -59,27 +58,21 @@ fn set_default_value(
}
}

fn to_field_value<'a>(
ctx: &mut EvalContext<'a, ResolverContext<'a>>,
value: async_graphql::Value,
) -> Result<FieldValue<'static>> {
let type_name = ctx.type_name.take();

Ok(match (value, type_name) {
// NOTE: Mostly type_name is going to be None so we should keep that as the first check.
(value, None) => FieldValue::from(value),
(ConstValue::List(values), Some(TypeName::Vec(names))) => FieldValue::list(
values
.into_iter()
.zip(names)
.map(|(value, type_name)| FieldValue::from(value).with_type(type_name)),
),
(value @ ConstValue::Object(_), Some(TypeName::Single(type_name))) => {
FieldValue::from(value).with_type(type_name)
fn to_field_value(value: async_graphql::Value) -> FieldValue<'static> {
match value {
ConstValue::List(vec) => FieldValue::list(vec.into_iter().map(to_field_value)),
value => {
let type_name = value.get_type_name().map(|s| s.to_string());

let field_value = FieldValue::from(value);

if let Some(type_name) = type_name {
field_value.with_type(type_name)
} else {
field_value
}
}
(ConstValue::Null, _) => FieldValue::NULL,
(_, Some(_)) => bail!("Failed to match type_name"),
})
}
}

fn to_type(def: &Definition) -> dynamic::Type {
Expand Down Expand Up @@ -131,7 +124,7 @@ fn to_type(def: &Definition) -> dynamic::Type {
if let ConstValue::Null = value {
Ok(FieldValue::NONE)
} else {
Ok(Some(to_field_value(ctx, value)?))
Ok(Some(to_field_value(value)))
}
}
.instrument(span)
Expand Down
6 changes: 4 additions & 2 deletions src/core/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::fmt::{self, Display};
use std::num::NonZeroU64;

use anyhow::Result;
use async_graphql::parser::types::{ConstDirective, ServiceDocument};
use async_graphql::Positioned;
use derive_setters::Setters;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tailcall_macros::{CustomResolver, DirectiveDefinition, InputDefinition};
Expand Down Expand Up @@ -254,7 +255,8 @@ pub struct Field {
///
/// Map of argument name and its definition.
#[serde(default, skip_serializing_if = "is_default")]
pub args: BTreeMap<String, Arg>,
#[schemars(with = "HashMap::<String, Arg>")]
pub args: IndexMap<String, Arg>,

///
/// Publicly visible documentation for the field.
Expand Down
9 changes: 5 additions & 4 deletions src/core/config/from_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use async_graphql::parser::types::{
use async_graphql::parser::Positioned;
use async_graphql::Name;
use async_graphql_value::ConstValue;
use indexmap::IndexMap;

use super::telemetry::Telemetry;
use super::Alias;
Expand Down Expand Up @@ -294,7 +295,7 @@ fn to_field(field_definition: &FieldDefinition) -> Valid<config::Field, String>
fn to_input_object_field(field_definition: &InputValueDefinition) -> Valid<config::Field, String> {
to_common_field(
field_definition,
BTreeMap::new(),
IndexMap::new(),
field_definition
.default_value
.as_ref()
Expand All @@ -303,7 +304,7 @@ fn to_input_object_field(field_definition: &InputValueDefinition) -> Valid<confi
}
fn to_common_field<F>(
field: &F,
args: BTreeMap<String, config::Arg>,
args: IndexMap<String, config::Arg>,
default_value: Option<ConstValue>,
) -> Valid<config::Field, String>
where
Expand Down Expand Up @@ -356,8 +357,8 @@ fn to_type_of(type_: &Type) -> String {
BaseType::List(ty) => to_type_of(ty),
}
}
fn to_args(field_definition: &FieldDefinition) -> BTreeMap<String, config::Arg> {
let mut args: BTreeMap<String, config::Arg> = BTreeMap::new();
fn to_args(field_definition: &FieldDefinition) -> IndexMap<String, config::Arg> {
let mut args = IndexMap::new();

for arg in field_definition.arguments.iter() {
let arg_name = pos_name_to_string(&arg.node.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ type NU {
}

type Query {
testVar0Var0(nnu: NNU__nu0, nu: NU__u0!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar0Var1(nnu: NNU__nu0, nu: NU__u1!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar0Var2(nnu: NNU__nu0, nu: NU__u2!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar1Var0(nnu: NNU__nu1, nu: NU__u0!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar1Var1(nnu: NNU__nu1, nu: NU__u1!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar1Var2(nnu: NNU__nu1, nu: NU__u2!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar2Var0(nnu: NNU__nu2, nu: NU__u0!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar2Var1(nnu: NNU__nu2, nu: NU__u1!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar2Var2(nnu: NNU__nu2, nu: NU__u2!): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar0Var0(nu: NU__u0!, nnu: NNU__nu0): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar0Var1(nu: NU__u0!, nnu: NNU__nu1): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar0Var2(nu: NU__u0!, nnu: NNU__nu2): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar1Var0(nu: NU__u1!, nnu: NNU__nu0): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar1Var1(nu: NU__u1!, nnu: NNU__nu1): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar1Var2(nu: NU__u1!, nnu: NNU__nu2): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar2Var0(nu: NU__u2!, nnu: NNU__nu0): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar2Var1(nu: NU__u2!, nnu: NNU__nu1): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
testVar2Var2(nu: NU__u2!, nnu: NNU__nu2): U @http(baseURL: "http://localhost", path: "/users/{{args.nu.u}}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ input T4 {
}

type Mutation {
addCart(addCartInput: T4, code: String): T2 @http(baseURL: "https://dummyjson.com", body: "{{.args.addCartInput}}", method: "POST", path: "/carts/add", query: [{key: "code", value: "{{.args.code}}"}])
addCart(code: String, addCartInput: T4): T2 @http(baseURL: "https://dummyjson.com", body: "{{.args.addCartInput}}", method: "POST", path: "/carts/add", query: [{key: "code", value: "{{.args.code}}"}])
}

type T1 {
Expand Down
Loading

0 comments on commit be6bdac

Please sign in to comment.