medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
453 stars 31 forks source link

Unselected Fields Returning as null When Using select in Prisma Dart #436

Open Hackman-Adu opened 1 week ago

Hackman-Adu commented 1 week ago

What version of Prisma Dart is running?

5.2.0

What version of Prisma CLI is running?

5.20.0

What type of app are you using?

Dart Native (Server/CLI)

What database are you using?

MySQL

What steps can reproduce the bug?

var user = await prisma.user.findUnique(
  select: UserSelect(
    firstName: true, lastName: true, password: true, userId: true),
  where: UserWhereUniqueInput(emailAddress: 'user@example.com')
);

What is the expected behavior?

Only the selected fields (firstName, lastName, password, userId) should be returned.

What do you see instead?

Other unselected fields are also returned with null values.

Additional information

I encountered an issue where unselected fields are being returned as null in the response when using the select option with Prisma Dart. I expected Prisma to only return the fields I selected, but instead, it returns other fields as null.

medz commented 1 week ago

@Hackman-Adu Thanks for your feedback, but the requirement you reported cannot be implemented. (Maybe it will be implemented in the future when the macro is officially launched)

But for now, Dart does not distinguish between null input and no input. In Dart, they are all null types. We cannot dynamically construct the return type through select or include.

You should notice that in model.dart, all model classes are nullable fields.

I will keep this issue open and mark it as implementable when Dart supports it or we find other ways to support this behavior.

Hackman-Adu commented 1 week ago

@medz Thanks for the prompt response. Yes, I realized that the unavailability of Dart macros could be the reason behind this limitation. I just wanted to bring it to your attention.

Currently, as a workaround, I am using an extension on maps to handle and filter out null values when select is applied. I appreciate your consideration of this issue and look forward to future updates. Thanks again!