Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many To Many Relation not working #5802

Open
3 of 14 tasks
HusseinReda97pro opened this issue Jan 14, 2025 · 1 comment
Open
3 of 14 tasks

Many To Many Relation not working #5802

HusseinReda97pro opened this issue Jan 14, 2025 · 1 comment
Labels
datastore Issues related to the DataStore Category pending-triage This issue is in the backlog of issues to triage to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided

Comments

@HusseinReda97pro
Copy link

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
}
@github-actions github-actions bot added pending-triage This issue is in the backlog of issues to triage pending-maintainer-response Pending response from a maintainer of this repository labels Jan 14, 2025
@ekjotmultani
Copy link
Member

Hi @HusseinReda97pro, I'm sorry you are facing this issue. I will attempt to reproduce and get back to you

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Jan 14, 2025
@ekjotmultani ekjotmultani added datastore Issues related to the DataStore Category to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category pending-triage This issue is in the backlog of issues to triage to-be-reproduced Issues that have not been reproduced yet, but have reproduction steps provided
Projects
None yet
Development

No branches or pull requests

2 participants