0

I'm searching for an answer to this problem, and it seems others have as well but no clear answer I could find anywhere (Appsync query union return type throws 400)

I have a GraphlQL type that has a property than can return either a String or an array of Strings, like so.

type Button {
   color: String | [String]
}

Is there a way to accomplish this using Appsync? I've tried using a Union, but get a 400 error instead

type ColorSingle {
   color: String
}

type ColorMulti {
   color: [String]
}

union Colors = ColorSingle | ColorMulti

type Button {
   color: Colors
}

and the query:

getSource(sourceId: "company") {
   themeConfig {
     component {
        ...on ColorSingle {
           __typename
           color
       }
       ...on ColorMulti {
           __typename
           color
       }
    }
  }
}
geeberry
  • 617
  • 2
  • 10
  • 17

1 Answers1

0

Hopefully not too late to help here... I was previously getting a 400 when not providing __typename in the response. AWS documentation on this - https://docs.aws.amazon.com/appsync/latest/devguide/interfaces-and-unions.html