Skip to content

Commit

Permalink
fix: tailcall generation schema for non required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Dec 6, 2024
1 parent 6ca5788 commit b771a41
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
16 changes: 8 additions & 8 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ directive @graphQL(
argument to batch several requests into a single batch request.Make sure you have
also specified batch settings to the `@upstream` and to the `@graphQL` operator.
"""
batch: Boolean!
batch: Boolean
"""
Enables deduplication of IO operations to enhance performance.This flag prevents
duplicate IO requests from being executed concurrently, reducing resource load. Caution:
Expand Down Expand Up @@ -269,7 +269,7 @@ directive @link(
The source of the link. It can be a URL or a path to a file. If a path is provided,
it is relative to the file that imports the link.
"""
src: String!
src: String
"""
The type of the link. It can be `Config`, or `Protobuf`.
"""
Expand Down Expand Up @@ -728,8 +728,8 @@ input Headers {
}

input Routes {
graphQL: String!
status: String!
graphQL: String
status: String
}

input ScriptOptions {
Expand Down Expand Up @@ -772,7 +772,7 @@ Output the telemetry metrics data to prometheus server
"""
input PrometheusExporter {
format: PrometheusFormat
path: String!
path: String
}

"""
Expand All @@ -782,7 +782,7 @@ input StdoutExporter {
"""
Output to stdout in pretty human-readable format
"""
pretty: Boolean!
pretty: Boolean
}

input TelemetryExporter {
Expand All @@ -793,7 +793,7 @@ input TelemetryExporter {
}

input Batch {
delay: Int!
delay: Int
headers: [String!]
maxSize: Int
}
Expand All @@ -816,7 +816,7 @@ input GraphQL {
argument to batch several requests into a single batch request.Make sure you have
also specified batch settings to the `@upstream` and to the `@graphQL` operator.
"""
batch: Boolean!
batch: Boolean
"""
Enables deduplication of IO operations to enhance performance.This flag prevents
duplicate IO requests from being executed concurrently, reducing resource load. Caution:
Expand Down
5 changes: 1 addition & 4 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,7 @@
},
"dedupe": {
"description": "Enables deduplication of IO operations to enhance performance.\n\nThis flag prevents duplicate IO requests from being executed concurrently, reducing resource load. Caution: May lead to issues with APIs that expect unique results for identical inputs, such as nonce-based APIs.",
"type": [
"boolean",
"null"
]
"type": "boolean"
},
"headers": {
"description": "The headers parameter allows you to customize the headers of the GraphQL request made by the `@graphQL` operator. It is used by specifying a key-value map of header names and their values.",
Expand Down
2 changes: 1 addition & 1 deletion src/core/blueprint/operators/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn compile_graphql(
.map(|req_template| {
let field_name = graphql.name.clone();
let batch = graphql.batch;
let dedupe = graphql.dedupe.unwrap_or_default();
let dedupe = graphql.dedupe;
IR::IO(IO::GraphQL { req_template, field_name, batch, dl_id: None, dedupe })
})
}
2 changes: 1 addition & 1 deletion src/core/config/directives/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ pub struct GraphQL {
/// concurrently, reducing resource load. Caution: May lead to issues
/// with APIs that expect unique results for identical inputs, such as
/// nonce-based APIs.
pub dedupe: Option<bool>,
pub dedupe: bool,
}
2 changes: 1 addition & 1 deletion tailcall-typedefs-common/src/directive_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn into_directive_definition(
TypeSystemDefinition::Directive(pos(async_graphql::parser::types::DirectiveDefinition {
description: description.map(|inner| pos(inner.clone())),
name: pos(Name::new(name)),
arguments: into_input_value_definition(&schema),
arguments: into_input_value_definition(schema),
is_repeatable: attrs.repeatable,
locations: attrs
.locations
Expand Down
47 changes: 25 additions & 22 deletions tailcall-typedefs-common/src/input_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ pub trait InputDefinition {
}

pub fn into_input_definition(schema: SchemaObject, name: &str) -> TypeSystemDefinition {
let description = get_description(&schema);
let description = get_description(&schema).cloned();

TypeSystemDefinition::Type(pos(TypeDefinition {
name: pos(Name::new(name)),
kind: TypeKind::InputObject(InputObjectType {
fields: into_input_value_definition(&schema),
fields: into_input_value_definition(schema),
}),
description: description.map(|inner| pos(inner.clone())),
description: description.map(pos),
directives: vec![],
extend: false,
}))
}

pub fn into_input_value_definition(schema: &SchemaObject) -> Vec<Positioned<InputValueDefinition>> {
pub fn into_input_value_definition(schema: SchemaObject) -> Vec<Positioned<InputValueDefinition>> {
let mut arguments_type = vec![];
if let Some(subschema) = schema.subschemas.clone() {
let list = subschema.any_of.or(subschema.all_of).or(subschema.one_of);
if let Some(list) = list {
for schema in list {
let schema_object = schema.into_object();
arguments_type.extend(build_arguments_type(&schema_object));
arguments_type.extend(build_arguments_type(schema_object));

Check warning on line 37 in tailcall-typedefs-common/src/input_definition.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-typedefs-common/src/input_definition.rs#L37

Added line #L37 was not covered by tests
}

return arguments_type;
Expand All @@ -44,22 +44,19 @@ pub fn into_input_value_definition(schema: &SchemaObject) -> Vec<Positioned<Inpu
build_arguments_type(schema)
}

fn build_arguments_type(schema: &SchemaObject) -> Vec<Positioned<InputValueDefinition>> {
fn build_arguments_type(schema: SchemaObject) -> Vec<Positioned<InputValueDefinition>> {
let mut arguments = vec![];
if let Some(properties) = schema
.object
.as_ref()
.map(|object| object.properties.clone())
{
for (name, property) in properties.into_iter() {
if let Some(obj) = schema.object {
let required = obj.required;
for (name, property) in obj.properties.into_iter() {
let property = property.into_object();
let description = get_description(&property);
let nullable = !required.contains(&name);
let definition = pos(InputValueDefinition {
description: description.map(|inner| pos(inner.to_owned())),
name: pos(Name::new(&name)),
ty: pos(determine_input_value_type_from_schema(
name,
property.clone(),
name, &property, nullable,
)),
default_value: None,
directives: Vec::new(),
Expand All @@ -72,7 +69,11 @@ fn build_arguments_type(schema: &SchemaObject) -> Vec<Positioned<InputValueDefin
arguments
}

fn determine_input_value_type_from_schema(mut name: String, schema: SchemaObject) -> Type {
fn determine_input_value_type_from_schema(
mut name: String,
schema: &SchemaObject,
nullable: bool,
) -> Type {
first_char_to_upper(&mut name);
if let Some(instance_type) = &schema.instance_type {
match instance_type {
Expand All @@ -82,25 +83,25 @@ fn determine_input_value_type_from_schema(mut name: String, schema: SchemaObject
| InstanceType::Number
| InstanceType::String
| InstanceType::Integer => Type {
nullable: false,
nullable,
base: BaseType::Named(Name::new(get_instance_type_name(typ))),
},
_ => determine_type_from_schema(name, &schema),
_ => determine_type_from_schema(name, schema),
},
SingleOrVec::Vec(typ) => match typ.first().unwrap() {
InstanceType::Null
| InstanceType::Boolean
| InstanceType::Number
| InstanceType::String
| InstanceType::Integer => Type {
nullable: true,
nullable,
base: BaseType::Named(Name::new(get_instance_type_name(typ.first().unwrap()))),
},
_ => determine_type_from_schema(name, &schema),
_ => determine_type_from_schema(name, schema),

Check warning on line 100 in tailcall-typedefs-common/src/input_definition.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-typedefs-common/src/input_definition.rs#L100

Added line #L100 was not covered by tests
},
}
} else {
determine_type_from_schema(name, &schema)
determine_type_from_schema(name, schema)
}
}

Expand Down Expand Up @@ -145,14 +146,16 @@ fn determine_type_from_arr_valid(name: String, array_valid: &ArrayValidation) ->
nullable: true,
base: BaseType::List(Box::new(determine_input_value_type_from_schema(
name,
schema.clone().into_object(),
&schema.clone().into_object(),
false,
))),
},
SingleOrVec::Vec(schemas) => Type {
nullable: true,
base: BaseType::List(Box::new(determine_input_value_type_from_schema(
name,
schemas[0].clone().into_object(),
&schemas[0].clone().into_object(),
false,

Check warning on line 158 in tailcall-typedefs-common/src/input_definition.rs

View check run for this annotation

Codecov / codecov/patch

tailcall-typedefs-common/src/input_definition.rs#L157-L158

Added lines #L157 - L158 were not covered by tests
))),
},
}
Expand Down

0 comments on commit b771a41

Please sign in to comment.