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