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

Is it possibile to change the filter of @searchable autogenerated query? #333

Closed
mdepascale opened this issue Mar 24, 2020 · 7 comments
Closed
Assignees
Labels
graphql-transformer-v1 question Further information is requested

Comments

@mdepascale
Copy link

mdepascale commented Mar 24, 2020

Which Category is your question related to?
Amplify auto generated query @model @searchable

Amplify CLI Version
4.16.1

What AWS Services are you utilizing?
Amplify, DynamoDB, ElasticSearch, Cognito

Provide additional details e.g. code snippets
searchDocuments(filter: SearchableDocumentFilterInput, sort: SearchableDocumentSortInput, limit: Int, nextToken: String): SearchableDocumentConnection.

is it possible to make the filter required? like this filter: SearchableDocumentFilterInput!
also is it possibile to not have the autogenerated query? maybe doing @searchable(null) ?

thank you

@ammarkarachi ammarkarachi added question Further information is requested pending-triage and removed question Further information is requested labels Mar 24, 2020
@ammarkarachi
Copy link
Contributor

@mdepascale @searchable(null) would not be possible, If you could give us more information on what you are trying to do with @searchable we could come with a possible solution

@mdepascale
Copy link
Author

mdepascale commented Mar 25, 2020

hello @ammarkarachi
what I'd like to be able to do is change this query

searchDocuments(filter: SearchableDocumentFilterInput, sort: SearchableDocumentSortInput, limit: Int, nextToken: String): SearchableDocumentConnection

into this

searchDocuments(filter: SearchableDocumentFilterInput!, sort: SearchableDocumentSortInput, limit: Int): SearchableDocumentConnection

notice the ! after SearchableDocumentFilterInput

I've already have get in contact with the aws support and they told me it can't be done.
Do maybe it could be a feature request, to be able to edit the query configuration

@vkumarvs
Copy link

vkumarvs commented Apr 10, 2020

I have kind of similar related problem:

type Factory
@model
@searchable
@key(fields: ["pk", "sk"])
) {
pk: ID!
sk: ID!
dataType: DataType! ---------> enum type
######################################
workstation: WorkStationData #input types nested objects {contains multiple fields}
region: RegionData #input type nested object
}

I used searchable directive and the filtering code generated by Tranformer doesn't include workstation object.

export type SearchableFactoryFilterInput = {
pk?: SearchableIDFilterInput | null,
sk?: SearchableIDFilterInput | null,
and?: Array< SearchableFactoryFilterInput | null > | null,
or?: Array< SearchableFactoryFilterInput | null > | null,
not?: SearchableFactoryFilterInput | null,
};

It only contains pk and sk so I do not have choice to get data based on nested filtering. Any suggestion?

@kaustavghosh06 kaustavghosh06 added graphql-transformer-v1 question Further information is requested and removed pending-response labels Apr 24, 2020
@SwaySway
Copy link
Contributor

Hello @mdepascale
You can add the query manually in the schema, though be sure to include the filter type and it's definitions as well. Making the filter argument would be a breaking change, is there a use case in which you need the argument to be mandatory? I can discuss this use case with the team.

@SwaySway
Copy link
Contributor

Hello @vkumarvs
Currently @searchable does not support querying for nested objects. This is an enhancement we are looking at it.

Enums: aws-amplify/amplify-cli#3248
With @connections: aws-amplify/amplify-cli#763

@andreialecu
Copy link

@SwaySway could you expand with an example on how to add the query manually in the schema? How would you disable the default query generated by amplify?

For example assume the following schema:

interface ChatMessage {
  id: ID!
  userId: ID!
  user: User
  text: String!
  deleted: Boolean
  createdAt: AWSDateTime!
}

I'd like the search to only return messages where deleted: { ne: true } via a custom search query, and disable the built in one. Is this possible?

Same for a different model where there is a public field that can be true/false. I'd like searches to only occur on public: true items.

If the filter is not mandatory, you can just pull the entire database by omitting it.

@OperanceTim
Copy link

OperanceTim commented Jul 7, 2021

@mdepascale @searchable(null) would not be possible, If you could give us more information on what you are trying to do with @searchable we could come with a possible solution

Why is this not possible?

We have a use case where we are applying a custom pipeline resolver to the ElasticSearch data source in Amplify to use complex security. If we want to use the resources generated by @searchable we have to create an additional query but that leaves the original query open and users can see data they are not supposed to.

Why can we not use @searchable(queries: null) as is the case for the @model directive?

It also appears we cannot replace the search query like we can with list or get queries via custom resources for example.

@alharris-at alharris-at transferred this issue from aws-amplify/amplify-cli May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graphql-transformer-v1 question Further information is requested
Projects
None yet
Development

No branches or pull requests

8 participants