Skip to content

bug: dart types for queries with optional input fail to generate #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
supplier-storefront-dev opened this issue Apr 13, 2025 · 1 comment

Comments

@supplier-storefront-dev
Copy link

supplier-storefront-dev commented Apr 13, 2025

Provide environment information

[✓] Flutter (Channel stable, 3.29.2, on macOS 15.4 24E248 darwin-arm64, locale en-US) [747ms]
• Flutter version 3.29.2 on channel stable at /Users/user/code/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c236373904 (4 weeks ago), 2025-03-13 16:17:06 -0400
• Engine revision 18b71d647a
• Dart version 3.7.2
• DevTools version 2.42.3

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [466ms]
• Android SDK at /Users/user/Library/Android/sdk
✗ cmdline-tools component is missing
Run path/to/sdkmanager --install "cmdline-tools;latest"
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run flutter doctor --android-licenses to accept the SDK licenses.
See https://flutter.dev/to/macos-android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [1,031ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16E140
• CocoaPods version 1.16.2

[✓] Chrome - develop for the web [16ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3) [15ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29)

[✓] VS Code (version 1.99.1) [14ms]
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.108.0

[✓] Connected device (4 available) [6.2s]
• iPhone 16 Pro (mobile) • AC4C69F8-8A29-4995-9C45-D4686325872B • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-4
(simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.4 24E248 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.4 24E248 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 135.0.7049.85

[✓] Network resources [1,371ms]
• All expected network resources are available.

! Doctor found issues in 1 category.

Describe the bug

thanks for this tool. i'm happy to help debug but i am new to flutter. I would need some assistance on where to look. Some of my types are failing to generate when the input field to the trpc route is optional .

Link to reproduction

n/a

To reproduce

create a trpc router like so:

const GetSupplierRequest = z.object({
  ids: z.array(z.string()),
});
export const supplierRouter = createTRPCRouter({
  get: orgProcedure
    .input(GetSupplierRequest.optional())
    .query(async ({ ctx, input }) => {
// ...
    }),
});

follow commands from README

Additional information

json from trpc-extracted

    "supplier.get": {
      "path": "supplier.get",
      "routeType": "query",
      "input": {
        "anyOf": [
          {
            "not": {}
          },
          {
            "type": "object",
            "properties": {
              "ids": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "ids"
            ],
            "additionalProperties": false
          }
        ],
        "$schema": "http://json-schema.org/draft-07/schema#"
      },
      "output": null
    }

trpc.router.dart

class _R$supplier_get {
  final TRPCClient _client;
  const _R$supplier_get(this._client);
  Future<void> query(Supplier_getInput input) async {
    final response =
        await _client.query('supplier.get', payload: input.toJson());
    final returnData = response.unwrap();
  }
}
@polvallverdu
Copy link
Collaborator

Hey! Thank you for using trpc-client-dart. The JSON schema conversion is pretty limited, hopefully zod v4 solves this. In the meantime, can you try using nullable instead of optional?

So it would be:

const GetSupplierRequest = z.object({
  ids: z.array(z.string()),
});
export const supplierRouter = createTRPCRouter({
  get: orgProcedure
    .input(GetSupplierRequest.nullable())
    .query(async ({ ctx, input }) => {
// ...
    }),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants