## Query item

Now that you were able to make a mutation, take the `Id` that was printed out and use it in your query to retrieve data.

<BlockSwitcher>
<Block name="Java">

```java
private void getTodo(String id) {
    Amplify.API.query(
        ModelQuery.get(Todo.class, id),
        response -> Log.i("MyAmplifyApp", ((Todo) response.getData()).getName()),
        error -> Log.e("MyAmplifyApp", error.toString(), error)
    );
}
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
private fun getTodo(id: String) {
    Amplify.API.query(ModelQuery.get(Todo::class.java, id),
        { Log.i("MyAmplifyApp", "Query results = ${(it.data as Todo).name}") },
        { Log.e("MyAmplifyApp", "Query failed", it) }
    );
}
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
suspend fun getTodo(id: String) {
   try {
       val response = Amplify.API.query(ModelQuery.get(Todo::class.java, id))
       Log.i("MyAmplifyApp", response.data.name)
   } catch (error: ApiException) {
       Log.e("MyAmplifyApp", "Query failed", error)
   }
}
```

</Block>
<Block name="RxJava">

```java
private void getTodo(String id) {
  RxAmplify.API.query(ModelQuery.get(Todo.class, id))
          .subscribe(
              response -> Log.i("MyAmplifyApp", ((Todo) response.getData()).getName()),
              error -> Log.e("MyAmplifyApp", error.toString(), error)
          );
}
```

</Block>
</BlockSwitcher>

## List items

You can get the list of items that match a condition that you specify in `Amplify.API.query`:

<BlockSwitcher>
<Block name="Java">

```java
Amplify.API.query(
    ModelQuery.list(Todo.class, Todo.NAME.contains("first")),
    response -> {
        for (Todo todo : response.getData()) {
            Log.i("MyAmplifyApp", todo.getName());
        }
    },
    error -> Log.e("MyAmplifyApp", "Query failure", error)
);
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
Amplify.API.query(
    ModelQuery.list(Todo::class.java, Todo.NAME.contains("first")),
    { response ->
        response.data.forEach { todo ->
            Log.i("MyAmplifyApp", todo.name)
        }
    },
    { Log.e("MyAmplifyApp", "Query failure", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
try {
    Amplify.API
        .query(ModelQuery.list(Todo::class.java, Todo.NAME.contains("first")))
        .response.data
        .items.forEach { todo -> Log.i("MyAmplifyApp", todo.name) }
} catch (error: ApiException) {
    Log.e("MyAmplifyApp", "Query failure", error)
}
```

</Block>
<Block name="RxJava">

```java 
RxAmplify.API.query(ModelQuery.list(Todo.class, Todo.NAME.contains("first"))
    .subscribe(
        response -> {
            for (Todo todo : response.getData()) {
                Log.i("MyAmplifyApp", todo.getName());
            }
        },
        error -> Log.e("MyAmplifyApp", "Query failure", error)
    );
```

</Block>
</BlockSwitcher>

> **Note**: This approach will only return up to the first 1,000 items.  To change this limit or make requests for additional results beyond this limit, use *pagination* as discussed below.

## List subsequent pages of items

A list query only returns the first 1,000 items by default, so for large data sets, you'll need to paginate through the results.  After receiving a page of results, you can obtain a `GraphQLRequest` for requesting the next page, if there are more results available.  The page size is configurable as well, as in the example below.

<BlockSwitcher>
<Block name="Java">

```java
public void queryFirstPage() {
    query(ModelQuery.list(Todo.class, ModelPagination.limit(1_000)));
}

private static void query(GraphQLRequest<PaginatedResult<Todo>> request) {
    Amplify.API.query(
        request,
        response -> {
            if (response.hasData()) {
                for (Todo todo : response.getData()) {
                    Log.d("MyAmplifyApp", todo.getName());
                }
                if (response.getData().hasNextResult()) {
                    query(response.getData().getRequestForNextResult());
                }
            }
        },
        failure -> Log.e("MyAmplifyApp", "Query failed.", failure)
    );
}
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
fun queryFirstPage() {
    query(ModelQuery.list(Todo::class.java, ModelPagination.limit(1_000)))
}

fun query(request: GraphQLRequest<PaginatedResult<Todo>>) {
    Amplify.API.query(request,
        { response ->
            if (response.hasData()) {
                response.data.items.forEach { todo ->
                    Log.d("MyAmplifyApp", todo.name)
                }
                if (response.data.hasNextResult()) {
                    query(response.data.requestForNextResult)
                }
            }
        },
        { Log.e("MyAmplifyApp", "Query failed", it) }
    )
}
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
suspend fun queryFirstPage() {
    query(ModelQuery.list(Todo::class.java,
        ModelPagination.firstPage().withLimit(1_000)))
}

suspend fun query(request: GraphQLRequest<PaginatedResult<Todo>>) {
    try {
        val response = Amplify.API.query(request)
        response.data.items.forEach { todo ->
            Log.d("MyAmplifyApp", todo.name)
        }
        if (response.data.hasNextResult()) {
            query(response.data.requestForNextResult)
        }
    } catch (error: ApiException) {
        Log.e("MyAmplifyApp", "Query failed.", error)
    }
}
```

</Block>

<Block name="RxJava">

```java
BehaviorSubject<GraphQLRequest<PaginatedResult<Todo>>> subject =
        BehaviorSubject.createDefault(ModelQuery.list(Todo.class, ModelPagination.limit(1_000)));
subject.concatMap(request -> RxAmplify.API.query(request).toObservable())
    .doOnNext(response -> {
        if (response.hasErrors()) {
            subject.onError(new Exception(String.format("Query failed: %s", response.getErrors())));
        } else if (!response.hasData()) {
            subject.onError(new Exception("Empty response from AppSync."));
        } else if(response.getData().hasNextResult()) {
            subject.onNext(response.getData().getRequestForNextResult());
        } else {
            subject.onComplete();
        }
    })
    .concatMapIterable(GraphQLResponse::getData)
    .subscribe(
        todo -> Log.d(TAG, "Todo: " + todo),
        error -> Log.e(TAG, "Error: " + error)
    );
```

</Block>
</BlockSwitcher>
