Description
Description
when I declare Many To Many Relation and query models many-to-many list come with null value
Categories
- Analytics
- API (REST)
- API (GraphQL)
- Auth
- Authenticator
- DataStore
- Notifications (Push)
- Storage
Steps to Reproduce
GraphQL scheam
type Category @model @auth(rules: [{ allow: public }]) {
id: ID!
name: String!
order: Int
people: [Person] @manytomany(relationName: "PersonCategories")
}
type Taxonomy @model @auth(rules: [{ allow: public }]) {
id: ID!
name: String!
emoji: String
people: [Person] @manytomany(relationName: "PersonTaxonomies")
}
type Person @model @auth(rules: [{ allow: public }]) {
id: ID!
first_name: String!
last_name: String!
bio: String
city: String
country: String
image: String
job_title: String
organization: String
taxonomies: [Taxonomy] @manytomany(relationName: "PersonTaxonomies")
categories: [Category] @manytomany(relationName: "PersonCategories")
is_featured: Boolean
is_discoverable: Boolean
}
query person
final persons = await Amplify.DataStore.query(Person.classType);
print(persons.first.taxonomies);
taxonomies come with null value
and any many-to-many relation
also the data saved correct in data base and the GraphQL Request on API retrieve data
like this
Future customRequest2() async {
const document = '''
query GetPeople {
listPeople {
items {
id
first_name
last_name
bio
city
country
image
job_title
organization
is_featured
is_discoverable
industry {
id
name
}
taxonomies {
items {
id
taxonomy {
id
name
emoji
}
}
}
categories {
items {
id
category {
id
name
}
}
}
goals {
items {
id
goal {
id
name
}
}
}
}
}
}
''';
final request = GraphQLRequest<String>(
document: document,
decodePath: 'listPeople',
);
try {
final response = await Amplify.API.query(request: request).response;
if (response.errors.isNotEmpty) {
print('Response Error: ${response.errors}');
} else {
print("data: ${response.data}");
final List<dynamic> items = jsonDecode(response.data!)['listPeople']['items'];
final List<Person> people = items.map((item) => Person.fromJson(item)).toList();
print('Response data: ${people.length}');
setState(() {
persons = people;
});
}
} catch (e, sk) {
print('An error occurred: $e');
print(sk);
}
}
I don't know why DataStore does not retrieve taxonomies and categories with every person
Screenshots
No response
Platforms
- iOS
- Android
- Web
- macOS
- Windows
- Linux
Flutter Version
3.22.3
Amplify Flutter Version
^2.5.0
Deployment Method
Amplify CLI (Gen 1)
Schema
type Category @model @auth(rules: [{ allow: public }]) {
id: ID!
name: String!
order: Int
people: [Person] @manyToMany(relationName: "PersonCategories")
}
type Taxonomy @model @auth(rules: [{ allow: public }]) {
id: ID!
name: String!
emoji: String
people: [Person] @manyToMany(relationName: "PersonTaxonomies")
}
type Person @model @auth(rules: [{ allow: public }]) {
id: ID!
first_name: String!
last_name: String!
bio: String
city: String
country: String
image: String
job_title: String
organization: String
taxonomies: [Taxonomy] @manyToMany(relationName: "PersonTaxonomies")
categories: [Category] @manyToMany(relationName: "PersonCategories")
is_featured: Boolean
is_discoverable: Boolean
}