Avoid fetch in a transform

#1

I know that transform has to be a pure function that does not do any fetches/updates. But if I have a type like this

entity type SomeType {
   fieldA: TypeA
   fieldB: [TypeB]
}

And canonicals like:

aId,bId
a1,b1
...
a1,b2
a2,b1

How I can avoid the fetch as in this case TypeB can be linked to many instances of TypeA?

0 Likes

#2

Is there a 1:1 relationship between SomeType and TypeA or a many:1?

If it’s 1:1 you could do something like:

entity type SomeType {
   fieldA: TypeA
   fieldB: [TypeB](parent)
}

type TransformCanonicalTypeToSomeType mixes SomeType transforms CanonicalType {
    id: ~ expression "aId"
}

type TransformCanonicalTypeToTypeB mixes TypeB transforms CanonicalType {
    id: ~ expression "bId"
    parent: ~ expression { id: "aId" }
}

and in the case of many:1, there’s likely some other sort of unique identifier for each SomeType related to TypeA. In that case it would be:

entity type SomeType {
   fieldA: TypeA
   fieldB: [TypeB](parent)
}

type TransformCanonicalTypeToSomeType mixes SomeType transforms CanonicalType {
    id: ~ expression "concat(aId, '_', someOtherIdentifier)"
}

type TransformCanonicalTypeToTypeB mixes TypeB transforms CanonicalType {
    id: ~ expression "bId"
    parent: ~ expression { id: "concat(aId, '_', someOtherIdentifier)" }
}
0 Likes

#3

TypeB can be linked to multiple instances of TypeA, and he cannot have one parent TypeA. That’s the problem!

0 Likes

#4

I don’t understand, according to the way you defined your type above the following is true, no?

  • each instance of TypeB with one SomeType instance
  • a SomeType instance is associated with one TypeA instance

if TypeB can be associated with several instances of TypeA and vice-versa I would think SomeType should look like this:

entity type SomeType {
   fieldA: [TypeA](parent)
   fieldB: [TypeB](parent)
}
0 Likes

#5

no an instance of TypeB can be present in many instances of SomeType, the field fieldB is just a collection, no foreign keys.

0 Likes