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

How to make manyToMany searchable? #1229

Closed
mithun35h opened this issue Feb 4, 2023 · 4 comments
Closed

How to make manyToMany searchable? #1229

mithun35h opened this issue Feb 4, 2023 · 4 comments
Assignees

Comments

@mithun35h
Copy link

Amplify CLI Version

10.7.0

Question

@manytomany(relationName: "name")

create a dynamodb table with the given name, how to make this searchable? or sync it with opensearch

writing post script to create trigger for the table and also create functions in appsync with VTL i think is a complicated customization

@mithun35h mithun35h added pending-triage question Further information is requested labels Feb 4, 2023
@josefaidt josefaidt transferred this issue from aws-amplify/amplify-cli Feb 6, 2023
@josefaidt josefaidt self-assigned this Feb 9, 2023
@josefaidt
Copy link
Contributor

Hey @mithun35h 👋 thanks for raising this! Unfortunately we will not be able to add @searchable on a field itself, however we can use @hasMany to manually create the join table (similar to how @manyToMany creates a join table behind the scenes). From here we can add @searchable to the join table

type Class
  @model
  @auth(rules: [{ allow: owner }, { allow: groups, groupsField: "cohorts" }]) {
  id: ID!
  name: String!
  cohorts: [String]
  students: [ClassStudent] @hasMany
}

type Student
  @model
  @auth(rules: [{ allow: owner }, { allow: private, operations: [read] }]) {
  id: ID!
  name: String!
  classes: [ClassStudent] @hasMany
  owner: String! @auth(rules: [{ allow: owner, operations: [create, read] }])
}

type ClassStudent
  @model
  @searchable
  @auth(
    rules: [{ allow: owner }, { allow: groups, groupsField: "classCohorts" }]
  ) {
  id: ID!
  class: Class! @belongsTo
  student: Student! @belongsTo
  classCohorts: [String] # this will be the cohorts of the class, we need to carry this field onto the join model in order to apply
}

@tarunv69
Copy link

tarunv69 commented Feb 27, 2023

Hello @josefaidt , I did try out the solution that you have provided here but there was this error EMFILE: too many open files, open

To explain my issue better, let me refer it with the same table as your solution.

The schema before :

type Class
  @model
  @auth(rules: [{ allow: owner }, { allow: groups}]) {
  id: ID!
  name: String!
  student: [Student] @manyToMany(relationName: "classStudent")
}

type Student
  @model
  @auth(rules: [{ allow: owner }, { allow: private, operations: [read] }]) {
  id: ID!
  name: String!
  class: [Class] @manyToMany(relationName: "classStudent")
  owner: String! @auth(rules: [{ allow: owner, operations: [create, read] }])
}

After the changes, the schema looked like this:

type Class
  @model
  @auth(rules: [{ allow: owner }, { allow: groups, groupsField: "cohorts" }]) {
  id: ID!
  name: String!
  students: [ClassStudent] @hasMany
}

type Student
  @model
  @auth(rules: [{ allow: owner }, { allow: private, operations: [read] }]) {
  id: ID!
  name: String!
  classes: [ClassStudent] @hasMany
  owner: String! @auth(rules: [{ allow: owner, operations: [create, read] }])
}

type ClassStudent
  @model
  @searchable
  @auth(
    rules: [{ allow: owner }, { allow: groups }]
  ) {
  id: ID!
  class: Class! @belongsTo
  student: Student! @belongsTo
}

So I got the error "EMFILE: too many open files, open" after pushing the latter schema. Tried it several times only to get the same issue at the end.

Region
eu-central-1

Amplify CLI Version
10.7.2

OS
Mac

Node version
Node.js v18.13.0

@phani-srikar
Copy link
Contributor

Hi @mithun35h, I've tried to deploy your schema and had to make some minor changes shown below:

type Class
  @model
  @auth(rules: [{ allow: owner }, { allow: groups, groupsField: "cohorts" }]) {
  id: ID!
  name: String!
  students: [ClassStudent] @hasMany
}

type Student
  @model
  @auth(rules: [{ allow: owner }, { allow: private, operations: [read] }]) {
  id: ID!
  name: String!
  classes: [ClassStudent] @hasMany
  owner: String!
}

type ClassStudent
  @model
  @searchable
  @auth(
    rules: [{ allow: owner }]
  ) {
  id: ID!
  class: Class! @belongsTo
  student: Student! @belongsTo
}

With the above schema, I am able to deploy successfully and did not run into the File limit error you've mentioned.
However, I've found a similar issue when using the Amplify Studio. Do you use Amplify Studio for your App deployments?

@AnilMaktala
Copy link
Member

Hi 👋, We are closing this issue as we have not received any response from you. However, if you are still facing the same issue and require our assistance, please don't hesitate to leave a comment and provide us with the information our team had previously asked for. This way, we can reopen the issue and provide you with better assistance.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants