Tuesday 27 October 2020

How to return a graphql Union from a python lambda to AWS appsync?

Is it possible to respond with graphql Union from a python lambda? How? It seems possible but I cannot get it over the line.

I am including a __typename attribute but most of the time I get this error:

{'errorType': 'BadRequestException', 
 'message': "Could not determine the exact type of MealMix. Missing __typename key on value.'"}

MealMix is my union, and the schema looks like:

type Meal { name: String }
type OtherMeal { name: String }
union MealMix = Meal | OtherMeal
type Query {
    GetMealMix(identity_id: ID!, date: AWSDate!): [MealMix]
}

The query is:

        query test_query {
            GetMealMix(identity_id: "this", date: "2020-11-20") {
                ... on Meal {name}
                ... on OtherMeal {name}
            }
        }

From the lambda I am returning:

return [{' __typename': 'Meal',
         'name': 'Kiwifruit, Zespri Gold, Raw'},
        {' __typename': 'OtherMeal',
         'name': 'The meal at the end of the universe'}]

The response template is the default: $util.toJson($ctx.result)

My googling seems to suggest I just need to include the __typename attribute, but there are no explicit Python examples to that effect. I'm asking first, am I flogging a dead horse (meaning this is not implemented and will never work), and second, if it does work, how exactly?



from How to return a graphql Union from a python lambda to AWS appsync?

No comments:

Post a Comment