1
1
import { getCustomStaticPath } from ' @/utils/getCustomStaticPath' ;
2
-
2
+ // cspell:ignore ACCOUNTREPRESENTATIVEID
3
3
export const meta = {
4
4
title: ' Customize secondary indexes' ,
5
5
description:
@@ -48,7 +48,7 @@ export const schema = a.schema({
48
48
});
49
49
```
50
50
51
- <InlineFilter filters = { [" javascript" , " angular" , " react-native" , " react" , " nextjs" , " vue" , " android" , " flutter " ]} >
51
+ <InlineFilter filters = { [" javascript" , " angular" , " react-native" , " react" , " nextjs" , " vue" , " android" ]} >
52
52
53
53
The example client query below allows you to query for "Customer" records based on their ` accountRepresentativeId ` :
54
54
@@ -104,6 +104,27 @@ let queriedCustomers = try await Amplify.API.query(
104
104
```
105
105
106
106
</InlineFilter >
107
+
108
+ <InlineFilter filters = { [" flutter" ]} >
109
+
110
+ The example client query below allows you to query for "Customer" records based on their ` accountRepresentativeId ` :
111
+
112
+ ``` dart title="lib/main.dart"
113
+ import 'package:amplify_api/amplify_api.dart';
114
+ import 'package:amplify_flutter/amplify_flutter.dart';
115
+ import 'models/ModelProvider.dart';
116
+
117
+ // highlight-start
118
+ final request = ModelQueries.list(
119
+ Customer.classType,
120
+ where: Customer.ACCOUNTREPRESENTATIVEID.eq(YOUR_REP_ID),
121
+ );
122
+ // highlight-end
123
+
124
+ ```
125
+
126
+ </InlineFilter >
127
+
107
128
<Accordion title = " Review how this works under the hood with Amazon DynamoDB" >
108
129
109
130
Amplify uses Amazon DynamoDB tables as the default data source for ` a.model() ` . For key-value databases, it is critical to model your access patterns with "secondary indexes". Use the ` .secondaryIndexes() ` modifier to configure a secondary index.
@@ -133,7 +154,7 @@ export const schema = a.schema({
133
154
});
134
155
```
135
156
136
- <InlineFilter filters = { [" javascript" , " angular" , " react-native" , " react" , " nextjs" , " vue" , " android" , " flutter " ]} >
157
+ <InlineFilter filters = { [" javascript" , " angular" , " react-native" , " react" , " nextjs" , " vue" , " android" ,]} >
137
158
138
159
On the client side, you should find a new ` listBy... ` query that's named after hash key and sort keys. For example, in this case: ` listByAccountRepresentativeIdAndName ` . You can supply the filter as part of this new list query:
139
160
@@ -185,6 +206,26 @@ let queriedCustomers = try await Amplify.API.query(
185
206
```
186
207
</InlineFilter >
187
208
209
+ <InlineFilter filters = { [" flutter" ]} >
210
+
211
+ The example client query below allows you to query for "Customer" records based on their ` name ` AND their ` accountRepresentativeId ` :
212
+
213
+ ``` dart title="lib/main.dart"
214
+ import 'package:amplify_api/amplify_api.dart';
215
+ import 'package:amplify_flutter/amplify_flutter.dart';
216
+ import 'models/ModelProvider.dart';
217
+
218
+ // highlight-start
219
+ final request = ModelQueries.list(
220
+ Customer.classType,
221
+ where: Customer.ACCOUNTREPRESENTATIVEID.eq(YOUR_REP_ID) & Customer.NAME.beginsWith("Rene"),
222
+ );
223
+ // highlight-end
224
+
225
+ ```
226
+
227
+ </InlineFilter >
228
+
188
229
## Customize the query field for secondary indexes
189
230
190
231
You can also customize the auto-generated query name under ` client.models.<MODEL_NAME>.listBy... ` by setting the ` queryField() ` modifier.
@@ -206,7 +247,7 @@ const schema = a.schema({
206
247
});
207
248
```
208
249
209
- <InlineFilter filters = { [" javascript" , " angular" , " react-native" , " react" , " nextjs" , " vue" , " android" , " flutter " ]} >
250
+ <InlineFilter filters = { [" javascript" , " angular" , " react-native" , " react" , " nextjs" , " vue" , " android" ]} >
210
251
211
252
In your client app code, you'll see query updated under the Data client:
212
253
@@ -258,6 +299,43 @@ let queriedCustomers = try await Amplify.API.query(
258
299
```
259
300
</InlineFilter >
260
301
302
+ <InlineFilter filters = { [" flutter" ]} >
303
+
304
+ In your client app code, you can use the updated query name.
305
+
306
+ ``` dart title="lib/main.dart"
307
+ import 'package:amplify_api/amplify_api.dart';
308
+ import 'package:amplify_flutter/amplify_flutter.dart';
309
+ import 'models/ModelProvider.dart';
310
+
311
+ var accountRepresentativeId = "John";
312
+ var operationName = "listByRep";
313
+ var document = """
314
+ query ListByRep {
315
+ $operationName(accountRepresentativeId: "$accountRepresentativeId") {
316
+ items {
317
+ accountRepresentativeId
318
+ createdAt
319
+ id
320
+ name
321
+ phoneNumber
322
+ updatedAt
323
+ }
324
+ nextToken
325
+ }
326
+ }
327
+ """;
328
+
329
+ final request = GraphQLRequest(
330
+ document: document,
331
+ variables: {
332
+ 'accountRepresentativeId': accountRepresentativeId,
333
+ 'operationName': operationName,
334
+ },
335
+ );
336
+ ```
337
+ </InlineFilter >
338
+
261
339
262
340
## Customize the name of secondary indexes
263
341
0 commit comments