This uses the schema from schema.graphql so you can go straight ahead into
-
amplify init -
amplify add apiand choose GraphQL, and useschema.graphql -
amplify push -
cd apiSearchableAppand runpod install -
xedto open the app
The schema contains a model with @searchable annotated
type Blog6 @model @searchable {
id: ID!
name: String!
posts: [Post6] @connection(keyName: "byBlog", fields: ["id"])
}
Run amplify console api and navigate to the Queries tab, and determine the search query you want to perform and its parameters.
This sample provides an extension that makes it easy to map to a AppSync search query.
func searchBlogs() {
let filter: [String: Any] = [
"name": [
"matchPhrase": "first"
]
]
Amplify.API.query(request: .search(Blog6.self,
filter: filter,
limit: 1000,
sort: QuerySortBy.ascending(Blog6.keys.id))) { event in
switch event {
case .success(let result):
switch result {
case .success(let blogs):
print("Successfully searched blogs: \(blogs)")
case .failure(let error):
print("Got failed result with \(error.errorDescription)")
}
case .failure(let error):
print("Got failed event with error \(error)")
}
}
}Extension https://gist.github.com/lawmicha/d8a9453a3dfdc976f4cfa976a9c4eb30