Prisma-client-js: Array types

Created on 15 Oct 2019  路  11Comments  路  Source: prisma/prisma-client-js

As you tell me @divyenduz I create an issue for a follow up on this one https://github.com/prisma/photonjs/issues/256

Why array types are | null and not simple empty array?

bu2-confirmed kinbug

Most helpful comment

AHAH yes thats PERFECT

All 11 comments

@yovanoc Can you please provide an example?

I think it depends on the type (an array can be a nullable array (| null case) or a non-nullable array [] empty array case).

If I understand correctly, please share an example of what you mean.

I just sent you an email

I checked this out and arrays are not | null

Also, the schema doesn't allow nullable array by design for the same reasons as you have posted.

Can you please send in the query or the screenshot where arrays are nullable?

I tested using [email protected], binary version: 237b46b97773f5018e336550e4285e2a78c38483

Ok now with latest alpha array are not nullable anymore, but an optional field in my schema in nested select is not marked as nullable.

PS: Schema and query in our mail conversation. thanks

image

I can't reproduce. It is nullable. Also, as a side note please don't confuse ? operator with nullability. ? makes a property optional not nullable

You'are right I said nullability when a field is optional in the prisma schema and should be | null in the generated typescript no? I make a little reproduction tested with [email protected], binary version: 998508a3ac0132b0b211dec85419e0a27f3d1813.

Schema:
image

Query:

const userTest = await photon.userTests.findOne({
    where: {
      id: "Example"
    },
    select: {
      id: true,
      globalConfig: {
        select: {
          accounts: {
            select: {
              username: true,
              password: true,
              config: {
                select: {
                  data: true,
                  list: true
                }
              }
            }
          }
        }
      }
    }
  });

Result:
image

Here I don't get why accounts are marked as | null and the list of Random model too. But what I was telling you first was this AccountData? but yeah now it's good for that.

Thanks

Oh yes, you are right. account and config.list should not be marked a nullable field.

image

I can confirm this as a bug now. Here is the reproduction for internal use: https://github.com/harshit-test-org/prisma-photon-259

Fixed in latest alpha.
You can try it out with npm i -g prisma2@alpha.

Still happening to me on
image

Please try again with alpha.278, sometimes the CI/npm takes a bit longer.
I just manually test it with 278 and it works for me.

AHAH yes thats PERFECT

Was this page helpful?
0 / 5 - 0 ratings