Can't add Interface-Childs with addParent(...) mutation

I have following schema:

interface Parameter {
  id: String! @id

  label: String!
}

type StringParameter implements Parameter {
  value: String!
}

type FloatParameter implements Parameter {
  value: Float!
}

type TestType {
  parameters: [Parameter!]
}

The generated mutation:

mutation {
  addTestType(input: [
    {
      parameters: [{
          id: "param1"
          label: ""
          value: 1.0
      }
      ]
    }
  ]) {
  ...
   }
}

does not work because the type for creating new parameters is ParameterRef.
Shouldn’t the type rather be:

{
   stringParameterRef: StringParameterRef
   floatParameterRef: FloatParameterRef
}

instead? (Like with union input types)

Do I need to do something differently?

@maaft, Currently we don’t generate the reference of types implemented by interfaces.
If you want to add objects of types implemented by interfaces for example StringParameter or FloatParameter from TestType then you need to first create the object of those types and then provide the reference of those while creating TestType like below.

1.First create the object of StringParameter

mutation {
  addStringParameter(input: [{id:"param1",label:"xy",value:"re"}
  ]) {
    stringParameter{
      id
      label
      value
    }
  numUids
   }
}

2.Using Id of the generated object of StringParameter, provide a reference while adding TestType

mutation {
  addTestType(input: [{parameters: [{id: "param1"}]}
  ]) {
    testType{
      parameters{
        label
        ...on StringParameter {
        value
      }
        
      }
    }
  numUids
   }
}

Another easy approach is you can specify the implementing types in the schema itself. For example, you can specify the StringParameter or FloatParameter in the schema itself.

type TestType {
  stringParameter: [StringParameter]
  floatParameter:[FloatParameter]
}

But the problem is you will end up adding lots of references of implementing types in case you have many of them.

Yes, I’m aware of this. This would require two mutations though. Do you think you could plan this as a feature?

yeah sure, we will discuss this internally and get back to you, Thanks.

1 Like

Hi @JatinDevDG!

Did you find time to discuss this internally? I’m currently pulling my hair out with all the double mutations…

Hi @maaft, sorry for the late reply. We had discussion on it when this issue is posted but i guess it’s still in backlog. I will discuss it again with team and try to scope it out.

2 Likes

@JatinDevDG Hi, I keep stumbling across needing this functionality.

Any updates?

I can also give a definite use-case:

You need this, when you have interface-childs of the same interface on different parent-types:

interface Writable {
  ...
 }

type Foo {
   writables: [Writeable!]!
}

type Bar {
  writables: [Writeable!]!
}

As you can see, without this feature you can’t create a Bar or a Foo that have any writables. You also cannot first add e.g. a Bar and afterwards the corresponding Writables because you don’t have an inverse edge.

It should be obvious that I shouldn’t be forced to add inverse edges for every possible type that is using that interface as a child.

I.e. a bad solution would be:

interface Writable {
   foo: Foo
   bar: Bar
 }

type Foo {
   writables: [Writeable!]! @hasInverse(field: foo)
}

type Bar {
  writables: [Writeable!]! @hasInverse(field: bar)
}