Skip to content

Updating JSON array field causes "Invalid array filter key" error #586

@ymc9

Description

@ymc9

ZModel:

type AuthInfo {
    aProperty Boolean

    @@auth
}

type Foo {
    bar String
    baz Int

    @@allow("all", auth().aProperty)
}

model JsonArrayRoot {
    id String @id @default(cuid())

    fields JsonArrayField[]

    @@allow("all", auth().aProperty)
}

model JsonArrayField {
  id String @id @default(cuid())
  data Foo[] @json
  rootId String

  root JsonArrayRoot @relation(fields: [rootId], references: [id])

  @@allow("all", auth().aProperty)
}

TS:

const db = new ZenStackClient(schema, {
    ...,
    plugins: [
        {
            id: 'foo',
            name: 'foo',
            description: 'foo',
            onEntityMutation: {
                afterEntityMutation: async () => Promise.resolve(),
                beforeEntityMutation: async () => Promise.resolve(),
                runAfterMutationWithinTransaction: true,
            },
        },
    ],
});

const authed = db.$setAuth({ aProperty: true });

const root = await authed.jsonArrayRoot.create({ data: {} });

const created = await authed.jsonArrayField.create({
    data: {
        data: [],
        rootId: root.id,
    },
});

const updateData = [
    { bar: 'hello', baz: 1 },
    { bar: 'world', baz: 2 },
];

await authed.jsonArrayField.update({
    where: { id: created.id },
    data: {
        data: updateData,
        rootId: root.id,
    },
});

Error:

Invalid array filter key: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions