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

Add a way to resolve "implicit" relationships #48

Open
JBBianchi opened this issue Feb 19, 2025 · 0 comments
Open

Add a way to resolve "implicit" relationships #48

JBBianchi opened this issue Feb 19, 2025 · 0 comments
Labels
Milestone

Comments

@JBBianchi
Copy link
Member

What would you like to be added?

Currently, the ProjectionType makes it easy to list explicitly defined relationships. However, there is no straightforward way to resolve implicit relationships between entities.

Consider the following entity definitions:
CartItem

name: CartItem
summary: Represents a cart item
description: Represents a cart item
schema:
  type: object
  properties:
    orderId:
      type: string
    productId:
      type: string
    product:
      type: object
    quantity:
      type: number
  required: [orderId, productId, quantity]
triggers:
  create:
    - event:
        type: io.cloud-shapes.examples.events.cart-item.created.v1
        source: https://examples.cloud-shapes.io
        correlation:
          attribute: subject
      state: '${ .data }'
relationships:
  - type: one-to-one
    target: Product
    key: productId
    path: product

Order

name: Order
summary: Represents a sales order
description: Represents a sales order
schema:
  type: object
  properties:
    status:
      type: string
    items:
      type: array
  required: [status]
triggers:
  create:
    - event:
        type: io.cloud-shapes.examples.events.order.created.v1
        source: https://examples.cloud-shapes.io
        correlation:
          attribute: subject
      state: '${ .data }'
relationships:
  - type: one-to-many
    target: CartItem
    key: orderId
    path: items

The CartItem entity explicitly defines a relationship with Product.
However, CartItem also has an implicit relationship with Order, but this is not directly defined in its relationships.
There should be an easy way to resolve such implicit relationships.

Proposal(s):

Either add implicit relationships in the ProjectionType.Relationships, with a flag to distinguish the explicit and implicit ones.
Or add an "ImplicitRelationships" property to ProjectionType.

Alternative(s):

As an alternative, we can query the API of ProjectionTypes to find projection types where the relationships have a target that corresponds to the entity in question. For example, in the case of CartItem, we can look for projection types where a relationship's target is CartItem. This allows us to infer implicit relationships without them being explicitly defined within the entity itself.

Additional info:

No response

Community Notes

  • Please vote by adding a 👍 reaction to the feature to help us prioritize.
  • If you are interested to work on this feature, please leave a comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

1 participant