Skip to content

Commit 433affe

Browse files
committed
Added documentation for using queryFields
1 parent d5b4151 commit 433affe

File tree

1 file changed

+39
-4
lines changed
  • src/pages/[platform]/build-a-backend/data/data-modeling/secondary-index

1 file changed

+39
-4
lines changed

src/pages/[platform]/build-a-backend/data/data-modeling/secondary-index/index.mdx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ The example client query below allows you to query for "Customer" records based
112112
```dart title="lib/main.dart"
113113
import 'package:amplify_api/amplify_api.dart';
114114
import 'package:amplify_flutter/amplify_flutter.dart';
115-
import 'amplify_outputs.dart';
116115
import 'models/ModelProvider.dart';
117116
118117
// highlight-start
119118
final request = ModelQueries.list(
120119
Customer.classType,
121-
where: accountRepresentativeId.eq(YOUR_REP_ID),
120+
where: Customer.ACCOUNTREPRESENTATIVEID.eq(YOUR_REP_ID),
122121
);
123122
// highlight-end
124123
@@ -214,13 +213,12 @@ The example client query below allows you to query for "Customer" records based
214213
```dart title="lib/main.dart"
215214
import 'package:amplify_api/amplify_api.dart';
216215
import 'package:amplify_flutter/amplify_flutter.dart';
217-
import 'amplify_outputs.dart';
218216
import 'models/ModelProvider.dart';
219217
220218
// highlight-start
221219
final request = ModelQueries.list(
222220
Customer.classType,
223-
where: Customer.accountRepresentativeId.eq(YOUR_REP_ID) & Customer.name.begins("Rene"),
221+
where: Customer.ACCOUNTREPRESENTATIVEID.eq(YOUR_REP_ID) & Customer.NAME.beginsWith("Rene"),
224222
);
225223
// highlight-end
226224
@@ -301,6 +299,43 @@ let queriedCustomers = try await Amplify.API.query(
301299
```
302300
</InlineFilter>
303301

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+
304339

305340
## Customize the name of secondary indexes
306341

0 commit comments

Comments
 (0)