I am using AWS Amplify with Flutter and I have a schema as such:
type User @model @searchable {
id: ID! @primaryKey
email: AWSEmail!
roomProfileId: ID
roomProfile: RoomProfile @hasOne(fields: ["roomProfileId"])
}
type RoomProfile @model @searchable {
id: ID! @primaryKey
roomType: String
rentPrice: Int
userId: ID!
user: User! @belongsTo(fields: ["userId"])
}
I then make a query like this:
const getProfiles =
''' query getProfiles($gender: String, $isActive: Boolean, $createdAfter: String, $limit: Int) {
searchRoomProfiles(filter: {gender: {eq: $gender}, isActive: {eq: $isActive}, createdAt: {gt: $createdAfter}}, limit: $limit, sort: {field: createdAt, direction: asc}) {
items {
id
roomType
user {
id
}
}
}
}
''';
final getRoomProfilesRequest = GraphQLRequest(
document: getProfiles,
variables: <String, dynamic>{
'gender': user.gender.name,
'isActive': 'true',
'createdAfter': user.nextRoomDate,
'limit': pendingRoomProfiles.toString(),
},
decodePath: "searchRoomProfiles",
);
final response =
await Amplify.API.query(request: getRoomProfilesRequest).response;
String? dataString = response.data;
print("esponse.data);
The issue is that the id and roomType are fetched successfully and I see them printed, but user is null.
I tried going to the AWS AppSync console and making the same query (i.e. copy pasting the query), and it returned the user successfully. Any idea why it isn’t working on my client?