Skip to content
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

Nested classes how-to in Dgraph 101 #42

Open
marc4gov opened this issue Jan 4, 2025 · 1 comment
Open

Nested classes how-to in Dgraph 101 #42

marc4gov opened this issue Jan 4, 2025 · 1 comment

Comments

@marc4gov
Copy link

marc4gov commented Jan 4, 2025

I'm trying to extend the Dgraph 101 example with AssemblyScript to my own nested classes and types, but I run into errors when trying to upsert them. Plain, unnested classes seem to work fine.
I'm sure there's an easy fix for this, but not able to find it, see attached files.

as.zip

@marc4gov marc4gov changed the title Nested classes how-to in dGraph 101 Nested classes how-to in Dgraph 101 Jan 4, 2025
@marc4gov
Copy link
Author

marc4gov commented Jan 6, 2025

So, a bit further down the rabbit hole... I cannot get the graph relations the way they should be. AssemblyScript is complaining about circular references EnergyProfile/PumpingStation - I get that - but now I end up with these classes, they work, but I lose the typical Graph features now:

export class EnergyProfile {
    @alias("EnergyProfile.id")
    id!: string

    @alias("EnergyProfile.pumpingstation_id")  // Note the _id suffix
    @omitnull()
    pumpingstation_id: string | null = null     // Actually store the ID as string

    @alias("EnergyProfile.name")
    name: string = ""

    @alias("EnergyProfile.day")
    day: i16 = 1

    @alias("EnergyProfile.month")
    month: i16 = 1

    @alias("EnergyProfile.price")
    price: f32[] = [1.0]
}

@json
export class PumpingStation {
    @alias("PumpingStation.id")
    id!: string

    @alias("PumpingStation.name")
    name: string = ""

    @alias("PumpingStation.flow_rate")
    flow_rate: f32 = 0.0

    @alias("PumpingStation.energyprofile_ids")  // Note the _ids suffix
    @omitnull()
    energyprofile_ids: string[] | null = null   // Actually store IDs as strings

    @alias("PumpingStation.place")
    place: string = ""
}

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

No branches or pull requests

1 participant