We are implementing an app in React-Naitive and for this we are using aws and amplify. Now we are trying to get all elements of an interface or union type in graphql. The Interface is calling TrackingItem and the type which are implementing this is called UserFood and UserSymptom. We tried this also, with union and just a array of TrackingItems. But with every possibility we don’t get any element. The return value is just null and we are expect the ID of TrackingItems, or in case of getAllTrackingItems an array of IDs from TrackingItem.
Graphql-schema:
type Query {
getAllTrackingItems: [TrackingItem]
# Retrieve tracking items
findTrackingItem(id: ID!): TrackingItem
# Search across all UnionTrackingItems
search(id: ID!): [UnionTrackingItems]
}
union UnionTrackingItems = UserSymptom | UserFood
interface TrackingItem {
id: ID!
userId: ID!
}
type UserFood implements TrackingItem @model {
id: ID!
userId : ID!
type: String!
foodId: ID!
food : Food @connection(fields: ["foodId"])
}
type UserSymptom implements TrackingItem @model {
id: ID!
userId : ID!
type: String!
symptomId: ID!
symptom : Symptom @connection(fields: ["symptomId"])
strenght: Int
}
Our queries which we are testing after amplify mock:
query MyQuery {
getAllTrackingItems {
id
}
findTrackingItem(id: 1) {
id
}
search(id: 1) {
... on UserFood {
id
}
}
getUserFood(id: 1) {
id
}
}
Our results:
{
"data": {
"getAllTrackingItems": null,
"findTrackingItem": null,
"search": null,
"getUserFood": {
"id": "1"
}
}
}
Can anyone help? Thank you!