diff --git a/birdie_snapshots/mutation_with_input_object_variable.accepted b/birdie_snapshots/mutation_with_input_object_variable.accepted index 813fbd0..c811153 100644 --- a/birdie_snapshots/mutation_with_input_object_variable.accepted +++ b/birdie_snapshots/mutation_with_input_object_variable.accepted @@ -8,6 +8,7 @@ import gleam/dynamic/decode import gleam/json import squall import gleam/option.{type Option, Some, None} +import gleam/list pub type ProfileInput { ProfileInput(display_name: Option(String), description: Option(String)) diff --git a/birdie_snapshots/mutation_with_json_scalar_in_input_object.accepted b/birdie_snapshots/mutation_with_json_scalar_in_input_object.accepted index 12a364c..4492ad2 100644 --- a/birdie_snapshots/mutation_with_json_scalar_in_input_object.accepted +++ b/birdie_snapshots/mutation_with_json_scalar_in_input_object.accepted @@ -9,6 +9,7 @@ import gleam/json import squall import gleam/option.{type Option, Some, None} import gleam/dynamic.{type Dynamic} +import gleam/list pub type SettingsInput { SettingsInput(metadata: Option(json.Json), display_name: Option(String)) diff --git a/birdie_snapshots/mutation_with_nested_input_object_types.accepted b/birdie_snapshots/mutation_with_nested_input_object_types.accepted index 5df3d45..4c62d25 100644 --- a/birdie_snapshots/mutation_with_nested_input_object_types.accepted +++ b/birdie_snapshots/mutation_with_nested_input_object_types.accepted @@ -8,6 +8,7 @@ import gleam/dynamic/decode import gleam/json import squall import gleam/option.{type Option, Some, None} +import gleam/list pub type BlobInput { BlobInput(data: String, mime_type: String) diff --git a/birdie_snapshots/mutation_with_optional_input_object_fields_(imports_some,_none).accepted b/birdie_snapshots/mutation_with_optional_input_object_fields_(imports_some,_none).accepted index f9e658c..265594c 100644 --- a/birdie_snapshots/mutation_with_optional_input_object_fields_(imports_some,_none).accepted +++ b/birdie_snapshots/mutation_with_optional_input_object_fields_(imports_some,_none).accepted @@ -8,6 +8,7 @@ import gleam/dynamic/decode import gleam/json import squall import gleam/option.{type Option, Some, None} +import gleam/list pub type ProfileInput { ProfileInput( diff --git a/src/squall/internal/codegen.gleam b/src/squall/internal/codegen.gleam index d3bfb23..2c8e9fc 100644 --- a/src/squall/internal/codegen.gleam +++ b/src/squall/internal/codegen.gleam @@ -207,6 +207,7 @@ fn imports_doc( needs_option: Bool, needs_dynamic: Bool, needs_option_constructors: Bool, + needs_list: Bool, ) -> Document { // Minimal imports - just what we need for decoders and the squall client let core_imports = [ @@ -226,8 +227,14 @@ fn imports_doc( False -> [] } + let list_imports = case needs_list { + True -> ["import gleam/list"] + False -> [] + } + list.append(core_imports, optional_imports) |> list.append(dynamic_imports) + |> list.append(list_imports) |> list.map(doc.from_string) |> doc.join(with: doc.line) } @@ -371,10 +378,20 @@ pub fn generate_operation( // Only check output fields for Dynamic usage (input fields use json.Json, not Dynamic) let needs_dynamic = detect_dynamic_usage(output_field_types) let needs_option_constructors = detect_optional_input_fields(input_types) + // Need gleam/list import when there are input types (for list.filter_map in serializers) + let needs_list = case input_types { + [] -> False + _ -> True + } // Build imports let imports = - imports_doc(needs_option, needs_dynamic, needs_option_constructors) + imports_doc( + needs_option, + needs_dynamic, + needs_option_constructors, + needs_list, + ) // Combine all code using doc combinators // Order: imports, input types, nested types, nested serializers, response type, response decoder, response serializer, function