Skip to content

Syntactic sugar around relationship creation #28

@yt-ms

Description

@yt-ms

Checklist

Is your feature related to a problem? Please describe it.

Currently, to add a relationship between two elements is a little clunky (mirroring the Java API):

c1 = Container("Container 1")
c2 = Container("Container 2")
r = c1.add_relationship(destination=c2, description="Sends events to")

I think we can do better in Python.

Describe the solution you would like.

By overriding __rshift__ and __irshift__ on Element then we can achieve something much cleaner:

c1 = Container("Container 1")
c2 = Container("Container 2")
c1 >> "Sends events to" >> c2

The result of this expression would be the Relationship so you could continue to add technologies, tags, etc. We could also provide a shortcut that creates a general relationship with description "Uses":

c1 >> c2

And we should also support constructing the relationship explicitly:

c1 >> Relationship("Sends events to", technologies="Kafka") >> c2

This becomes even more useful if people choose to subtype Relationship:

c1 >> Kafka("Sends events to", topic="eventStream") >> c2

(here the topic would be added to the properties collection of the Relationship)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions