lolopinto / ent

MIT License
51 stars 6 forks source link

UUIDListType fields codegen with errors in the Builder #1793

Open Swahvay opened 6 months ago

Swahvay commented 6 months ago

A field defined as :

horseIDs: UUIDListType({
  nullable: true,
  fieldEdge: {
    schema: 'Horse',
    inverseEdge: {
      name: 'competitionEntries',
    },
  },
}),

generates the following code block in getEditedFields:

addField('horseIDs', input.horseIds);
if (input.horseIds !== undefined) {
  if (input.horseIds) {
    this.orchestrator.addInboundEdge(
      input.horseIds, // Error here
      EdgeType.HorseToCompetitionEntries,
      NodeType.Horse,
    );
  }
  if (
    this.existingEnt &&
    this.existingEnt.horseIds &&
    this.existingEnt.horseIds !== input.horseIds
  ) {
    this.orchestrator.removeInboundEdge(
      this.existingEnt.horseIds, // Error here
      EdgeType.HorseToCompetitionEntries,
    );
  }
}

There error is Argument of type 'ID[]' is not assignable to parameter of type 'ID'. Not sure if it matters, but for me the field is defined on a pattern.

Swahvay commented 6 months ago

The should probably be generated as:

addField('horseIDs', input.horseIds);
if (input.horseIds) {
  input.horseIds.forEach((horseId) =>
    this.orchestrator.addInboundEdge(
      horseId,
      EdgeType.HorseToCompetitionEntries,
      NodeType.Horse,
    ),
  );
}
if (this.existingEnt && this.existingEnt.horseIds) {
  this.existingEnt.horseIds.forEach((horseId) => {
    if (!input.horseIds?.includes(horseId)) {
      this.orchestrator.removeInboundEdge(
        horseId,
        EdgeType.HorseToCompetitionEntries,
      );
    }
  });
}
lolopinto commented 6 months ago

hmm, i think UUIDlistType with inverseEdge hasn't worked in the past. is this a new field? or did this break with v0.2?

Swahvay commented 6 months ago

This is a new field. I ended up going a different direction anyways, so I'm not blocked on this, but it's still a valid bug.

Swahvay commented 6 months ago

Everything else seemed to work except that builder setting edges.