Last active
July 11, 2020 17:07
-
-
Save CompileConnected/bf8f2a8b6a337451065280027a94cc56 to your computer and use it in GitHub Desktop.
How to filter query in aws appsync todo list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this is how to query with one parameter | |
fun queryContainsName(name: String) { | |
//this is the part where not in the documentation | |
mAWSAppSyncClient.query( | |
ListTodosQuery | |
.builder() | |
.filter( | |
ModelTodosFilterInput | |
.builder() | |
.name(ModelStringInput.builder().contains(name).build()) | |
.build() | |
) | |
.build() | |
).responseFetcher(AppSyncResponseFetchers.CACHE_AND_NETWORK) | |
.enqueue(todosCallback) | |
} | |
//now there difference case when you want to query with two or more | |
//let say we want to query todo list that contains name or description of something | |
fun queryContainsNameOrDescription(name: String, description: String) { | |
//this is the part where your brain say why | |
mAWSAppSyncClient.query( | |
ListTodosQuery | |
.builder() | |
.filter( | |
ModelTodosFilterInput | |
.builder() | |
.or( | |
listOf( | |
ModelTodosFilterInput | |
.builder() | |
.name( | |
ModelStringInput | |
.builder() | |
.contains(name) | |
.build() | |
) | |
.build(), | |
ModelTodosFilterInput | |
.builder() | |
.description( | |
ModelStringInput | |
.builder() | |
.contains(description) | |
.build() | |
) | |
.build() | |
) | |
) | |
.build() | |
) | |
.build() | |
).responseFetcher(AppSyncResponseFetchers.CACHE_AND_NETWORK) | |
.enqueue(todosCallback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment