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

Feature Request: Search and filter data with Amplify.API without custom GraphQL Document #4189

Open
7 of 14 tasks
MarlonJD opened this issue Nov 27, 2023 · 7 comments
Open
7 of 14 tasks
Labels
feature-request A request for a new feature or an enhancement to an existing API or category. GraphQL API Issues related to the API (GraphQL) Category

Comments

@MarlonJD
Copy link
Contributor

Description

Hello, on amplify-flutter there is no search option like ModelQueries.list, do we planning to add this?
I would like to try to add this if it's possible.

Query predicate operations for search will be one of these:

matchPhrasePrefix, matchPhrase, match, multiMatch, ne, range, regexp, eq, exists, gt, gte, lt, lte, wildcard

for example search operation can be like this example,
it can be build on the ModelQueries.list,

example ModelQueries.list was like this:

final request = ModelQueries.list(
  Student.classType,
  where: Student.NAME.eq("John"),
);

to

// eq example
final request = ModelQueries.search(
  Student.classType,
  where: Student.NAME.eq("John"),
  limit: 10,
);

// on search matchPhrasePrefix operation will be important
final request = ModelQueries.search(
  Student.classType,
  where: Student.NAME.matchPhrasePrefix("Jo"),
  limit: 10,
);

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

No response

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.3.10

Amplify Flutter Version

0.6.10

Deployment Method

Amplify CLI

Schema

type Student @model @searchable {
  name: String
  dateOfBirth: AWSDate
  email: AWSEmail
  examsCompleted: Int
}
@khatruong2009 khatruong2009 added GraphQL API Issues related to the API (GraphQL) Category pending-triage This issue is in the backlog of issues to triage labels Nov 27, 2023
@NikaHsn NikaHsn added feature-request A request for a new feature or an enhancement to an existing API or category. and removed pending-triage This issue is in the backlog of issues to triage labels Dec 1, 2023
@MarlonJD
Copy link
Contributor Author

MarlonJD commented Dec 4, 2023

I just added #4210 for this issue, please let me know if it's good for you, thanks

@MarlonJD MarlonJD changed the title Future Request: Search and filter data with Amplify.API without custom GraphQL Document Feature Request: Search and filter data with Amplify.API without custom GraphQL Document Dec 4, 2023
@Equartey
Copy link
Contributor

Equartey commented Dec 7, 2023

Hi @MarlonJD, thanks for sharing the proactive solution.

It's unclear to me why you would need a separate ModelQueries.serach() method. Could you please explain why your use case could not be solved with a new query predicate passed to the existing ModelQueries.list() method?

@MarlonJD
Copy link
Contributor Author

MarlonJD commented Dec 7, 2023

Hi @Equartey, thanks. It's for @searchable directive, see https://docs.amplify.aws/flutter/build-a-backend/graphqlapi/search-and-result-aggregations/ here, it's creating new query in GraphQL, for example listTodosis for normal query, but if you use OpenSearch and for getting search results in GraphQL query, we'll use searchTodos.

If I use listTodos,

  1. I have to create customDocument and replace listTodos with searchTodos in created document in ModelQueries.list()
  2. and there is no matchPhrasePrefix in Query predicate operations, for this reason, I have to create custom variables.

So ModelQueries.search() creating required variables and correct document for this. So it's solving this issue

@Equartey
Copy link
Contributor

Equartey commented Dec 7, 2023

@MarlonJD ah yeah I understand now. Thank you for the context.

In the meantime, this query can be made using our advance workflows escape hatch. I'm guessing you already knew this, but calling it out to be sure. From the doc example you linked it could look something like this in dart:

final document = '''query SearchStudentsByEmail {
 searchStudents(filter: { name: { eq: "Rene Brandel" } }) {
   items {
     id
     name
     email
   }
 }
}''';
final req = GraphQLRequest<Student>(
   document: document,
   decodePath: 'searchStudents.items', // document title + .items
   modelType: Student.classType);

Thanks again for the contribution. I'll let you know if we have any more questions and updates.

@MarlonJD
Copy link
Contributor Author

MarlonJD commented Dec 7, 2023

@Equartey yes I'm doing just like that. So this feature request is for avoid these long and custom codes, that's why I'm proposing this. BTW if you check the PR codes, please let me know what's your ideas about these, and I can change commit message and merge into 1 commit if it's necessary

@Equartey
Copy link
Contributor

Equartey commented Dec 7, 2023

@MarlonJD Great, yeah I can see the value add for sure. I'll let you know if we want to combine them, thanks.

@MasterNeuromancer
Copy link

I would like to add that the amplify flutter docs have a dedicated section for how to add search using the @searchable directive, but there is no easy way to access this on the flutter side. It seems like elasticsearch resources are being deployed in that case for no reason. Also that whole section has javascript examples instead of flutter/dart code which is just kinda sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A request for a new feature or an enhancement to an existing API or category. GraphQL API Issues related to the API (GraphQL) Category
Projects
None yet
Development

No branches or pull requests

5 participants