@hasInverse from implementing type to an inerface

Hi,

I have a bit complicated question
This is my scheme

interface IArtifact {
  id: ID!
  name: String! @search(by: [exact, regexp])
  cuid: String! @search(by: [hash]) @id
  in: [Version!]!
  tic: DateTime!
  createdAt: DateTime! @search(by: [year])
  storedIn: [IDataSource!]
  createdBy: User
}

interface IObjectArtifact{
    inputOf: [IArtifact!]
    outputOf: IArtifact
    saver: ObjectHandler
    loader: ObjectHandler
}
type ScriptArtifact implements IArtifact {
    inputs: [IObjectArtifact!] @hasInverse(field: inputOf)
    output: IObjectArtifact! @hasInverse(field: outputOf)
}

The @hasInverse directive doesn’t work here because inputOf and outputOf are referencing the interface IArtifact and not the type ScriptArtifact. In other words, it doesn’t recognize that ScriptArtifact is implementing IArtifact.

My question is how can I make it work and if it is currently impossible what workaround you might suggest.

Many Thanks

Hi @spinelsun,

Yes, I tried reproducing this and it didn’t work.
Possible Workaround:

  1. In case inputOf and outputOf field is only going to be used to store inverse edges of ScriptArtifact and not used in any other derived types from IArtifact, you may make inputOf and outputOf of types, [ScriptArtifact!] and ScriptArtifact respectively.
  2. In case other derived types of IArtifact are also going to have inputs and output field and its inverse is going to be stored in inputOf and outputOf, you may consider keeping inputs and output as a field of IArtifact rather than ScriptArtifact

The thing is that not all IArtifact implementations have inputs and outpus.
Also all IObjectArtifacts might be an input or an output of the IArtifacts.
These are the rules of my app’s data modeling.

I need something that will alow that model.
In the mean time I chose option number 1 because currently I only have ScriptArtifacts but soon we might have more Artifacts.

Thanks

1 Like